#include <CdbAnyTypeDict.hh>
Public Member Functions | |
| CdbAnyTypeDict () | |
| The default constructor. | |
| CdbAnyTypeDict (const CdbAnyTypeDict< K > &other) | |
| The copy constructor. | |
| virtual | ~CdbAnyTypeDict () |
| The destructor. | |
| CdbAnyTypeDict< K > & | operator= (const CdbAnyTypeDict< K > &other) |
| The assignment operator. | |
| bool | empty () const |
| Check if the dictionary is empty (has no keys registered). | |
| bool | exists (const K &theKey) const |
| Check if the specified key exists in the dictionary. | |
| template<typename V> CdbStatus | insert (const K &theKey, const V &theValue) |
| Insert the new object into the dictionary. | |
| template<typename V> CdbStatus | replace (const K &theKey, const V &theValue, const bool forceCreateFlag=true) |
| Replace an object in the dictionary. | |
| template<typename V> CdbStatus | find (const K &theKey, V &theValue) const |
| Find an object in the dictionary. | |
| void | keys (std::vector< K > &theVectorOfKeys) const |
| Get a vector of keys registered in the dictionary. | |
The class can be used to store heterogenious collections of objects. The only template parameter of the class is:
K - a type of the dictionary's keys
Objects stored in the dictionary can be of any types as long as these types support the value semantics (meet the following minimal interface):
class T { public: T(); T(const T&); ~T(); T& operator=(const T&); };
All keys in the dictionary are unique. A type of each object is also remembered (in some form) by the dictionary, therefore next time, when a user will be making a query to find an object for a certain key then the stored object's type will get compared with the one expected by the users, and they should match. Otherwise a error code will get returned.
Here is a simple example how to use the dictionary:
CdbAnyTypeDict<std::string> dict;
if( !dict.exists( "PI" )) { const double pi = 3.14; if( CdbStatus::Success != dict.insert( "PI", pi )) { cerr << "failed to insert 'PI' into the dictionary
"; ... } } if( CdbStatus::Success != dict.replace( "PI", 3.14195, false )) { cerr << "failed to replice 'PI' in the dictionary with a more precise value
"; ... }
Definition at line 93 of file CdbAnyTypeDict.hh.
|
|||||||||
|
The default constructor.
Definition at line 105 of file CdbAnyTypeDict.hh. |
|
||||||||||
|
The copy constructor.
Definition at line 109 of file CdbAnyTypeDict.hh. |
|
|||||||||
|
The destructor.
Definition at line 118 of file CdbAnyTypeDict.hh. |
|
|||||||||
|
Check if the dictionary is empty (has no keys registered).
Definition at line 143 of file CdbAnyTypeDict.hh. Referenced by main(). |
|
||||||||||
|
Check if the specified key exists in the dictionary.
Definition at line 150 of file CdbAnyTypeDict.hh. Referenced by CdbAnyTypeDict< std::string >::insert(), and main(). |
|
||||||||||||||||||||
|
Find an object in the dictionary. The method will try to find an existing object in the dictionary for the specified key. If the key is not found then the CdbStatus::NotFound value will be returned. If the key is already known to the dictionary then the expected object's type should match the one stored before. Otherwise the CdbStatus::ConflictOfParameters status value will be returned. Definition at line 213 of file CdbAnyTypeDict.hh. Referenced by main(). |
|
||||||||||||||||||||
|
Insert the new object into the dictionary. The method is meant to make a copy of the input object and register it in the dictionary with the specified key. A type of the input object will also be remembered, so that next time when a user will be making a query for that key then the stored type will get compared with the one expected by the user. The method will return CdbStatus::Error if the specified key is already known to the dictionary. Definition at line 166 of file CdbAnyTypeDict.hh. Referenced by main(). |
|
||||||||||
|
Get a vector of keys registered in the dictionary. The method would initialize and fill the specified vector with known keys. Note that the keys will not be sorted. Definition at line 233 of file CdbAnyTypeDict.hh. |
|
||||||||||
|
The assignment operator.
Definition at line 127 of file CdbAnyTypeDict.hh. |
|
||||||||||||||||||||||||
|
Replace an object in the dictionary. The method will replace an existing object in the dictionary for the specified key. Depending on a value of the optional "forceCreateFlag" the key may or may not be allowed to be missing in the dictionary prior to calling the method. If the keys is not known and the flag is set to "false" then the CdbStatus::NotFound value will be returned. Otherwise a new entry will be created. If the key is already known to the dictionary then the new object's type should match the one stored before. Otherwise the CdbStatus::ConflictOfParameters status value will be returned. Definition at line 188 of file CdbAnyTypeDict.hh. Referenced by main(). |
1.3-rc3