JayBeams  0.1
Another project to have fun coding.
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
jb::itch5::short_string_field< wire_size_value, value_validator > Class Template Reference

A helper type to define short (and fixed sized) string fields. More...

#include <short_string_field.hpp>

Inheritance diagram for jb::itch5::short_string_field< wire_size_value, value_validator >:

Public Types

typedef value_validator value_validator_t
 The type of validator. More...
 

Public Member Functions

 short_string_field (value_validator_t const &validator=value_validator_t())
 Constructor. More...
 
 short_string_field (std::string const &rhs, value_validator_t const &validator=value_validator_t())
 Constructor from a std::string. More...
 
char const * c_str () const
 Return the C-string representation. More...
 
Base comparison operators
bool operator== (short_string_field const &rhs) const
 compare vs another short_string_field More...
 
bool operator< (short_string_field const &rhs) const
 compare vs another short_string_field More...
 
bool operator== (char const *rhs) const
 compare vs a C string More...
 
bool operator< (char const *rhs) const
 compare vs a C string More...
 
default assignment and copy operators
 short_string_field (short_string_field const &rhs)=default
 
 short_string_field (short_string_field &&rhs)=default
 
short_string_fieldoperator= (short_string_field const &rhs)=default
 
short_string_fieldoperator= (short_string_field &&rhs)=default
 

Static Public Attributes

static constexpr std::size_t wire_size = wire_size_value
 The size of the field on the wire. More...
 
static constexpr std::size_t buffer_size = jb::p2ceil(wire_size_value)
 The size of the field in memory. More...
 

Private Member Functions

void assign (char const *buf)
 Assignment from a character buffer. More...
 
void nul_terminate ()
 NUL terminate the string. More...
 
void validate () const
 Validate the value using the functor. More...
 

Private Attributes

char buffer_ [buffer_size]
 The in-memory representation. More...
 
value_validator_t value_validator_
 The validator. More...
 

Friends

struct jb::itch5::decoder< true, short_string_field >
 
struct jb::itch5::decoder< false, short_string_field >
 

Detailed Description

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
class jb::itch5::short_string_field< wire_size_value, value_validator >

A helper type to define short (and fixed sized) string fields.

The ITCH-5.0 protocol uses many fields that are short strings, that is, fixed-length alpha numeric fields. While it is normally easy to treat these fields as character strings, the fields may not be NUL terminated. In fact, the protocol spec specifically states that the fields will be left justified, and padded with spaces.

We want an in-memory representation that is NUL terminated (for compatibility with all the C/C++ libraries), and we do not wish to allocate memory for these fields (as we would do if we used std::string).

Template Parameters
wire_size_valuethe size of the field on the wire, in bytes.
value_validatora functor to validate the value for those fields that are only supposed to assume a known set of values.

Definition at line 39 of file short_string_field.hpp.

Member Typedef Documentation

◆ value_validator_t

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
typedef value_validator jb::itch5::short_string_field< wire_size_value, value_validator >::value_validator_t

The type of validator.

Definition at line 56 of file short_string_field.hpp.

Constructor & Destructor Documentation

◆ short_string_field() [1/4]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
jb::itch5::short_string_field< wire_size_value, value_validator >::short_string_field ( value_validator_t const &  validator = value_validator_t())
inlineexplicit

Constructor.

Definition at line 59 of file short_string_field.hpp.

Referenced by jb::itch5::short_string_field< 8 >::operator<().

◆ short_string_field() [2/4]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
jb::itch5::short_string_field< wire_size_value, value_validator >::short_string_field ( std::string const &  rhs,
value_validator_t const &  validator = value_validator_t() 
)
inlineexplicit

Constructor from a std::string.

Definition at line 66 of file short_string_field.hpp.

◆ short_string_field() [3/4]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
jb::itch5::short_string_field< wire_size_value, value_validator >::short_string_field ( short_string_field< wire_size_value, value_validator > const &  rhs)
default

◆ short_string_field() [4/4]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
jb::itch5::short_string_field< wire_size_value, value_validator >::short_string_field ( short_string_field< wire_size_value, value_validator > &&  rhs)
default

