7#include <unordered_map>
19 const std::out_of_range& e,
20 const std::string& key,
21 const std::unordered_map<std::string, std::any>& data
30template<
typename HoldType>
55 Dictionary(
const std::unordered_map<std::string, std::any>& keyValuePairs);
57 Dictionary(
const std::initializer_list<std::pair<std::string, std::any>>& initList);
64 void insert(
const std::string& key,
const std::any& value);
71 [[nodiscard]]
bool contains(
const std::string& key)
const;
88 [[nodiscard]] std::any&
operator[](
const std::string& key);
95 [[nodiscard]]
const std::any&
operator[](
const std::string& key)
const;
106 [[nodiscard]] T&
get(
const std::string& key)
110 return std::any_cast<T&>(
operator[](key));
112 catch (
const std::bad_any_cast& e)
114 logBadAnyCast<T>(e, key, data_);
128 [[nodiscard]]
const T&
get(
const std::string& key)
const
132 return std::any_cast<const T&>(
operator[](key));
134 catch (
const std::bad_any_cast& e)
136 logBadAnyCast<T>(e, key, data_);
150 [[nodiscard]]
const T
get(
const std::string& key, T defaultValue)
const
154 return T(get<T>(key));
165 [[nodiscard]]
bool isType(
const std::string& key)
const
167 return contains(key) && std::any_cast<T>(&data_.at(key));
175 [[nodiscard]]
bool isDict(
const std::string& key)
const;
196 std::vector<std::string>
keys()
const;
202 std::unordered_map<std::string, std::any>&
getMap();
208 const std::unordered_map<std::string, std::any>&
getMap()
const;
214 bool empty()
const {
return data_.empty(); }
218 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, T defaultValue) const
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.
bool isType(const std::string &key) const
Checks if the value associated with the given key is of given Type T.
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)
Integer types used throughout NeoN.
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)
A wrapper class to put references in dictionaries to overcome the issue that std::any cannot hold a r...
#define NEON_TYPE_VISIBLE