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

Definition at line 574 of file FieldConvertors.h.

576 {
577 size_t len = value.size();
578 if (len < 8 || len > 18) throw FieldConvertError(value);
579
580 size_t i = 0;
581 int c = 0;
582 for( c = 0; c < 2; ++c )
583 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
584 if( value[i++] != ':' ) throw FieldConvertError(value);
585 for( c = 0; c < 2; ++c )
586 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
587 if( value[i++] != ':' ) throw FieldConvertError(value);
588 for( c = 0; c < 2; ++c )
589 if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
590
591 int hour, min, sec;
592
593 i = 0;
594
595 hour = value[i++] - '0';
596 hour = 10 * hour + value[i++] - '0';
597 // No check for >= 0 as no '-' are converted here
598 if( 23 < hour ) throw FieldConvertError(value);
599
600 ++i; // skip ':'
601
602 min = value[i++] - '0';
603 min = 10 * min + value[i++] - '0';
604 // No check for >= 0 as no '-' are converted here
605 if( 59 < min ) throw FieldConvertError(value);
606
607 ++i; // skip ':'
608
609 sec = value[i++] - '0';
610 sec = 10 * sec + value[i++] - '0';
611
612 // No check for >= 0 as no '-' are converted here
613 if( 60 < sec ) throw FieldConvertError(value);
614
615 if (len == 8)
616 return UtcTimeOnly (hour, min, sec, 0);
617
618 if( value[i++] != '.' ) throw FieldConvertError(value);
619
620 int fraction = 0;
621 for (; i < len; ++i)
622 {
623 char ch = value[i];
624 if( !IS_DIGIT(ch)) throw FieldConvertError(value);
625 fraction = (fraction * 10) + ch - '0';
626 }
627
628 return UtcTimeOnly (hour, min, sec, fraction, len - 8 - 1);
629 }
#define IS_DIGIT(x)

References IS_DIGIT.

◆ convert() [2/2]

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

Definition at line 548 of file FieldConvertors.h.

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 );
558 result[2] = ':';
559 integer_to_string_padded ( result + 3, 2, minute );
560 result[5] = ':';
561 integer_to_string_padded ( result + 6, 2, second );
562
563 if( precision )
564 {
565 result[8] = '.';
566 if( integer_to_string_padded ( result + 9, precision, fraction )
567 != result + 9 )
568 throw FieldConvertError();
569 }
570
571 return std::string(result, precision ? (8 + 1 + precision) : 8);
572 }
char * integer_to_string_padded(char *buf, const size_t len, signed_int t, const char paddingChar='0')

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:

Generated on Thu Feb 29 2024 22:38:19 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001