Static Public Member Functions | List of all members
FIX::UtcTimeStampConvertor Struct Reference

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

#include <FieldConvertors.h>

Static Public Member Functions

static std::string convert (const UtcTimeStamp &value, int precision=0) throw ( FieldConvertError )
 
static UtcTimeStamp convert (const std::string &value) throw ( FieldConvertError )
 

Detailed Description

Converts a UtcTimeStamp to/from a string.

Definition at line 447 of file FieldConvertors.h.

Member Function Documentation

◆ convert() [1/2]

static UtcTimeStamp FIX::UtcTimeStampConvertor::convert ( const std::string &  value)
throw (FieldConvertError
)
inlinestatic

Definition at line 482 of file FieldConvertors.h.

483  :' ) throw FieldConvertError(value);
484  for( c = 0; c < 2; ++c )
485  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
486 
487  int year, mon, mday, hour, min, sec;
488 
489  i = 0;
490 
491  year = value[i++] - '0';
492  year = 10 * year + value[i++] - '0';
493  year = 10 * year + value[i++] - '0';
494  year = 10 * year + value[i++] - '0';
495 
496  mon = value[i++] - '0';
497  mon = 10 * mon + value[i++] - '0';
498  if( mon < 1 || 12 < mon ) throw FieldConvertError(value);
499 
500  mday = value[i++] - '0';
501  mday = 10 * mday + value[i++] - '0';
502  if( mday < 1 || 31 < mday ) throw FieldConvertError(value);
503 
504  ++i; // skip '-'
505 
506  hour = value[i++] - '0';
507  hour = 10 * hour + value[i++] - '0';
508  // No check for >= 0 as no '-' are converted here
509  if( 23 < hour ) throw FieldConvertError(value);
510 
511  ++i; // skip ':'
512 
513  min = value[i++] - '0';
514  min = 10 * min + value[i++] - '0';
515  // No check for >= 0 as no '-' are converted here
516  if( 59 < min ) throw FieldConvertError(value);
517 
518  ++i; // skip ':'
519 
520  sec = value[i++] - '0';
521  sec = 10 * sec + value[i++] - '0';
522 
523  // No check for >= 0 as no '-' are converted here
524  if( 60 < sec ) throw FieldConvertError(value);
525 
526  if (len == 17)
527  return UtcTimeStamp (hour, min, sec, 0,
528  mday, mon, year);
529 
530  if( value[i++] != '.' ) throw FieldConvertError(value);
531 
532  int fraction = 0;
533  for (; i < len; ++i)
534  {
535  char ch = value[i];
536  if( !IS_DIGIT(ch)) throw FieldConvertError(value);
537  fraction = (fraction * 10) + ch - '0';
538  }
539 
540  return UtcTimeStamp (hour, min, sec, fraction,
541  mday, mon, year, len - 17 - 1);
542  }
543 };
544 
546 struct UtcTimeOnlyConvertor
547 {
548  static std::string convert( const UtcTimeOnly& value,
549  int precision = 0 )
550  throw( FieldConvertError )
551  {
552  char result[ 8+10 ]; // Maximum
553  int hour, minute, second, fraction;
554 
555  value.getHMS( hour, minute, second, fraction, precision );
556 
557  integer_to_string_padded ( result, 2, hour );

◆ convert() [2/2]

static std::string FIX::UtcTimeStampConvertor::convert ( const UtcTimeStamp value,
int  precision = 0 
)
throw (FieldConvertError
)
inlinestatic

Definition at line 449 of file FieldConvertors.h.

449  :';
450  integer_to_string_padded( result + 12, 2, minute);
451  result[14] = ':';
452  integer_to_string_padded( result + 15, 2, second);
453 
454  if( precision )
455  {
456  result[17] = '.';
457  if( integer_to_string_padded ( result + 18, precision, fraction )
458  != result + 18 )
459  {
460  throw FieldConvertError();
461  }
462  }
463 
464  return std::string(result, precision ? (17 + 1 + precision) : 17);
465  }
466 
467  static UtcTimeStamp convert( const std::string& value )
468  throw( FieldConvertError )
469  {
470  size_t len = value.size();
471  if (len < 17 || len > 27) throw FieldConvertError(value);
472 
473  size_t i = 0;
474  int c = 0;
475  for( c = 0; c < 8; ++c )
476  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
477  if (value[i++] != '-') throw FieldConvertError(value);
478  for( c = 0; c < 2; ++c )
479  if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
480  if( value[i++] != ':' ) throw FieldConvertError(value);

Referenced by FIX::BoolField::operator bool().


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

Generated on Thu Apr 23 2020 04:32:03 for QuickFIX by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2001