High Frequency FIX Parser
C++ library for high frequency messaging with the Financial Information Exchange (FIX) protocol.
Public Member Functions | List of all members
hffix::field_value Class Reference

FIX field value for hffix::message_reader. More...

#include <hffix.hpp>

Public Member Functions

char const * begin () const
 Pointer to the beginning of the field value in the buffer.
 
char const * end () const
 Pointer to past-the-end of the field value in the buffer.
 
size_t size () const
 Size of the field value, in bytes.
 
String Conversion Methods
std::string as_string () const
 Ascii value as std::string.
 
std::string_view as_string_view () const
 Ascii value as std::string_view.
 
char as_char () const
 Ascii value as char.
 
Decimal Float Conversion Methods
template<typename Int_type >
void as_decimal (Int_type &mantissa, Int_type &exponent) const
 Ascii-to-decimal conversion.
 
Integer Conversion Methods
template<typename Int_type >
Int_type as_int () const
 Ascii-to-integer conversion.
 
Date and Time Conversion Methods
bool as_date (int &year, int &month, int &day) const
 Ascii-to-date conversion.
 
bool as_monthyear (int &year, int &month) const
 Ascii-to-month-year conversion.
 
bool as_timeonly (int &hour, int &minute, int &second, int &millisecond) const
 Ascii-to-time conversion with millisecond precision.
 
bool as_timeonly_nano (int &hour, int &minute, int &second, int &nanosecond) const
 Ascii-to-time conversion with nanosecond precision.
 
bool as_timestamp (int &year, int &month, int &day, int &hour, int &minute, int &second, int &millisecond) const
 Ascii-to-timestamp conversion with millisecond precision.
 
bool as_timestamp_nano (int &year, int &month, int &day, int &hour, int &minute, int &second, int &nanosecond) const
 Ascii-to-timestamp conversion with nanosecond precision.
 
Boost Date and Time Conversion Methods
boost::gregorian::date as_date () const
 Ascii-to-date conversion.
 
boost::posix_time::time_duration as_timeonly () const
 Ascii-to-time conversion with millisecond precision.
 
boost::posix_time::time_duration as_timeonly_nano () const
 Ascii-to-time conversion with nanosecond precision.
 
boost::posix_time::ptime as_timestamp () const
 Ascii-to-timestamp conversion with millisecond precision.
 
boost::posix_time::ptime as_timestamp_nano () const
 Ascii-to-timestamp conversion with nanosecond precision.
 

std::chrono Date and Time Conversion Methods

template<typename Clock , typename Duration >
bool as_timestamp (std::chrono::time_point< Clock, Duration > &tp) const
 Ascii-to-time-point conversion with millisecond precision.
 
template<typename Clock , typename Duration >
bool as_timestamp_nano (std::chrono::time_point< Clock, Duration > &tp) const
 Ascii-to-time-point conversion with nanosecond precision.
 
template<typename Rep , typename Period >
bool as_timeonly (std::chrono::duration< Rep, Period > &dur) const
 Ascii-to-time conversion.
 
template<typename Rep , typename Period >
bool as_timeonly_nano (std::chrono::duration< Rep, Period > &dur) const
 Ascii-to-time conversion with nanosecond precision.
 

Detailed Description

FIX field value for hffix::message_reader.

Usage

This class is a range begin(),end() of pointers into a message_reader buffer which delimit the value for one field.

FIX field values are an array of chars, and are usually ASCII. Type conversion deserialization is provided by the as_ family of methods.

Extension

Keep in mind that if you don't like the way any of the the as_ methods perform deserialization for a type, then you can deserialize the field value yourself, by reading the string delimited by begin(),end().

For example, these two statements should be equivalent for a field_value v:

int i = v.as_int();
int i = boost::lexical_cast<int>(v.begin(), v.size());

Definition at line 1575 of file hffix.hpp.

Member Function Documentation

◆ as_char()

char hffix::field_value::as_char ( ) const
inline

Ascii value as char.

Returns
The first char of the ascii value of the field.

Definition at line 1719 of file hffix.hpp.

◆ as_date() [1/2]

boost::gregorian::date hffix::field_value::as_date ( ) const
inline

Ascii-to-date conversion.

Parses ascii and returns a LocalMktDate or UTCDate.

Returns
Date if parsing was successful, else boost::posix_time::not_a_date_time.

