|
NeoN
A framework for CFD software
|
A class representing a dictionary that stores key-value pairs. More...
#include <dictionary.hpp>
Public Member Functions | |
| Dictionary ()=default | |
| Dictionary (const std::unordered_map< std::string, std::any > &keyValuePairs) | |
| Dictionary (const std::initializer_list< std::pair< std::string, std::any > > &initList) | |
| void | insert (const std::string &key, const std::any &value) |
| Inserts a key-value pair into the dictionary. | |
| bool | contains (const std::string &key) const |
| Checks if the given key is present in the dictionary. | |
| void | remove (const std::string &key) |
| Removes an entry from the dictionary based on the specified key. | |
| std::any & | operator[] (const std::string &key) |
| Accesses the value associated with the given key. | |
| const std::any & | operator[] (const std::string &key) const |
| Accesses the value associated with the given key. | |
| template<typename T > | |
| T & | get (const std::string &key) |
| Retrieves the value associated with the given key, casting it to the specified type. | |
| template<typename T > | |
| const T & | get (const std::string &key) const |
| Retrieves the value associated with the given key, casting it to the specified type. | |
| template<typename T > | |
| const T | get (const std::string &key, T defaultValue) const |
| Retrieves the value associated with the given key, casting it to the specified type. | |
| template<typename T > | |
| bool | isType (const std::string &key) const |
| Checks if the value associated with the given key is of given Type T. | |
| bool | isDict (const std::string &key) const |
| Checks if the value associated with the given key is a dictionary. | |
| Dictionary & | subDict (const std::string &key) |
| Retrieves a sub-dictionary associated with the given key. | |
| const Dictionary & | subDict (const std::string &key) const |
| Retrieves a sub-dictionary associated with the given key. | |
| std::vector< std::string > | keys () const |
| Retrieves the keys of the dictionary. | |
| std::unordered_map< std::string, std::any > & | getMap () |
| Retrieves the underlying unordered map of the dictionary. | |
| const std::unordered_map< std::string, std::any > & | getMap () const |
| Retrieves the underlying unordered map of the dictionary. | |
| bool | empty () const |
| Checks whether the dictionary is empty. | |
A class representing a dictionary that stores key-value pairs.
The Dictionary class provides a way to store and retrieve values using string. It supports inserting key-value pairs, accessing values using the subscript operator, and retrieving values of specific types using the get function. It also supports storing sub-dictionaries, which can be accessed using the subDict function. The values are stored using std::any, which allows storing values of any type.
Definition at line 49 of file dictionary.hpp.
|
default |
| NeoN::Dictionary::Dictionary | ( | const std::unordered_map< std::string, std::any > & | keyValuePairs | ) |
| NeoN::Dictionary::Dictionary | ( | const std::initializer_list< std::pair< std::string, std::any > > & | initList | ) |
| bool NeoN::Dictionary::contains | ( | const std::string & | key | ) | const |
Checks if the given key is present in the dictionary.
| key | The key to check. |
|
inline |
Checks whether the dictionary is empty.
Definition at line 214 of file dictionary.hpp.
|
inline |
Retrieves the value associated with the given key, casting it to the specified type.
| T | The type to cast the value to. |
| key | The key to retrieve the value for. |
Definition at line 106 of file dictionary.hpp.
|
inline |
Retrieves the value associated with the given key, casting it to the specified type.
| T | The type to cast the value to. |
| key | The key to retrieve the value for. |
Definition at line 128 of file dictionary.hpp.
|
inline |
Retrieves the value associated with the given key, casting it to the specified type.
| T | The type to cast the value to. |
| key | The key to retrieve the value for. |
Definition at line 150 of file dictionary.hpp.
| std::unordered_map< std::string, std::any > & NeoN::Dictionary::getMap | ( | ) |
Retrieves the underlying unordered map of the dictionary.
| const std::unordered_map< std::string, std::any > & NeoN::Dictionary::getMap | ( | ) | const |
Retrieves the underlying unordered map of the dictionary.
| void NeoN::Dictionary::insert | ( | const std::string & | key, |
| const std::any & | value | ||
| ) |
Inserts a key-value pair into the dictionary.
| key | The key to insert. |
| value | The value to insert. |
| bool NeoN::Dictionary::isDict | ( | const std::string & | key | ) | const |
Checks if the value associated with the given key is a dictionary.
| key | The key to check. |
|
inline |
Checks if the value associated with the given key is of given Type T.
| key | The key to check. |
Definition at line 165 of file dictionary.hpp.
| std::vector< std::string > NeoN::Dictionary::keys | ( | ) | const |
Retrieves the keys of the dictionary.
| std::any & NeoN::Dictionary::operator[] | ( | const std::string & | key | ) |
Accesses the value associated with the given key.
| key | The key to access. |
| const std::any & NeoN::Dictionary::operator[] | ( | const std::string & | key | ) | const |
Accesses the value associated with the given key.
| key | The key to access. |
| void NeoN::Dictionary::remove | ( | const std::string & | key | ) |
Removes an entry from the dictionary based on the specified key.
This function removes the entry with the specified key from the dictionary.
| key | The key of the entry to be removed. |
| Dictionary & NeoN::Dictionary::subDict | ( | const std::string & | key | ) |
Retrieves a sub-dictionary associated with the given key.
| key | The key to retrieve the sub-dictionary for. |
| const Dictionary & NeoN::Dictionary::subDict | ( | const std::string & | key | ) | const |
Retrieves a sub-dictionary associated with the given key.
| key | The key to retrieve the sub-dictionary for. |