5#include <unordered_map>
16 const std::out_of_range& e,
17 const std::string& key,
18 const std::unordered_map<std::string, std::any>& data
38 Dictionary(
const std::unordered_map<std::string, std::any>& keyValuePairs);
40 Dictionary(
const std::initializer_list<std::pair<std::string, std::any>>& initList);
47 void insert(
const std::string& key,
const std::any& value);
54 [[nodiscard]]
bool contains(
const std::string& key)
const;
71 [[nodiscard]] std::any&
operator[](
const std::string& key);
78 [[nodiscard]]
const std::any&
operator[](
const std::string& key)
const;
89 [[nodiscard]] T&
get(
const std::string& key)
93 return std::any_cast<T&>(
operator[](key));
95 catch (
const std::bad_any_cast& e)
97 logBadAnyCast<T>(e, key, data_);
111 [[nodiscard]]
const T&
get(
const std::string& key)
const
115 return std::any_cast<const T&>(
operator[](key));
117 catch (
const std::bad_any_cast& e)
119 logBadAnyCast<T>(e, key, data_);
129 [[nodiscard]]
bool isDict(
const std::string& key)
const;
149 std::vector<std::string>
keys()
const;
155 std::unordered_map<std::string, std::any>&
getMap();
161 const std::unordered_map<std::string, std::any>&
getMap()
const;
167 bool empty()
const {
return data_.empty(); }
171 std::unordered_map<std::string, std::any> data_;
A class representing a dictionary that stores key-value pairs.
std::any & operator[](const std::string &key)
Accesses the value associated with the given key.
void insert(const std::string &key, const std::any &value)
Inserts a key-value pair into the dictionary.
void remove(const std::string &key)
Removes an entry from the dictionary based on the specified key.
Dictionary(const std::unordered_map< std::string, std::any > &keyValuePairs)
std::vector< std::string > keys() const
Retrieves the keys of the dictionary.
Dictionary(const std::initializer_list< std::pair< std::string, std::any > > &initList)
const std::any & operator[](const std::string &key) const
Accesses the value associated with the given key.
bool empty() const
Checks whether the dictionary is empty.
bool contains(const std::string &key) const
Checks if the given key is present in the dictionary.
bool isDict(const std::string &key) const
Checks if the value associated with the given key is a dictionary.
const T & get(const std::string &key) const
Retrieves the value associated with the given key, casting it to the specified type.
const Dictionary & subDict(const std::string &key) const
Retrieves a sub-dictionary associated with the given key.
std::unordered_map< std::string, std::any > & getMap()
Retrieves the underlying unordered map of the dictionary.
T & get(const std::string &key)
Retrieves the value associated with the given key, casting it to the specified type.
const std::unordered_map< std::string, std::any > & getMap() const
Retrieves the underlying unordered map of the dictionary.
Dictionary & subDict(const std::string &key)
Retrieves a sub-dictionary associated with the given key.
void logOutRange(const std::out_of_range &e, const std::string &key, const std::unordered_map< std::string, std::any > &data)