Definition at line 1938 of file hffix.hpp.

◆ as_date() [2/2]

bool hffix::field_value::as_date ( int &  year,
int &  month,
int &  day 
) const
inline

Ascii-to-date conversion.

Parses ascii and returns a LocalMktDate or UTCDate.

Parameters
[out]yearYear.
[out]monthMonth.
[out]dayDay.
Returns
True if successful and the out arguments were set.

Definition at line 1797 of file hffix.hpp.

◆ as_decimal()

template<typename Int_type >
void hffix::field_value::as_decimal ( Int_type &  mantissa,
Int_type &  exponent 
) const
inline

Ascii-to-decimal conversion.

Converts an ascii string to a decimal float, of the form mantissa×10exponent.

Non-normalized. The exponent will always be less than or equal to zero. If the decimal float is an integer, the exponent will be zero.

Template Parameters
Int_typeInteger type for the mantissa and exponent.
Parameters
[out]mantissaReference to storage for the mantissa of the decimal float to be returned.
[out]exponentReference to storage for the exponent of the decimal float to be returned.

Definition at line 1741 of file hffix.hpp.

◆ as_int()

template<typename Int_type >
Int_type hffix::field_value::as_int ( ) const
inline

Ascii-to-integer conversion.

Parses ascii and returns an integer.

Template Parameters
Int_typeThe type of integer to be returned. May be an unsigned integer.
Returns
The ascii field value represented as an integer of type Int_type.

Definition at line 1778 of file hffix.hpp.

◆ as_monthyear()

bool hffix::field_value::as_monthyear ( int &  year,
int &  month 
) const
inline

Ascii-to-month-year conversion.

Parses ascii and returns a month-year.

Parameters
[out]yearYear.
[out]monthMonth.
Returns
True if successful and the out arguments were set.

Definition at line 1815 of file hffix.hpp.

◆ as_string()

std::string hffix::field_value::as_string ( ) const
inline

Ascii value as std::string.

Warning
This function will, of course, allocate memory if the string is larger than the short-string-optimization size. This is the only function in this library which may allocate memory on the free store. Instead of using this function, consider reading the field value with begin() and end().
Returns
An std::string that contains a copy of the ascii value of the field.
Exceptions
std::bad_alloc

Definition at line 1699 of file hffix.hpp.

◆ as_string_view()

std::string_view hffix::field_value::as_string_view ( ) const
inline

Ascii value as std::string_view.

Returns
An std::string_view that contains the ascii value of the field.

Definition at line 1709 of file hffix.hpp.

◆ as_timeonly() [1/3]

boost::posix_time::time_duration hffix::field_value::as_timeonly ( ) const
inline

Ascii-to-time conversion with millisecond precision.

Parses ascii and returns a time.

Returns
Time if parsing was successful, else boost::posix_time::not_a_date_time.

Definition at line 1957 of file hffix.hpp.

◆ as_timeonly() [2/3]

bool hffix::field_value::as_timeonly ( int &  hour,
int &  minute,
int &  second,
int &  millisecond 
) const
inline

Ascii-to-time conversion with millisecond precision.

Parses ascii and returns a time with millisecond precision.

Parameters
[out]hourHour.
[out]minuteMinute.
[out]secondSecond.
[out]millisecondMillisecond.
Returns
True if successful and the out arguments were set.

Definition at line 1839 of file hffix.hpp.

◆ as_timeonly() [3/3]

template<typename Rep , typename Period >
bool hffix::field_value::as_timeonly ( std::chrono::duration< Rep, Period > &  dur) const
inline

Ascii-to-time conversion.

Parses ascii and returns a time duration or time-of-day.

Parameters
[out]durThe return value duration.
Returns
True if parsing was successful and the return value was set, else False.

Definition at line 2097 of file hffix.hpp.

◆ as_timeonly_nano() [1/3]

boost::posix_time::time_duration hffix::field_value::as_timeonly_nano ( ) const
inline

Ascii-to-time conversion with nanosecond precision.

Parses ascii and returns a time.

Returns
Time if parsing was successful, else boost::posix_time::not_a_date_time.

Definition at line 1976 of file hffix.hpp.

◆ as_timeonly_nano() [2/3]

bool hffix::field_value::as_timeonly_nano ( int &  hour,
int &  minute,
int &  second,
int &  nanosecond 
) const
inline

Ascii-to-time conversion with nanosecond precision.

