A class representing a dictionary that stores key-value pairs.
More...
#include <dictionary.hpp>
|
| 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.
|
|
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 32 of file dictionary.hpp.
◆ Dictionary() [1/3]
NeoFOAM::Dictionary::Dictionary |
( |
| ) |
|
|
default |
◆ Dictionary() [2/3]
NeoFOAM::Dictionary::Dictionary |
( |
const std::unordered_map< std::string, std::any > & |
keyValuePairs | ) |
|
◆ Dictionary() [3/3]
NeoFOAM::Dictionary::Dictionary |
( |
const std::initializer_list< std::pair< std::string, std::any > > & |
initList | ) |
|
◆ contains()
bool NeoFOAM::Dictionary::contains |
( |
const std::string & |
key | ) |
const |
Checks if the given key is present in the dictionary.
- Parameters
-
- Returns
- True if the key is present, false otherwise.
◆ empty()
bool NeoFOAM::Dictionary::empty |
( |
| ) |
const |
|
inline |
Checks whether the dictionary is empty.
- Returns
- A bool indicating if the dictionary is empty
Definition at line 167 of file dictionary.hpp.
◆ get() [1/2]
template<typename T >
T & NeoFOAM::Dictionary::get |
( |
const std::string & |
key | ) |
|
|
inline |
Retrieves the value associated with the given key, casting it to the specified type.
- Template Parameters
-
T | The type to cast the value to. |
- Parameters
-
key | The key to retrieve the value for. |
- Returns
- A reference to the value associated with the key, casted to type T.
Definition at line 89 of file dictionary.hpp.
◆ get() [2/2]
template<typename T >
const T & NeoFOAM::Dictionary::get |
( |
const std::string & |
key | ) |
const |
|
inline |
Retrieves the value associated with the given key, casting it to the specified type.
- Template Parameters
-
T | The type to cast the value to. |
- Parameters
-
key | The key to retrieve the value for. |
- Returns
- A const reference to the value associated with the key, casted to type T.
Definition at line 111 of file dictionary.hpp.
◆ getMap() [1/2]
std::unordered_map< std::string, std::any > & NeoFOAM::Dictionary::getMap |
( |
| ) |
|
Retrieves the underlying unordered map of the dictionary.
- Returns
- A reference to the underlying unordered map.
◆ getMap() [2/2]
const std::unordered_map< std::string, std::any > & NeoFOAM::Dictionary::getMap |
( |
| ) |
const |
Retrieves the underlying unordered map of the dictionary.
- Returns
- A const reference to the underlying unordered map.
◆ insert()
void NeoFOAM::Dictionary::insert |
( |
const std::string & |
key, |
|
|
const std::any & |
value |
|
) |
| |
Inserts a key-value pair into the dictionary.
- Parameters
-
key | The key to insert. |
value | The value to insert. |
◆ isDict()
bool NeoFOAM::Dictionary::isDict |
( |
const std::string & |
key | ) |
const |
Checks if the value associated with the given key is a dictionary.
- Parameters
-
- Returns
- True if the value is a dictionary, false otherwise.
◆ keys()
std::vector< std::string > NeoFOAM::Dictionary::keys |
( |
| ) |
const |
Retrieves the keys of the dictionary.
- Returns
- A vector containing the keys of the dictionary.
◆ operator[]() [1/2]
std::any & NeoFOAM::Dictionary::operator[] |
( |
const std::string & |
key | ) |
|
Accesses the value associated with the given key.
- Parameters
-
- Returns
- A reference to the value associated with the key.
◆ operator[]() [2/2]
const std::any & NeoFOAM::Dictionary::operator[] |
( |
const std::string & |
key | ) |
const |
Accesses the value associated with the given key.
- Parameters
-
- Returns
- A const reference to the value associated with the key.
◆ remove()
void NeoFOAM::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.
- Parameters
-
key | The key of the entry to be removed. |
◆ subDict() [1/2]
Dictionary & NeoFOAM::Dictionary::subDict |
( |
const std::string & |
key | ) |
|
Retrieves a sub-dictionary associated with the given key.
- Parameters
-
key | The key to retrieve the sub-dictionary for. |
- Returns
- A reference to the sub-dictionary associated with the key.
◆ subDict() [2/2]
const Dictionary & NeoFOAM::Dictionary::subDict |
( |
const std::string & |
key | ) |
const |
Retrieves a sub-dictionary associated with the given key.
- Parameters
-
key | The key to retrieve the sub-dictionary for. |
- Returns
- A reference to the sub-dictionary associated with the key.
The documentation for this class was generated from the following file: