GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Dict Class Reference

This class implements a flexible dictionary that supports multiple data types. Elements in the dictionary consist of key-value pairs, where keys are std::strings and values can be any data type, as they are stored as a GRT::DynamicType. More...

#include <Dict.h>

Public Member Functions

 Dict ()
 Default Constructor.
 
 Dict (const Dict &rhs)
 Copy Constructor, copies the keys and values from the rhs dictionary to this dictionary. More...
 
 ~Dict ()
 Default Destructor.
 
Dictoperator= (const Dict &rhs)
 Equals operator, copies the keys and values from the rhs dictionary to this dictionary, clearing any elements in this dictionary first. More...
 
Dictoperator+ (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. More...
 
Dictoperator- (const Dict &rhs)
 Subtraction operator, removes any key-value pairs from this dictionary that match the keys in the rhs dictionary to this dictionary. More...
 
template<typename T >
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 exists, false otherwise. More...
 
template<typename T >
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 already in the dictionary will be overwritten, if the overwrite option is false then the function will return false indicating it could not add the new pair as a dictionary element already exists for this key. More...
 
bool remove (const std::string &key)
 removes a new key-value pair from the dictionary More...
 
bool exists (const std::string &key)
 returns true if the key exists in the current dictionary More...
 
bool clear ()
 clears all elements in the dictionary More...
 
bool empty () const
 returns true if the dictionary is empty, false otherwise More...
 
UINT getSize () const
 returns the size of the dictionary, which is the number of elements stored in the dictionary More...
 
Vector< std::string > getKeys () const
 returns a Vector of strings containing the keys in the dictionary, the vector will be empty if the dictionary is empty More...
 
template<typename T >
T & get (const std::string &key)
 returns a reference to the value that matches the key from the dictionary, the function will throw an error if the key does not exist More...
 
template<typename T >
bool set (const std::string &key, const T &value)
 sets the value for the key in the dictionary, if the key does not exist then the function will return false More...
 

Protected Attributes

dict data
 The internal buffer used to store elements in the dictionary.
 

Detailed Description

This class implements a flexible dictionary that supports multiple data types. Elements in the dictionary consist of key-value pairs, where keys are std::strings and values can be any data type, as they are stored as a GRT::DynamicType.

Definition at line 31 of file Dict.h.

Constructor & Destructor Documentation

Dict::Dict ( const Dict rhs)
inline

Copy Constructor, copies the keys and values from the rhs dictionary to this dictionary.

Parameters
rhsthe right-hand-side reference dictionary containing the keys you want to copy to this dictionary

Definition at line 44 of file Dict.h.

Member Function Documentation

template<typename T >
bool Dict::add ( const std::string &  key,
const T &  value,
const bool  overwrite = true 
)
inline

adds a new key-value pair to the dictionary, if the overwrite option is true then any matching key already in the dictionary will be overwritten, if the overwrite option is false then the function will return false indicating it could not add the new pair as a dictionary element already exists for this key.

Parameters
keythe key for the value you want to add
valuethe value that will be added to the dictionary and associated with the key
overwriteif true, then key-value pairs will always be added even if a dictionary element already exists with the same key, if false then the key must be unique
Returns
returns true if the key-value pair was added, false otherwise

Definition at line 128 of file Dict.h.

bool Dict::clear ( )
inline

clears all elements in the dictionary

Returns
returns true if the dictionary was cleared, false otherwise

Definition at line 175 of file Dict.h.

bool Dict::empty ( ) const
inline

returns true if the dictionary is empty, false otherwise

Returns
returns true if the dictionary is empty, false otherwise

Definition at line 184 of file Dict.h.

bool Dict::exists ( const std::string &  key)
inline

returns true if the key exists in the current dictionary

Parameters
keythe key you want to search for in the dictionary
Returns
returns true if the key exists in the current dictionary, false otherwise

Definition at line 162 of file Dict.h.

template<typename T >
T& Dict::get ( const std::string &  key)
inline

returns a reference to the value that matches the key from the dictionary, the function will throw an error if the key does not exist

Parameters
keythe key you want to search for in the dictionary
Returns
returns a reference to the value for the corresponding key in the dictionary

Definition at line 215 of file Dict.h.

Vector< std::string > Dict::getKeys ( ) const
inline

returns a Vector of strings containing the keys in the dictionary, the vector will be empty if the dictionary is empty

Returns
returns a Vector of the keys in the dictionary

Definition at line 200 of file Dict.h.

UINT Dict::getSize ( ) const
inline

returns the size of the dictionary, which is the number of elements stored in the dictionary

Returns
returns the size of the dictionary, which is the number of elements stored in the dictionary

Definition at line 192 of file Dict.h.

template<typename T >
bool Dict::operator() ( const std::string &  key,
T &  value 
)
inline

Access operator, assigns a reference of the value that matches the key, returning true if the value exists, false otherwise.

Note
the assignment is via a reference, therefore changing the value outside of the function will also change the value in the dictionary
Parameters
keythe key for the value you want to access
valuea reference to a data instance that will store the value associated with the key
Returns
returns true if the key and type match, false otherwise

Definition at line 109 of file Dict.h.

Dict& Dict::operator+ ( const Dict rhs)
inline

Addition operator, copies the keys and values from the rhs dictionary to this dictionary, adding them to any existing values in this dictionary.

Parameters
rhsthe right-hand-side reference dictionary containing the keys you want to add to this dictionary
Returns
returns a reference to this dictionary

Definition at line 76 of file Dict.h.

Dict& Dict::operator- ( const Dict rhs)
inline

Subtraction operator, removes any key-value pairs from this dictionary that match the keys in the rhs dictionary to this dictionary.

Parameters
rhsthe right-hand-side reference dictionary containing the keys you want to remove from this dictionary
Returns
returns a reference to this dictionary

Definition at line 90 of file Dict.h.

Dict& Dict::operator= ( const Dict rhs)
inline

Equals operator, copies the keys and values from the rhs dictionary to this dictionary, clearing any elements in this dictionary first.

Parameters
rhsthe right-hand-side reference dictionary containing the keys you want to copy to this dictionary
Returns
returns a reference to this dictionary

Definition at line 61 of file Dict.h.

bool Dict::remove ( const std::string &  key)
inline

removes a new key-value pair from the dictionary

Parameters
keythe key for the dictionary element you want to remove
Returns
returns true if the key was found and the dictionary element was removed, false otherwise

Definition at line 147 of file Dict.h.

template<typename T >
bool Dict::set ( const std::string &  key,
const T &  value 
)
inline

sets the value for the key in the dictionary, if the key does not exist then the function will return false

Parameters
keythe key you want to search for in the dictionary
valuethe new value for the corresponding key element
Returns
returns true if the dictionary element was updated, false otherwise

Definition at line 231 of file Dict.h.


The documentation for this class was generated from the following file: