FIX::IntConvertor Struct Reference

Converts integer to/from a string. More...

`#include <FieldConvertors.h>`

## Static Public Member Functions

static std::string | convert (signed_int value)
static bool | convert (std::string::const_iterator str, std::string::const_iterator end, signed_int &result)
static bool | convert (const std::string &value, signed_int &result)
static signed_int | convert (const std::string &value) throw ( FieldConvertError )
static bool | convertPositive (std::string::const_iterator str, std::string::const_iterator end, signed_int &result)
| Converts only positive number e.g. More...
static signed_int | convertPositive (const std::string &value) throw ( FieldConvertError )

## Detailed Description

Converts integer to/from a string.

Definition at line 152 of file FieldConvertors.h.

## Member Function Documentation

## convert() [1/4]

static std::string FIX::IntConvertor::convert | ( | signed_int | value | ) |

inline static

Definition at line 154 of file FieldConvertors.h.

References FIX::integer_to_string().

Referenced by FIX::DataDictionary::checkGroupCount(), FIX::DataDictionary::checkValidFormat(), FIX::CheckSumConvertor::convert(), FIX::SocketInitiator::doConnect(), FIX::ThreadedSocketInitiator::doConnect(), FIX::Session::doTargetTooHigh(), FIX::Message::extractField(), FIX::Parser::extractLength(), FIX::Session::generateBusinessReject(), FIX::Session::generateReject(), FIX::Session::generateResendRequest(), FIX::Session::generateSequenceReset(), FIX::Dictionary::getInt(), FIX::IntField::getValue(), FIX::Session::nextQueued(), FIX::Session::nextResendRequest(), FIX::Session::nextSequenceReset(), FIX::HttpServer::onInitialize(), FIX::SocketAcceptor::onInitialize(), FIX::ThreadedSocketAcceptor::onInitialize(), FIX::HttpConnection::processSession(), FIX::Dictionary::setInt(), FIX::IntField::setValue(), and FIX::Session::verify().

{
// buffer is big enough for significant digits and extra digit,
// minus and null
char buffer[std::numeric_limits<signed_int>::digits10 + 3];
const char* const start
= integer_to_string( buffer, sizeof (buffer), value );
return std::string( start, buffer + sizeof (buffer) - start - 1 );
}
FIX::integer_to_string
char * integer_to_string(char *buf, const size_t len, signed_int t)
Definition: FieldConvertors.h:93

## convert() [2/4]

static bool FIX::IntConvertor::convert | ( | std::string::const_iterator | str,
|  | std::string::const_iterator | end,
|  | signed_int & | result
| ) |  |

inline static

Definition at line 164 of file FieldConvertors.h.

{
bool isNegative = false;
signed_int x = 0;
if( str == end )
return false;
if( *str == '-' )
{
isNegative = true;
if( ++str == end )
return false;
}
do
{
const unsigned_int c = *str - '0';
if( c > 9 ) return false;
x = 10 * x + c;
} while ( ++str != end );
if( isNegative )
x = -x;
result = x;
return true;
}
FIX::unsigned_int
unsigned int unsigned_int
Definition: FieldConvertors.h:38
FIX::signed_int
int signed_int
Definition: FieldConvertors.h:37

## convert() [3/4]

static bool FIX::IntConvertor::convert | ( | const std::string & | value,
|  | signed_int & | result
| ) |  |

inline static

Definition at line 196 of file FieldConvertors.h.

References FIX::EmptyConvertor::convert().

{
return convert( value.begin(), value.end(), result );
}
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:154

## convert() [4/4]

static signed_int FIX::IntConvertor::convert | ( | const std::string & | value | ) |
throw | ( | FieldConvertError
| ) |  |

inline static

Definition at line 201 of file FieldConvertors.h.

References FIX::EmptyConvertor::convert().

{
signed_int result = 0;
if( !convert( value.begin(), value.end(), result ) )
throw FieldConvertError(value);
else
return result;
}
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:154
FIX::signed_int
int signed_int
Definition: FieldConvertors.h:37

## convertPositive() [1/2]

static bool FIX::IntConvertor::convertPositive | ( | std::string::const_iterator | str,
|  | std::string::const_iterator | end,
|  | signed_int & | result
| ) |  |

inline static

Converts only positive number e.g.

FIX field ID: [1 ... 2147483647] No leading whitespace/zero/plus/sign symbols allowed Value is fixed to not make difference between 32bit and 64bit code

Definition at line 214 of file FieldConvertors.h.

{
const int MAX_VALUE = 2147483647; // max value for 32-bit signed integer
const int HIGH_MARK = MAX_VALUE / 10;
const unsigned_int STOP_SYMBOL = MAX_VALUE % 10;
const std::size_t MAX_DIGITS = 10; // integer can hold up to 10 digits
const std::size_t length = std::distance( str, end );
if( length < 1 || length > MAX_DIGITS)
return false;
if( length == MAX_DIGITS )
{
end = str;
std::advance( end, length - 1 );
}
const unsigned_int ch = *str - '1';
if( ch > 8 )
return false;
unsigned_int x = 0;
do
{
const unsigned_int c = *str - '0';
if( c > 9 ) return false;
x = 10 * x + c;
} while( ++str < end );
// complete overflow condition check and value calculation
// this saves about 25% of speed when executed out of the main loop
if( length == MAX_DIGITS )
{
if( x > (unsigned int)HIGH_MARK )
return false;
const unsigned_int c = *str - '0';
if( x == (unsigned int)HIGH_MARK && c > STOP_SYMBOL )
return false;
x = 10 * x + c;
}
result = x;
return true;
}
FIX::unsigned_int
unsigned int unsigned_int
Definition: FieldConvertors.h:38

## convertPositive() [2/2]

static signed_int FIX::IntConvertor::convertPositive | ( | const std::string & | value | ) |
throw | ( | FieldConvertError
| ) |  |

inline static

Definition at line 265 of file FieldConvertors.h.

{
signed_int result = 0;
if( !convertPositive( value.begin(), value.end(), result ) )
throw FieldConvertError(value);
else
return result;
}
FIX::IntConvertor::convertPositive
static bool convertPositive(std::string::const_iterator str, std::string::const_iterator end, signed_int &result)
Converts only positive number e.g.
Definition: FieldConvertors.h:214
FIX::signed_int
int signed_int
Definition: FieldConvertors.h:37

The documentation for this struct was generated from the following file:

- FieldConvertors.h