Static Public Member Functions
FIX::UtcTimeOnlyConvertor Struct Reference

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

#include <FieldConvertors.h>

List of all members.

Static Public Member Functions

static std::string convert (const UtcTimeOnly &value, bool showMilliseconds=false) throw ( FieldConvertError )
static UtcTimeOnly convert (const std::string &value) throw ( FieldConvertError )

Detailed Description

Converts a UtcTimeOnly to/from a string.

Definition at line 687 of file FieldConvertors.h.


Member Function Documentation

static std::string FIX::UtcTimeOnlyConvertor::convert ( const UtcTimeOnly value,
bool  showMilliseconds = false 
) throw ( FieldConvertError ) [inline, static]

Definition at line 689 of file FieldConvertors.h.

References FIX::DateTime::getHMS(), and FIX::integer_to_string_padded().

Referenced by FIX::DataDictionary::checkValidFormat(), FIX::SessionFactory::create(), FIX::UtcTimeOnlyField::getValue(), and FIX::UtcTimeOnlyField::setValue().

  {
    char result[ 9+4 ];
    int hour, minute, second, millis;

    value.getHMS( hour, minute, second, millis );

    integer_to_string_padded ( result, 3, hour, 2 );
    result[2] = ':';
    integer_to_string_padded ( result + 3, 3, minute,  2 );
    result[5] = ':';
    integer_to_string_padded ( result + 6, 3, second,  2 );

    if( showMilliseconds )
    {
      result[8] = '.';
      if( integer_to_string_padded ( result + 9, 4, millis, 3 )
          != result + 9 )
          throw FieldConvertError();
    }

    return result;
  }
static UtcTimeOnly FIX::UtcTimeOnlyConvertor::convert ( const std::string &  value) throw ( FieldConvertError ) [inline, static]

Definition at line 715 of file FieldConvertors.h.

References IS_DIGIT, and FIX::TYPE::UtcTimeOnly.

  {
    bool haveMilliseconds = false;

    switch( value.size() )
    {
      case 12: haveMilliseconds = true;
      case 8: break;
      default: throw FieldConvertError(value);
    }

    int i = 0;
    int c = 0;
    for( c = 0; c < 2; ++c )
      if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
    if( value[i++] != ':' ) throw FieldConvertError(value);
    for( c = 0; c < 2; ++c )
      if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
    if( value[i++] != ':' ) throw FieldConvertError(value);
    for( c = 0; c < 2; ++c )
      if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);

    if( haveMilliseconds )
    {
      // ++i instead of i++ skips the '.' separator
      for( c = 0; c < 3; ++c )
        if( !IS_DIGIT(value[++i]) ) throw FieldConvertError(value);
    }

    int hour, min, sec, millis;
 
    i = 0;

    hour = value[i++] - '0';
    hour = 10 * hour + value[i++] - '0';
    // No check for >= 0 as no '-' are converted here
    if( 23 < hour ) throw FieldConvertError(value);
    ++i; // skip ':'

    min = value[i++] - '0';
    min = 10 * min + value[i++] - '0';
    // No check for >= 0 as no '-' are converted here
    if( 59 < min ) throw FieldConvertError(value);
    ++i; // skip ':'

    sec = value[i++] - '0';
    sec = 10 * sec + value[i++] - '0';
    // No check for >= 0 as no '-' are converted here
    if( 60 < sec ) throw FieldConvertError(value);

    if( haveMilliseconds )
    {
      millis = (100 * (value[i+1] - '0')
                + 10 * (value[i+2] - '0')
                + (value[i+3] - '0'));
    }
    else
      millis = 0;

    return UtcTimeOnly( hour, min, sec, millis );
  }

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