Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::utils::fixed_string< N > Class Template Reference

A null-terminated character buffer of fixed capacity, stored inline. More...

#include <utils/fixed_string.hpp>

Inheritance diagram for slick::sim::utils::fixed_string< N >:
Collaboration diagram for slick::sim::utils::fixed_string< N >:

Public Member Functions

 fixed_string ()=default
 fixed_string (std::string_view value) noexcept
 fixed_string (const char *value) noexcept
fixed_string & operator= (std::string_view value) noexcept
fixed_string & operator= (const char *value) noexcept
void assign (std::string_view value) noexcept
 Truncates anything that does not fit and zero-fills the tail, so the buffer is always null-terminated and a recycled object can never leak the previous value past the terminator.
void clear () noexcept
const char * c_str () const noexcept
const char * data () const noexcept
char * data () noexcept
size_t size () const noexcept
bool empty () const noexcept
std::string_view view () const noexcept
 operator std::string_view () const noexcept
std::string str () const

Static Public Member Functions

static constexpr size_t capacity () noexcept
static constexpr size_t buffer_size () noexcept

Friends

bool operator== (const fixed_string &lhs, std::string_view rhs) noexcept
bool operator== (const fixed_string &lhs, const fixed_string &rhs) noexcept
std::ostream & operator<< (std::ostream &os, const fixed_string &value)

Detailed Description

template<size_t N>
class slick::sim::utils::fixed_string< N >

A null-terminated character buffer of fixed capacity, stored inline.

Order and Symbol use it for identity fields bounded by their wire formats. These fields are written once and read often; inline storage avoids heap allocations on pooled objects in the order path.

The layout is exactly char[N], with no size field or pointer. Consecutive fields therefore match a wire header byte for byte and can be copied with one memcpy. size() scans at most N bytes with strnlen, so avoid calling it repeatedly in a hot loop.

Values are truncated to N-1 characters, matching the wire fields' limit.

Definition at line 48 of file fixed_string.hpp.

Constructor & Destructor Documentation

◆ fixed_string() [1/3]

template<size_t N>
slick::sim::utils::fixed_string< N >::fixed_string ( )
default

◆ fixed_string() [2/3]

template<size_t N>
slick::sim::utils::fixed_string< N >::fixed_string ( std::string_view value)
inlinenoexcept

Definition at line 55 of file fixed_string.hpp.

◆ fixed_string() [3/3]

template<size_t N>
slick::sim::utils::fixed_string< N >::fixed_string ( const char * value)
inlinenoexcept

Definition at line 56 of file fixed_string.hpp.

Member Function Documentation

◆ assign()

template<size_t N>
void slick::sim::utils::fixed_string< N >::assign ( std::string_view value)
inlinenoexcept

Truncates anything that does not fit and zero-fills the tail, so the buffer is always null-terminated and a recycled object can never leak the previous value past the terminator.

Definition at line 67 of file fixed_string.hpp.

Referenced by slick::sim::utils::fixed_string< sizeof(MarketDataUpdate::symbol)>::fixed_string(), slick::sim::utils::fixed_string< sizeof(MarketDataUpdate::symbol)>::fixed_string(), slick::sim::utils::fixed_string< sizeof(MarketDataUpdate::symbol)>::operator=(), and slick::sim::utils::fixed_string< sizeof(MarketDataUpdate::symbol)>::operator=().

◆ buffer_size()

template<size_t N>
constexpr size_t slick::sim::utils::fixed_string< N >::buffer_size ( )
inlinestaticconstexprnoexcept

Definition at line 78 of file fixed_string.hpp.

◆ c_str()

template<size_t N>
const char * slick::sim::utils::fixed_string< N >::c_str ( ) const
inlinenoexcept

Definition at line 71 of file fixed_string.hpp.

Referenced by slick::sim::order_gateway::coinbase::to_json().

◆ capacity()

template<size_t N>
constexpr size_t slick::sim::utils::fixed_string< N >::capacity ( )
inlinestaticconstexprnoexcept

Definition at line 77 of file fixed_string.hpp.

◆ clear()

template<size_t N>
void slick::sim::utils::fixed_string< N >::clear ( )
inlinenoexcept

Definition at line 69 of file fixed_string.hpp.

◆ data() [1/2]

◆ data() [2/2]

template<size_t N>
char * slick::sim::utils::fixed_string< N >::data ( )
inlinenoexcept

Definition at line 73 of file fixed_string.hpp.

◆ empty()

◆ operator std::string_view()

template<size_t N>
slick::sim::utils::fixed_string< N >::operator std::string_view ( ) const
inlinenoexcept

Definition at line 81 of file fixed_string.hpp.

◆ operator=() [1/2]

template<size_t N>
fixed_string & slick::sim::utils::fixed_string< N >::operator= ( const char * value)
inlinenoexcept

Definition at line 59 of file fixed_string.hpp.

◆ operator=() [2/2]

template<size_t N>
fixed_string & slick::sim::utils::fixed_string< N >::operator= ( std::string_view value)
inlinenoexcept

Definition at line 58 of file fixed_string.hpp.

◆ size()

template<size_t N>
size_t slick::sim::utils::fixed_string< N >::size ( ) const
inlinenoexcept

◆ str()

template<size_t N>
std::string slick::sim::utils::fixed_string< N >::str ( ) const
inline

Definition at line 82 of file fixed_string.hpp.

Referenced by slick::sim::order_gateway::OrderStore::apply().

◆ view()

◆ operator<<

template<size_t N>
std::ostream & operator<< ( std::ostream & os,
const fixed_string< N > & value )
friend

Definition at line 91 of file fixed_string.hpp.

◆ operator== [1/2]

template<size_t N>
bool operator== ( const fixed_string< N > & lhs,
const fixed_string< N > & rhs )
friend

Definition at line 87 of file fixed_string.hpp.

◆ operator== [2/2]

template<size_t N>
bool operator== ( const fixed_string< N > & lhs,
std::string_view rhs )
friend

Definition at line 84 of file fixed_string.hpp.


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