18 #ifndef GRT_DICT_HEADER 19 #define GRT_DICT_HEADER 21 #include "GRTTypedefs.h" 22 #include "DynamicType.h" 32 typedef std::map< std::string, DynamicType > dict;
45 for (
auto const& x : rhs.
data ) {
46 this->
data[ x.first ] = x.second;
64 for (
auto const& x : rhs.
data ) {
65 this->
data[ x.first ] = x.second;
78 for (
auto const& x : rhs.
data ) {
79 this->
data[ x.first ] = x.second;
92 for (
auto const& x : rhs.
data ) {
93 if( this->
exists( x.first ) ) {
94 this->
remove( x.first );
128 bool add(
const std::string &key,
const T &value,
const bool overwrite =
true ) {
130 data[ key ].set( value );
134 it =
data.find( key );
135 if( it ==
data.end() ) {
136 data[ key ].set( value );
147 bool remove(
const std::string &key ) {
149 it =
data.find( key );
150 if( it !=
data.end() ) {
164 it =
data.find( key );
165 if( it !=
data.end() ) {
193 return (UINT)
data.size();
202 keys.reserve(
data.size() );
203 for (
auto const& x :
data ) {
204 keys.push_back( x.first );
215 T&
get(
const std::string &key ) {
217 it =
data.find( key );
218 if( it ==
data.end() ) {
219 throw "Unknown key: " + key;
221 return it->second.get< T >();
231 bool set(
const std::string &key,
const T &value ) {
233 it =
data.find( key );
234 if( it ==
data.end() ) {
237 return it->second.set( value );
246 #endif //GRT_HEADER_GUARD This class implements a flexible dictionary that supports multiple data types. Elements in the dictio...
UINT getSize() const
returns the size of the dictionary, which is the number of elements stored in the dictionary ...
Vector< std::string > getKeys() const
returns a Vector of strings containing the keys in the dictionary, the vector will be empty if the di...
bool exists(const std::string &key)
returns true if the key exists in the current dictionary
bool operator()(const std::string &key, T &value)
Access operator, assigns a reference of the value that matches the key, returning true if the value e...
bool clear()
clears all elements in the dictionary
Dict & operator+(const Dict &rhs)
Addition operator, copies the keys and values from the rhs dictionary to this dictionary, adding them to any existing values in this dictionary.
Dict & operator-(const Dict &rhs)
Subtraction operator, removes any key-value pairs from this dictionary that match the keys in the rhs...
Dict(const Dict &rhs)
Copy Constructor, copies the keys and values from the rhs dictionary to this dictionary.
~Dict()
Default Destructor.
dict data
The internal buffer used to store elements in the dictionary.
Dict & operator=(const Dict &rhs)
Equals operator, copies the keys and values from the rhs dictionary to this dictionary, clearing any elements in this dictionary first.
Dict()
Default Constructor.
bool empty() const
returns true if the dictionary is empty, false otherwise
bool add(const std::string &key, const T &value, const bool overwrite=true)
adds a new key-value pair to the dictionary, if the overwrite option is true then any matching key al...