algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::Code< N > Class Template Reference

A short uppercase code (letters, digits, _), stored inline without allocation. More...

#include <algotradelib/src/core/types.hpp>

Inheritance diagram for algotradelib::Code< N >:

Public Member Functions

 Code ()=default
 Constructs an empty code.
 Code (std::string_view text)
 Constructs a code.
std::string_view view () const noexcept
 Returns the code's characters.
std::string str () const
 Returns the code as a string.
bool empty () const noexcept
 Tests whether the code is empty.
std::size_t size () const noexcept
 Returns the number of characters.

Static Public Member Functions

static std::optional< Code > try_make (std::string_view text)
 Makes a code without throwing.
static constexpr std::size_t capacity () noexcept
 Returns the maximum number of characters.

Friends

bool operator== (const Code &lhs, const Code &rhs)
 Compares two codes' characters.
bool operator!= (const Code &lhs, const Code &rhs)
 Compares two codes for inequality.

Detailed Description

template<std::size_t N>
class algotradelib::Code< N >

A short uppercase code (letters, digits, _), stored inline without allocation.

The length is stored in one byte, so N must be at most 255.

Holds a broker code the library may not recognize (a market segment, an exchange id) exactly as sent, so it can be carried, compared and displayed.

Template Parameters
NThe maximum number of characters.

Definition at line 131 of file types.hpp.

Constructor & Destructor Documentation

◆ Code() [1/2]

template<std::size_t N>
algotradelib::Code< N >::Code ( )
default

Constructs an empty code.

Referenced by operator!=, operator==, and try_make().

◆ Code() [2/2]

template<std::size_t N>
algotradelib::Code< N >::Code ( std::string_view text)
inlineexplicit

Constructs a code.

Parameters
textUp to N characters, each A-Z, 0-9 or _.
Exceptions
std::invalid_argumentif text is longer than N or has any other character.

Definition at line 142 of file types.hpp.

Member Function Documentation

◆ capacity()

template<std::size_t N>
constexpr std::size_t algotradelib::Code< N >::capacity ( )
inlinestaticconstexprnoexcept

Returns the maximum number of characters.

Returns
N.

Definition at line 210 of file types.hpp.

◆ empty()

template<std::size_t N>
bool algotradelib::Code< N >::empty ( ) const
inlinenoexcept

Tests whether the code is empty.

Returns
true if it has no characters.

Definition at line 198 of file types.hpp.

Referenced by algotradelib::CommissionRate::normalized(), and algotradelib::MarketSegment::str().

◆ size()

template<std::size_t N>
std::size_t algotradelib::Code< N >::size ( ) const
inlinenoexcept

Returns the number of characters.

Returns
The length, at most N.

Definition at line 204 of file types.hpp.

◆ str()

template<std::size_t N>
std::string algotradelib::Code< N >::str ( ) const
inline

Returns the code as a string.

Returns
A copy of the characters.

Definition at line 192 of file types.hpp.

Referenced by algotradelib::MarketSegment::str().

◆ try_make()

template<std::size_t N>
std::optional< Code > algotradelib::Code< N >::try_make ( std::string_view text)
inlinestatic

Makes a code without throwing.

Parameters
textUp to N characters, each A-Z, 0-9 or _.
Returns
The code, or std::nullopt if text is too long or has any other character.

Definition at line 163 of file types.hpp.

Referenced by algotradelib::market_segment(), and algotradelib::VenueKey::raw().

◆ view()

template<std::size_t N>
std::string_view algotradelib::Code< N >::view ( ) const
inlinenoexcept

Returns the code's characters.

Returns
A view of the code's own storage, valid while the code is alive.

Definition at line 184 of file types.hpp.

Referenced by operator==, and str().

◆ operator!=

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

Compares two codes for inequality.

Parameters
lhsThe first code.
rhsThe second code.
Returns
true if they differ.

Definition at line 226 of file types.hpp.

◆ operator==

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

Compares two codes' characters.

Parameters
lhsThe first code.
rhsThe second code.
Returns
true if they are equal.

Definition at line 218 of file types.hpp.


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