42 template <
typename Key,
typename Value>
52 nested_map(std::initializer_list<std::pair<const Key, Value>> init)
54 for (
const auto& [key, value] : init)
80 for (
const auto& it : other.
data)
82 data[it.first] = it.second;
108 template <
typename T>
109 typename std::enable_if<std::is_same<T, Value>::value, T>::type
112 auto it =
data.find(key);
114 if (it ==
data.end())
135 template <
typename T>
136 typename std::enable_if<!std::is_same<T, Value>::value, T>::type
139 auto it =
data.find(value);
141 if (it ==
data.end())
162 template <std::
size_t T>
165 auto it =
data.find(value);
167 if (it ==
data.end())
189 template <
typename T>
190 typename std::enable_if<std::is_same<T, Value>::value, T>::type
193 using namespace std::string_literals;
195 typename table_of_values::iterator it =
data.find(value);
197 if (it !=
data.end())
218 template <
typename T>
219 typename std::enable_if<!std::is_same<T, Value>::value, T>::type
222 using namespace std::string_literals;
225 typename table_of_values::iterator it = instance->
data.find(value);
227 if (it != instance->
data.end())
229 T* ptr = std::get_if<T>(&it->second);
241 throw cbeam::error::runtime_error(error_msg.empty() ?
"get_mapped_value_or_throw: missing value"s : error_msg);
256 template <std::
size_t T>
259 using namespace std::string_literals;
261 auto it =
data.find(value);
263 if (it !=
data.end())
265 auto* ptr = std::get_if<T>(&it->second);
277 throw cbeam::error::runtime_error(error_msg.empty() ?
"get_mapped_value_or_throw: missing value"s : error_msg);
281 template <
typename Key,
typename Value>
A Cbeam-specific runtime error that also acts like std::runtime_error.
Definition runtime_error.hpp:46
Offers advanced container types with unique approaches to stability and interprocess sharing....
Definition buffer.hpp:44
T get_value_or_default(const std::variant< Types... > &value) noexcept
Definition find.hpp:78
bool operator==(const nested_map< Key, Value > &lhs, const nested_map< Key, Value > &rhs)
Definition nested_map.hpp:282
A map structure that can store nested maps of keys and values. By including serialization/nested_map....
Definition nested_map.hpp:44
Key key_type
Definition nested_map.hpp:47
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.
Definition nested_map.hpp:163
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.
Definition nested_map.hpp:257
nested_map(std::initializer_list< std::pair< const Key, Value > > init)
Definition nested_map.hpp:52
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...
Definition nested_map.hpp:220
std::map< Key, nested_map< Key, Value > > nested_tables
A map of keys to nested nested_map instances, allowing hierarchical data organization.
Definition nested_map.hpp:46
std::map< Key, Value > table_of_values
A table mapping keys to values, capable of storing the actual data elements for serialization.
Definition nested_map.hpp:45
Value mapped_type
Definition nested_map.hpp:48
nested_map & operator=(const nested_map &other)
overwrite this nested_map with a copy of the other
Definition nested_map.hpp:64
nested_tables sub_tables
Definition nested_map.hpp:61
nested_map()=default
construct empty table
void clear()
Definition nested_map.hpp:91
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.
Definition nested_map.hpp:110
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.
Definition nested_map.hpp:191
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.
Definition nested_map.hpp:137
table_of_values data
Definition nested_map.hpp:60
void merge(const nested_map &other)
merges the other nested_map into this
Definition nested_map.hpp:78