Parses ascii and returns a time with nanosecond precision.

Parameters
[out]hourHour.
[out]minuteMinute.
[out]secondSecond.
[out]nanosecondNanosecond.
Returns
True if successful and the out arguments were set.

Definition at line 1859 of file hffix.hpp.

◆ as_timeonly_nano() [3/3]

template<typename Rep , typename Period >
bool hffix::field_value::as_timeonly_nano ( std::chrono::duration< Rep, Period > &  dur) const
inline

Ascii-to-time conversion with nanosecond precision.

Parses ascii and returns a time duration or time-of-day.

Parameters
[out]durThe return value duration.
Returns
True if parsing was successful and the return value was set, else False.

Definition at line 2121 of file hffix.hpp.

◆ as_timestamp() [1/3]

boost::posix_time::ptime hffix::field_value::as_timestamp ( ) const
inline

Ascii-to-timestamp conversion with millisecond precision.

Parses ascii and returns a timestamp with millisecond precision.

Returns
Date and Time if parsing was successful, else boost::posix_time::not_a_date_time.

Definition at line 1995 of file hffix.hpp.

◆ as_timestamp() [2/3]

bool hffix::field_value::as_timestamp ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
int &  millisecond 
) const
inline

Ascii-to-timestamp conversion with millisecond precision.

Parses ascii and returns a timestamp with millisecond precision.

Parameters
[out]yearYear.
[out]monthMonth.
[out]dayDay.
[out]hourHour.
[out]minuteMinute.
[out]secondSecond.
[out]millisecondMillisecond.
Returns
True if successful and the out arguments were set.

Definition at line 1882 of file hffix.hpp.

◆ as_timestamp() [3/3]

template<typename Clock , typename Duration >
bool hffix::field_value::as_timestamp ( std::chrono::time_point< Clock, Duration > &  tp) const
inline

Ascii-to-time-point conversion with millisecond precision.

Parses ascii and returns a std::chrono::time_point.

Uses algorithms from http://howardhinnant.github.io/date_algorithms.html , which implement a proleptic Gregorian calendar. This will probably be superseded by C++20.

Parameters
[out]tpThe return value time_point.
Returns
True if parsing was successful and tp was set, else False.

Definition at line 2058 of file hffix.hpp.

◆ as_timestamp_nano() [1/3]

boost::posix_time::ptime hffix::field_value::as_timestamp_nano ( ) const
inline

Ascii-to-timestamp conversion with nanosecond precision.

Parses ascii and returns a timestamp with nanosecond precision.

Returns
Date and Time if parsing was successful, else boost::posix_time::not_a_date_time.

Definition at line 2019 of file hffix.hpp.

◆ as_timestamp_nano() [2/3]

bool hffix::field_value::as_timestamp_nano ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
int &  nanosecond 
) const
inline

Ascii-to-timestamp conversion with nanosecond precision.

Parses ascii and returns a timestamp with nanosecond precision.

Parameters
[out]yearYear.
[out]monthMonth.
[out]dayDay.
[out]hourHour.
[out]minuteMinute.
[out]secondSecond.
[out]nanosecondNanosecond.
Returns
True if successful and the out arguments were set.

Definition at line 1910 of file hffix.hpp.

◆ as_timestamp_nano() [3/3]

template<typename Clock , typename Duration >
bool hffix::field_value::as_timestamp_nano ( std::chrono::time_point< Clock, Duration > &  tp) const
inline

Ascii-to-time-point conversion with nanosecond precision.

Parses ascii and returns a std::chrono::time_point.

Uses algorithms from http://howardhinnant.github.io/date_algorithms.html , which implement a proleptic Gregorian calendar. This will probably be superseded by C++20.

Parameters
[out]tpThe return value time_point.
Returns
True if parsing was successful and tp was set, else False.

Definition at line 2079 of file hffix.hpp.

◆ begin()

char const * hffix::field_value::begin ( ) const
inline

Pointer to the beginning of the field value in the buffer.

Definition at line 1579 of file hffix.hpp.

◆ end()

char const * hffix::field_value::end ( ) const
inline

Pointer to past-the-end of the field value in the buffer.

Definition at line 1584 of file hffix.hpp.

◆ size()

size_t hffix::field_value::size ( ) const
inline

Size of the field value, in bytes.

Definition at line 1589 of file hffix.hpp.


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