7#include <unordered_map>
18 const std::out_of_range& e,
19 const std::string& key,
20 const std::unordered_map<std::string, std::any>& data
40 Dictionary(
const std::unordered_map<std::string, std::any>& keyValuePairs);
42 Dictionary(
const std::initializer_list<std::pair<std::string, std::any>>& initList);
49 void insert(
const std::string& key,
const std::any& value);
56 [[nodiscard]]
bool contains(
const std::string& key)
const;
73 [[nodiscard]] std::any&
operator[](
const std::string& key);
80 [[nodiscard]]
const std::any&
operator[](
const std::string& key)
const;
91 [[nodiscard]] T&
get(
const std::string& key)
95 return std::any_cast<T&>(
operator[](key));
97 catch (
const std::bad_any_cast& e)
99 logBadAnyCast<T>(e, key, data_);
113 [[nodiscard]]
const T&
get(
const std::string& key)
const
117 return std::any_cast<const T&>(
operator[](key));
119 catch (
const std::bad_any_cast& e)
121 logBadAnyCast<T>(e, key, data_);
131 [[nodiscard]]
bool isDict(
const std::string& key)
const;
151 std::vector<std::string>
keys()
const;
157 std::unordered_map<std::string, std::any>&
getMap();
163 const std::unordered_map<std::string, std::any>&
getMap()
const;
169 bool empty()
const {
return data_.empty(); }
173 std::unordered_map<std::string, std::any> data_;
A class representing a dictionary that stores key-value pairs.
void remove(const std::string &key)
Removes an entry from the dictionary based on the specified key.
bool isDict(const std::string &key) const
Checks if the value associated with the given key is a dictionary.
T & get(const std::string &key)
Retrieves the value associated with the given key, casting it to the specified type.
const T & get(const std::string &key) const
Retrieves the value associated with the given key, casting it to the specified type.
std::any & operator[](const std::string &key)
Accesses the value associated with the given key.
Dictionary & subDict(const std::string &key)
Retrieves a sub-dictionary associated with the given key.
const std::any & operator[](const std::string &key) const
Accesses the value associated with the given key.
const std::unordered_map< std::string, std::any > & getMap() const
Retrieves the underlying unordered map of the dictionary.
const Dictionary & subDict(const std::string &key) const
Retrieves a sub-dictionary associated with the given key.
Dictionary(const std::initializer_list< std::pair< std::string, std::any > > &initList)
std::vector< std::string > keys() const
Retrieves the keys of the dictionary.
void insert(const std::string &key, const std::any &value)
Inserts a key-value pair into the dictionary.
bool empty() const
Checks whether the dictionary is empty.
std::unordered_map< std::string, std::any > & getMap()
Retrieves the underlying unordered map of the dictionary.
bool contains(const std::string &key) const
Checks if the given key is present in the dictionary.
Dictionary(const std::unordered_map< std::string, std::any > &keyValuePairs)
std::ostream & operator<<(std::ostream &os, const Dictionary &in)
void logOutRange(const std::out_of_range &e, const std::string &key, const std::unordered_map< std::string, std::any > &data)