Cbeam
Loading...
Searching...
No Matches
cbeam::container::nested_map< Key, Value > Struct Template Reference

A map structure that can store nested maps of keys and values. By including serialization/nested_map.hpp, it gains serialization capability. More...

#include <nested_map.hpp>

Public Types

using table_of_values = std::map<Key, Value>
 A table mapping keys to values, capable of storing the actual data elements for serialization.
 
using nested_tables = std::map<Key, nested_map<Key, Value>>
 A map of keys to nested nested_map instances, allowing hierarchical data organization.
 
using key_type = Key
 
using mapped_type = Value
 

Public Member Functions

 nested_map ()=default
 construct empty table
 
 nested_map (std::initializer_list< std::pair< const Key, Value > > init)
 
nested_mapoperator= (const nested_map &other)
 overwrite this nested_map with a copy of the other
 
void merge (const nested_map &other)
 merges the other nested_map into this
 
void clear ()
 
template<typename T>
std::enable_if< std::is_same< T, Value >::value, T >::type get_mapped_value_or_default (const Key &key) const
 Retrieves a value of type T associated with a given key from the map's values.
 
template<typename T>
std::enable_if<!std::is_same< T, Value >::value, T >::type get_mapped_value_or_default (const Key &value) const
 Retrieves a value of type T associated with a given key from the map's values.
 
template<std::size_t T>
auto get_mapped_value_or_default (const Key &value) const
 Retrieves a value from a std::variant associated with a given key, based on a type index.
 
template<typename T>
std::enable_if< std::is_same< T, Value >::value, T >::type get_mapped_value_or_throw (const Key &value, const std::string &error_msg={}) const
 Retrieves the value associated with a given key, throwing an exception if the key is not found.
 
template<typename T>
std::enable_if<!std::is_same< T, Value >::value, T >::type get_mapped_value_or_throw (const Key &value, const std::string &error_msg={}) const
 Retrieves the value associated with a given key, throwing an exception if the key is not found or the type does not match.
 
template<std::size_t T>
auto get_mapped_value_or_throw (const Key &value, const std::string &error_msg={}) const
 Retrieves a value from a std::variant associated with a given key, based on a type index.
 

Public Attributes

table_of_values data
 key value pairs of Value instances that store the actual data
 
nested_tables sub_tables
 list of sub tables, each having a unique name
 

Detailed Description

template<typename Key, typename Value>
struct cbeam::container::nested_map< Key, Value >

A map structure that can store nested maps of keys and values. By including serialization/nested_map.hpp, it gains serialization capability.

Member Typedef Documentation

◆ key_type

template<typename Key, typename Value>
using cbeam::container::nested_map< Key, Value >::key_type = Key

◆ mapped_type

template<typename Key, typename Value>
using cbeam::container::nested_map< Key, Value >::mapped_type = Value

◆ nested_tables

template<typename Key, typename Value>
using cbeam::container::nested_map< Key, Value >::nested_tables = std::map<Key, nested_map<Key, Value>>

A map of keys to nested nested_map instances, allowing hierarchical data organization.

◆ table_of_values

template<typename Key, typename Value>
using cbeam::container::nested_map< Key, Value >::table_of_values = std::map<Key, Value>

A table mapping keys to values, capable of storing the actual data elements for serialization.

Constructor & Destructor Documentation

◆ nested_map() [1/2]

template<typename Key, typename Value>
cbeam::container::nested_map< Key, Value >::nested_map ( )
default

construct empty table

◆ nested_map() [2/2]

template<typename Key, typename Value>
cbeam::container::nested_map< Key, Value >::nested_map ( std::initializer_list< std::pair< const Key, Value > > init)
inline

Member Function Documentation

◆ clear()

template<typename Key, typename Value>
void cbeam::container::nested_map< Key, Value >::clear ( )
inline

◆ get_mapped_value_or_default() [1/3]

template<typename Key, typename Value>
template<typename T>
std::enable_if< std::is_same< T, Value >::value, T >::type cbeam::container::nested_map< Key, Value >::get_mapped_value_or_default ( const Key & key) const
inline

Retrieves a value of type T associated with a given key from the map's values.

This function template fetches the value of type T associated with the specified key in the nested_map. If the key is not found in the map, a default-constructed value of type T is returned.

Template Parameters
TThe type to be retrieved from the map's value. If the map uses std::variant as the value type, T is interpreted as the type to retrieve from the std::variant.
Parameters
keyThe key whose value is to be retrieved.
Returns
The value of type T associated with the key if it exists, or a default-constructed value of type T if the key is not found.

◆ get_mapped_value_or_default() [2/3]

template<typename Key, typename Value>
template<typename T>
std::enable_if<!std::is_same< T, Value >::value, T >::type cbeam::container::nested_map< Key, Value >::get_mapped_value_or_default ( const Key & value) const
inline

