Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbAnyTypeDict< K > Class Template Reference

A dictionary class for objects of any type. More...

#include <CdbAnyTypeDict.hh>

List of all members.

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.


Detailed Description

template<class K>
class CdbAnyTypeDict< K >

A dictionary class for objects of any type.

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.


Constructor & Destructor Documentation

template<class K>
CdbAnyTypeDict< K >::CdbAnyTypeDict   [inline]
 

The default constructor.

Definition at line 105 of file CdbAnyTypeDict.hh.

template<class K>
CdbAnyTypeDict< K >::CdbAnyTypeDict const CdbAnyTypeDict< K > &    other [inline]
 

The copy constructor.

Definition at line 109 of file CdbAnyTypeDict.hh.

template<class K>
virtual CdbAnyTypeDict< K >::~CdbAnyTypeDict   [inline, virtual]
 

The destructor.

Definition at line 118 of file CdbAnyTypeDict.hh.


Member Function Documentation

template<class K>
bool CdbAnyTypeDict< K >::empty   const [inline]
 

Check if the dictionary is empty (has no keys registered).

Definition at line 143 of file CdbAnyTypeDict.hh.

Referenced by main().

template<class K>
bool CdbAnyTypeDict< K >::exists const K &    theKey const [inline]
 

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().

template<class K>
template<typename V>
CdbStatus CdbAnyTypeDict< K >::find const K &    theKey,
V &    theValue
const [inline]
 

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().

template<class K>
template<typename V>
CdbStatus CdbAnyTypeDict< K >::insert const K &    theKey,
const V &    theValue
[inline]
 

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().

template<class K>
void CdbAnyTypeDict< K >::keys std::vector< K > &    theVectorOfKeys const [inline]
 

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.

template<class K>
CdbAnyTypeDict<K>& CdbAnyTypeDict< K >::operator= const CdbAnyTypeDict< K > &    other [inline]
 

The assignment operator.

Definition at line 127 of file CdbAnyTypeDict.hh.

template<class K>
template<typename V>
CdbStatus CdbAnyTypeDict< K >::replace const K &    theKey,
const V &    theValue,
const bool    forceCreateFlag = true
[inline]
 

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().


The documentation for this class was generated from the following file:
Generated on Mon Dec 5 18:22:17 2005 for CDB by doxygen1.3-rc3