ITCHCPP 1.6.1
High-Performance NASDAQ TotalView-ITCH 5.0 Parser & Market-Data Platform
Loading...
Searching...
No Matches
itch::indicators::FrozenMap< KeyType, Size > Class Template Reference

An immutable, compile-time lookup table from a key to a description. More...

#include <indicators.hpp>

Public Types

using value_type = std::pair< KeyType, std::string_view >
 

Public Member Functions

constexpr FrozenMap (std::array< value_type, Size > entries) noexcept
 Constructs the map from an unsorted list of key/description entries, sorting them by key once so that find can binary search.
 
constexpr auto find (const KeyType &key) const noexcept -> std::optional< std::string_view >
 Returns the description for a key, or std::nullopt if absent.
 
constexpr auto at_or (const KeyType &key, std::string_view fallback) const noexcept -> std::string_view
 Returns the description for a key, or a fallback if absent.
 

Detailed Description

template<typename KeyType, std::size_t Size>
class itch::indicators::FrozenMap< KeyType, Size >

An immutable, compile-time lookup table from a key to a description.

Replaces the namespace-scope std::map globals that this header used to define: those incurred dynamic initialization in every translation unit and risked one-definition-rule trouble. A FrozenMap is a literal type held in read-only storage. Its entries are sorted once at compile time, so lookups are a branch-light binary search with no allocation and no runtime setup.

Template Parameters
KeyTypeThe key type (char for single-letter codes, or std::string_view for multi-character codes).
SizeThe number of entries.

Definition at line 35 of file indicators.hpp.

Member Typedef Documentation

◆ value_type

template<typename KeyType , std::size_t Size>
using itch::indicators::FrozenMap< KeyType, Size >::value_type = std::pair<KeyType, std::string_view>

Definition at line 37 of file indicators.hpp.

Constructor & Destructor Documentation

◆ FrozenMap()

template<typename KeyType , std::size_t Size>
constexpr itch::indicators::FrozenMap< KeyType, Size >::FrozenMap ( std::array< value_type, Size >  entries)
inlineexplicitconstexprnoexcept

Constructs the map from an unsorted list of key/description entries, sorting them by key once so that find can binary search.

Parameters
entriesThe key/description pairs backing this map, in any order.

Definition at line 44 of file indicators.hpp.

Member Function Documentation

◆ find()

template<typename KeyType , std::size_t Size>
constexpr auto itch::indicators::FrozenMap< KeyType, Size >::find ( const KeyType &  key) const -> std::optional<std::string_view>
inlineconstexprnoexcept

Returns the description for a key, or std::nullopt if absent.

Parameters
keyThe key to look up.
Returns
The matching description, or std::nullopt if no entry has this key.

Definition at line 53 of file indicators.hpp.

Referenced by itch::indicators::FrozenMap< KeyType, Size >::at_or().

◆ at_or()

template<typename KeyType , std::size_t Size>
constexpr auto itch::indicators::FrozenMap< KeyType, Size >::at_or ( const KeyType &  key,
std::string_view  fallback 
) const -> std::string_view
inlineconstexprnoexcept

Returns the description for a key, or a fallback if absent.

Parameters
keyThe key to look up.
fallbackThe description to return when key is not found.
Returns
The matching description, or fallback if no entry has this key.

Definition at line 67 of file indicators.hpp.

References itch::indicators::FrozenMap< KeyType, Size >::find().

Referenced by itch::analytics::cross_type_name(), and itch::analytics::imbalance_direction_name().


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