Retrieves a value of type T associated with a given key from the map's values.

This function template fetches the value of type T associated with the specified key in the nested_map. If the map's value type is std::variant, T is interpreted as the specific type to be extracted from the std::variant. If the key is not found in the map, a default-constructed value of type T is returned.

Template Parameters
TThe type to be retrieved from the map's value. If T is not the value type of the nested_map, T is interpreted as the type to retrieve from the std::variant.
Parameters
keyThe key whose value is to be retrieved.
Returns
The value of type T associated with the key if it exists, or a default-constructed value of type T if the key is not found.

◆ get_mapped_value_or_default() [3/3]

template<typename Key, typename Value>
template<std::size_t T>
auto cbeam::container::nested_map< Key, Value >::get_mapped_value_or_default ( const Key & value) const
inline

Retrieves a value from a std::variant associated with a given key, based on a type index.

This function template is specialized for maps where the value type is std::variant. It fetches the value associated with the specified key and extracts the value at the specified type index within the std::variant. If the key is not found in the map, a default-constructed value of the type at the given index in the std::variant is returned.

Template Parameters
TThe type index within the std::variant from which to retrieve the value.
Parameters
keyThe key whose value, a std::variant, is to be retrieved and inspected.
Returns
The value at the specified type index within the std::variant if the key exists; otherwise, a default-constructed value of the corresponding type.

◆ get_mapped_value_or_throw() [1/3]

template<typename Key, typename Value>
template<typename T>
std::enable_if< std::is_same< T, Value >::value, T >::type cbeam::container::nested_map< Key, Value >::get_mapped_value_or_throw ( const Key & value,
const std::string & error_msg = {} ) const
inline

Retrieves the value associated with a given key, throwing an exception if the key is not found.

This function template attempts to retrieve the value associated with the specified key in the nested_map. This template specialization is used if T is the Value type. if the key is found, it returns the associated value, otherwise an exception is thrown.

Template Parameters
TThe type of the value to be retrieved.
Parameters
keyThe key whose value is to be retrieved.
error_msgOptional custom error message for the exception. If empty, a default message is used.
Returns
The value associated with the key of type T.
Exceptions
cbeam::error::runtime_errorif the key is not found or if the type T does not match the value's type.

◆ get_mapped_value_or_throw() [2/3]

template<typename Key, typename Value>
template<typename T>
std::enable_if<!std::is_same< T, Value >::value, T >::type cbeam::container::nested_map< Key, Value >::get_mapped_value_or_throw ( const Key & value,
const std::string & error_msg = {} ) const
inline

Retrieves the value associated with a given key, throwing an exception if the key is not found or the type does not match.

This function template is specialized for maps where the value type is std::variant. It attempts to retrieve the value associated with the specified key in the nested_map. If T is one of the types in the variant, it attempts to retrieve the value of type T from the variant. If the key is not found, or if the type T is not compatible with the stored value, an exception is thrown.

Template Parameters
TThe type of the value to be retrieved.
Parameters
keyThe key whose value is to be retrieved.
error_msgOptional custom error message for the exception. If empty, a default message is used.
Returns
The value associated with the key of type T.
Exceptions
cbeam::error::runtime_errorif the key is not found or if the type T does not match the value's type.

◆ get_mapped_value_or_throw() [3/3]

template<typename Key, typename Value>
template<std::size_t T>
auto cbeam::container::nested_map< Key, Value >::get_mapped_value_or_throw ( const Key & value,
const std::string & error_msg = {} ) const
inline

Retrieves a value from a std::variant associated with a given key, based on a type index.

This function template is specialized for maps where the value type is std::variant. It fetches the value associated with the specified key and extracts the value at the specified type index within the std::variant. If the key is not found in the map, an exception is thrown.

Template Parameters
TThe type index within the std::variant from which to retrieve the value.
Parameters
keyThe key whose value, a std::variant, is to be retrieved and inspected.
error_msgOptional custom error message for the exception. If empty, a default message is used.
Returns
The value at the specified type index within the std::variant if the key exists; otherwise, a default-constructed value of the corresponding type.

◆ merge()

template<typename Key, typename Value>
void cbeam::container::nested_map< Key, Value >::merge ( const nested_map< Key, Value > & other)
inline

merges the other nested_map into this

◆ operator=()

template<typename Key, typename Value>
nested_map & cbeam::container::nested_map< Key, Value >::operator= ( const nested_map< Key, Value > & other)
inline

overwrite this nested_map with a copy of the other

Member Data Documentation

◆ data

template<typename Key, typename Value>
table_of_values cbeam::container::nested_map< Key, Value >::data

key value pairs of Value instances that store the actual data

◆ sub_tables

template<typename Key, typename Value>
nested_tables cbeam::container::nested_map< Key, Value >::sub_tables

list of sub tables, each having a unique name


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