Static Public Member Functions | List of all members
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)
inlinestatic

◆ convert() [2/4]

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

Definition at line 164 of file FieldConvertors.h.

168  {
169  bool isNegative = false;
170  signed_int x = 0;
171 
172  if( str == end )
173  return false;
174 
175  if( *str == '-' )
176  {
177  isNegative = true;
178  if( ++str == end )
179  return false;
180  }
181 
182  do
183  {
184  const unsigned_int c = *str - '0';
185  if( c > 9 ) return false;
186  x = 10 * x + c;
187  } while ( ++str != end );
188 
189  if( isNegative )
190  x = -x;
191 
192  result = x;
193  return true;
194  }
unsigned int unsigned_int
int signed_int

◆ convert() [3/4]

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

Definition at line 196 of file FieldConvertors.h.

References FIX::EmptyConvertor::convert().

197  {
198  return convert( value.begin(), value.end(), result );
199  }
static std::string convert(signed_int value)

◆ convert() [4/4]

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

Definition at line 201 of file FieldConvertors.h.

References FIX::EmptyConvertor::convert().

203  {
204  signed_int result = 0;
205  if( !convert( value.begin(), value.end(), result ) )
206  throw FieldConvertError(value);
207  else
208  return result;
209  }
static std::string convert(signed_int value)
int signed_int

◆ convertPositive() [1/2]

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

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.

218  {
219  const int MAX_VALUE = 2147483647; // max value for 32-bit signed integer
220  const int HIGH_MARK = MAX_VALUE / 10;
221  const unsigned_int STOP_SYMBOL = MAX_VALUE % 10;
222  const std::size_t MAX_DIGITS = 10; // integer can hold up to 10 digits
223 
224  const std::size_t length = std::distance( str, end );
225  if( length < 1 || length > MAX_DIGITS)
226  return false;
227 
228  if( length == MAX_DIGITS )
229  {
230  end = str;
231  std::advance( end, length - 1 );
232  }
233 
234  const unsigned_int ch = *str - '1';
235  if( ch > 8 )
236  return false;
237 
238  unsigned_int x = 0;
239 
240  do
241  {
242  const unsigned_int c = *str - '0';
243  if( c > 9 ) return false;
244  x = 10 * x + c;
245  } while( ++str < end );
246 
247  // complete overflow condition check and value calculation
248  // this saves about 25% of speed when executed out of the main loop
249  if( length == MAX_DIGITS )
250  {
251  if( x > (unsigned int)HIGH_MARK )
252  return false;
253 
254  const unsigned_int c = *str - '0';
255  if( x == (unsigned int)HIGH_MARK && c > STOP_SYMBOL )
256  return false;
257 
258  x = 10 * x + c;
259  }
260 
261  result = x;
262  return true;
263  }
unsigned int unsigned_int

◆ convertPositive() [2/2]

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

Definition at line 265 of file FieldConvertors.h.

267  {
268  signed_int result = 0;
269  if( !convertPositive( value.begin(), value.end(), result ) )
270  throw FieldConvertError(value);
271  else
272  return result;
273  }
static bool convertPositive(std::string::const_iterator str, std::string::const_iterator end, signed_int &result)
Converts only positive number e.g.
int signed_int

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

Generated on Thu Sep 5 2019 11:07:58 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001