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

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

#include <fixed_string.hpp>

Inheritance diagram for jb::fixed_string< wire_size_value >:

Public Member Functions

 fixed_string ()=default
 Default constructor. More...
 
 fixed_string (std::string const &rhs)
 Constructor from a std::string. More...
 
fixed_stringoperator= (std::string const &rhs)
 Assingment from std::string. More...
 
std::string str () const
 Return a representation as a std::string. More...
 
Base comparison operators
bool operator== (fixed_string const &rhs) const
 compare vs another fixed_string More...
 
bool operator< (fixed_string const &rhs) const
 compare vs another fixed_string More...
 
bool operator== (std::string const &rhs) const
 compare vs a std::string More...
 
bool operator< (std::string const &rhs) const
 compare vs a std::string More...
 
default assignment and copy operators
 fixed_string (fixed_string const &rhs)=default
 
 fixed_string (fixed_string &&rhs)=default
 
fixed_stringoperator= (fixed_string const &rhs)=default
 
fixed_stringoperator= (fixed_string &&rhs)=default
 

Static Public Attributes

static constexpr std::size_t wire_size = wire_size_value
 The size of the field on the wire. More...
 

Private Attributes

char buffer_ [wire_size]
 The in-memory representation. More...
 

Detailed Description

template<std::size_t wire_size_value>
class jb::fixed_string< wire_size_value >

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

Many market data protocols uses 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, several protocols define such fields as left justified, padded with spaces.

We want an in-memory representation that supports basic comparison operations, streaming to std::ostream, and conversion to std::string. We also want the C++ type to be a POD-type, so we can copy the message buffer directly into memory.

Template Parameters
wire_size_valuethe size of the field on the wire, in bytes.

Definition at line 32 of file fixed_string.hpp.

Constructor & Destructor Documentation

◆ fixed_string() [1/4]

template<std::size_t wire_size_value>
jb::fixed_string< wire_size_value >::fixed_string ( )
default

Default constructor.

Referenced by jb::fixed_string< 8 >::operator<().

◆ fixed_string() [2/4]

template<std::size_t wire_size_value>
jb::fixed_string< wire_size_value >::fixed_string ( std::string const &  rhs)
inlineexplicit

Constructor from a std::string.

Definition at line 44 of file fixed_string.hpp.

◆ fixed_string() [3/4]

template<std::size_t wire_size_value>
jb::fixed_string< wire_size_value >::fixed_string ( fixed_string< wire_size_value > const &  rhs)
default

◆ fixed_string() [4/4]

template<std::size_t wire_size_value>
jb::fixed_string< wire_size_value >::fixed_string ( fixed_string< wire_size_value > &&  rhs)
default

Member Function Documentation

◆ operator<() [1/2]

template<std::size_t wire_size_value>
bool jb::fixed_string< wire_size_value >::operator< ( fixed_string< wire_size_value > const &  rhs) const
inline

compare vs another fixed_string

Definition at line 74 of file fixed_string.hpp.

◆ operator<() [2/2]

template<std::size_t wire_size_value>
bool jb::fixed_string< wire_size_value >::operator< ( std::string const &  rhs) const
inline

compare vs a std::string

Definition at line 84 of file fixed_string.hpp.

◆ operator=() [1/3]

template<std::size_t wire_size_value>
fixed_string& jb::fixed_string< wire_size_value >::operator= ( std::string const &  rhs)
inline

Assingment from std::string.

Definition at line 53 of file fixed_string.hpp.

Referenced by jb::fixed_string< 8 >::operator<().

◆ operator=() [2/3]

template<std::size_t wire_size_value>
fixed_string& jb::fixed_string< wire_size_value >::operator= ( fixed_string< wire_size_value > const &  rhs)
default

◆ operator=() [3/3]

template<std::size_t wire_size_value>
fixed_string& jb::fixed_string< wire_size_value >::operator= ( fixed_string< wire_size_value > &&  rhs)
default

◆ operator==() [1/2]

template<std::size_t wire_size_value>
bool jb::fixed_string< wire_size_value >::operator== ( fixed_string< wire_size_value > const &  rhs) const
inline

compare vs another fixed_string

Definition at line 69 of file fixed_string.hpp.

◆ operator==() [2/2]

template<std::size_t wire_size_value>
bool jb::fixed_string< wire_size_value >::operator== ( std::string const &  rhs) const
inline

compare vs a std::string

Definition at line 79 of file fixed_string.hpp.

◆ str()

template<std::size_t wire_size_value>
std::string jb::fixed_string< wire_size_value >::str ( ) const
inline

Return a representation as a std::string.

Definition at line 60 of file fixed_string.hpp.

Referenced by jb::hash_value().

Member Data Documentation

◆ buffer_

template<std::size_t wire_size_value>
char jb::fixed_string< wire_size_value >::buffer_[wire_size]
private

◆ wire_size

template<std::size_t wire_size_value>
constexpr std::size_t jb::fixed_string< size >::wire_size = wire_size_value
static

The size of the field on the wire.

Define the constexpr.

Definition at line 38 of file fixed_string.hpp.

Referenced by jb::fixed_string< 8 >::operator<(), and jb::fixed_string< 8 >::operator==().


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