Static Public Member Functions
FIX::IntConvertor Struct Reference

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

#include <FieldConvertors.h>

List of all members.

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.
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

static std::string FIX::IntConvertor::convert ( signed_int  value) [inline, static]
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;
  }
static bool FIX::IntConvertor::convert ( const std::string &  value,
signed_int result 
) [inline, static]

Definition at line 196 of file FieldConvertors.h.

References convert().

  {
    return convert( value.begin(), value.end(), result );
  }
static signed_int FIX::IntConvertor::convert ( const std::string &  value) throw ( FieldConvertError ) [inline, static]

Definition at line 201 of file FieldConvertors.h.

References convert().

  {
    signed_int result = 0;
    if( !convert( value.begin(), value.end(), result ) )
      throw FieldConvertError(value);
    else
      return result;
  }
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.

Referenced by convertPositive().

  {
    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;
  }
static signed_int FIX::IntConvertor::convertPositive ( const std::string &  value) throw ( FieldConvertError ) [inline, static]

Definition at line 265 of file FieldConvertors.h.

References convertPositive().

  {
    signed_int result = 0;
    if( !convertPositive( value.begin(), value.end(), result ) )
      throw FieldConvertError(value);
    else
      return result;
  }

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

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001