FIX::UtcTimeOnlyConvertor Struct Reference

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

`#include <FieldConvertors.h>`

## Static Public Member Functions

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

## Detailed Description

Converts a UtcTimeOnly to/from a string.

Definition at line 546 of file FieldConvertors.h.

## Member Function Documentation

## convert() [1/2]

static UtcTimeOnly FIX::UtcTimeOnlyConvertor::convert | ( | const std::string & | value | ) |
throw | ( | FieldConvertError
| ) |  |

inline static

Definition at line 574 of file FieldConvertors.h.

{
size_t len = value.size();
if (len < 8 || len > 18) throw FieldConvertError(value);
size_t 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);
int hour, min, sec;
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 (len == 8)
return UtcTimeOnly (hour, min, sec, 0);
if( value[i++] != '.' ) throw FieldConvertError(value);
int fraction = 0;
for (; i < len; ++i)
{
char ch = value[i];
if( !IS_DIGIT(ch)) throw FieldConvertError(value);
fraction = (fraction * 10) + ch - '0';
}
return UtcTimeOnly (hour, min, sec, fraction, len - 8 - 1);
}
IS_DIGIT
#define IS_DIGIT(x)
Definition: FieldConvertors.h:49
FIX::TYPE::UtcTimeOnly
@ UtcTimeOnly
Definition: FieldTypes.h:933

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

## convert() [2/2]

static std::string FIX::UtcTimeOnlyConvertor::convert | ( | const UtcTimeOnly & | value,
|  | int | precision = `0`
| ) |  |
throw | ( | FieldConvertError
| ) |  |

inline static

Definition at line 548 of file FieldConvertors.h.

{
char result[ 8+10 ]; // Maximum
int hour, minute, second, fraction;
value.getHMS( hour, minute, second, fraction, precision );
integer_to_string_padded ( result, 2, hour );
result[2] = ':';
integer_to_string_padded ( result + 3, 2, minute );
result[5] = ':';
integer_to_string_padded ( result + 6, 2, second );
if( precision )
{
result[8] = '.';
if( integer_to_string_padded ( result + 9, precision, fraction )
!= result + 9 )
throw FieldConvertError();
}
return std::string(result, precision ? (8 + 1 + precision) : 8);
}
FIX::integer_to_string_padded
char * integer_to_string_padded(char *buf, const size_t len, signed_int t, const char paddingChar='0')
Definition: FieldConvertors.h:132

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

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

- FieldConvertors.h