Member Function Documentation

◆ assign()

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
void jb::itch5::short_string_field< wire_size_value, value_validator >::assign ( char const *  buf)
inlineprivate

Assignment from a character buffer.

Definition at line 117 of file short_string_field.hpp.

Referenced by jb::itch5::decoder< validate, short_string_field< wsize, F > >::r().

◆ c_str()

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
char const* jb::itch5::short_string_field< wire_size_value, value_validator >::c_str ( ) const
inline

Return the C-string representation.

Definition at line 76 of file short_string_field.hpp.

Referenced by jb::itch5::hash_value().

◆ nul_terminate()

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
void jb::itch5::short_string_field< wire_size_value, value_validator >::nul_terminate ( )
inlineprivate

◆ operator<() [1/2]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
bool jb::itch5::short_string_field< wire_size_value, value_validator >::operator< ( short_string_field< wire_size_value, value_validator > const &  rhs) const
inline

compare vs another short_string_field

Definition at line 90 of file short_string_field.hpp.

◆ operator<() [2/2]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
bool jb::itch5::short_string_field< wire_size_value, value_validator >::operator< ( char const *  rhs) const
inline

compare vs a C string

Definition at line 100 of file short_string_field.hpp.

◆ operator=() [1/2]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
short_string_field& jb::itch5::short_string_field< wire_size_value, value_validator >::operator= ( short_string_field< wire_size_value, value_validator > const &  rhs)
default

◆ operator=() [2/2]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
short_string_field& jb::itch5::short_string_field< wire_size_value, value_validator >::operator= ( short_string_field< wire_size_value, value_validator > &&  rhs)
default

◆ operator==() [1/2]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
bool jb::itch5::short_string_field< wire_size_value, value_validator >::operator== ( short_string_field< wire_size_value, value_validator > const &  rhs) const
inline

compare vs another short_string_field

Definition at line 85 of file short_string_field.hpp.

◆ operator==() [2/2]

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
bool jb::itch5::short_string_field< wire_size_value, value_validator >::operator== ( char const *  rhs) const
inline

compare vs a C string

Definition at line 95 of file short_string_field.hpp.

◆ validate()

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
void jb::itch5::short_string_field< wire_size_value, value_validator >::validate ( ) const
inlineprivate

Validate the value using the functor.

Template Parameters
enabledif false, disable all validation

Definition at line 144 of file short_string_field.hpp.

Referenced by jb::itch5::decoder< validate, short_string_field< wsize, F > >::r().

Friends And Related Function Documentation

◆ jb::itch5::decoder< false, short_string_field >

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
friend struct jb::itch5::decoder< false, short_string_field >
friend

Definition at line 115 of file short_string_field.hpp.

◆ jb::itch5::decoder< true, short_string_field >

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
friend struct jb::itch5::decoder< true, short_string_field >
friend

Definition at line 114 of file short_string_field.hpp.

Member Data Documentation

◆ buffer_

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
char jb::itch5::short_string_field< wire_size_value, value_validator >::buffer_[buffer_size]
private

◆ buffer_size

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
constexpr std::size_t jb::itch5::short_string_field< wire_size_value, value_validator >::buffer_size = jb::p2ceil(wire_size_value)
static

The size of the field in memory.

Definition at line 53 of file short_string_field.hpp.

◆ value_validator_

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
value_validator_t jb::itch5::short_string_field< wire_size_value, value_validator >::value_validator_
private

The validator.

Definition at line 155 of file short_string_field.hpp.

Referenced by jb::itch5::short_string_field< 8 >::validate().

◆ wire_size

template<std::size_t wire_size_value, typename value_validator = noop_validator<char const*>>
constexpr std::size_t jb::itch5::short_string_field< wire_size_value, value_validator >::wire_size = wire_size_value
static

The size of the field on the wire.

Definition at line 50 of file short_string_field.hpp.

Referenced by jb::itch5::short_string_field< 8 >::nul_terminate(), and jb::itch5::short_string_field< 8 >::short_string_field().


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