Image Component Library (ICL)
|
Abstract and associative Data Container for Data of different types. More...
#include <MultiTypeMap.h>
Classes | |
struct | DataArray |
internally used data handling structure More... | |
struct | Entry |
entry struct used in getEntryList function More... | |
Public Member Functions | |
MultiTypeMap () | |
Default constructor (create a new MultiTypeMap object) | |
~MultiTypeMap () | |
Destructor (deletes all remaining data) | |
template<class T > | |
T * | allocArray (const std::string &id, unsigned int n) |
Allocates a new memory block (new T[n]) for the given id string. | |
template<class T > | |
T & | allocValue (const std::string &id, const T &val=T()) |
Allocates a new memory elements (new T(val)) for the given id string. | |
template<class T > | |
void | release (const std::string &id) |
release the data element that is associated with the given id | |
template<class T > | |
T * | getArray (const std::string &id, int *lenDst=0) |
get a T* that is associated with the given id | |
template<class T > | |
T & | getValue (const std::string &id, bool checkType=true) |
get a T reference that is associated with the given id | |
template<class T > | |
const T & | getValue (const std::string &id, bool checkType=true) const |
const std::string & | getType (const std::string &id) const |
returns the RTTI string type identifier, for the entry associated with id | |
template<class T > | |
bool | checkType (const std::string &id) const |
checks if the type-id associated with the template parameter T is compatible to the entry for id | |
bool | isArray (const std::string &id) const |
returns whether an entry is an array or a value | |
bool | contains (const std::string &id) const |
returns whether a given value is already set | |
void | lock () const |
void | unlock () const |
internally unlocks the data store | |
void | listContents () const |
shows a list of currently contained data | |
void | clear () |
std::vector< Entry > | getEntryList () const |
returns a list of all entries | |
Static Public Member Functions | |
template<class T > | |
static const std::string & | get_type_name () |
internally used wrapper function for RTTI | |
Protected Types | |
typedef std::map< std::string, DataArray > | DataMap |
internal definition | |
typedef SmartPtr< DataMap > | SmartDataMapPtr |
internal definition | |
typedef SmartPtr< Mutex > | SmartMutexPtr |
internal definition | |
Protected Member Functions | |
bool | check_type_internal (const std::string &id, const std::string &typestr) const |
Protected Attributes | |
SmartDataMapPtr | m_oDataMapPtr |
Smart-Pointer to the underlying data (allows shallow copies) | |
SmartMutexPtr | m_oMutexPtr |
mutex to handle syncronous calls |
Abstract and associative Data Container for Data of different types.
The MultiTypeMap class can be used to create an associative container for different types. It provides an interface for a type-save handling of single elements as well as arrays of data.
Single elements are created internally as a copy (copy constructor) of a given value (by default the empty constructor for a specific type is used to create a default initializing instance). Arrays elements and value elements may not be mixed up as array elements must be created and released in a different way (using new[] and delete[] instead of new() and delete).
In addition the class provides some utility functions to get information about all contained data elements.
The type-safety is facilitated using the C++ RTTI (Run-Time Type Identification) which is not very fast. Also the access functions getValue() and getArray() are not very fast, because the underlying memory is organized in a std::map, which must be searched. Hence, the more elements a MultiTypeMap object contains, the slower a single data element will be accessible (it's just a map internally :-) ).
To accelerate data access just store a reference to the data element or a pointer anywhere and work with that pointer!.
typedef std::map<std::string,DataArray> icl::utils::MultiTypeMap::DataMap [protected] |
internal definition
typedef SmartPtr<DataMap> icl::utils::MultiTypeMap::SmartDataMapPtr [protected] |
internal definition
typedef SmartPtr<Mutex> icl::utils::MultiTypeMap::SmartMutexPtr [protected] |
internal definition
Default constructor (create a new MultiTypeMap object)
Destructor (deletes all remaining data)
T* icl::utils::MultiTypeMap::allocArray | ( | const std::string & | id, |
unsigned int | n | ||
) | [inline] |
Allocates a new memory block (new T[n]) for the given id string.
id | name of this data block |
n | count of elements (min 1) |
T& icl::utils::MultiTypeMap::allocValue | ( | const std::string & | id, |
const T & | val = T() |
||
) | [inline] |
Allocates a new memory elements (new T(val)) for the given id string.
id | name of this data block |
val | initial value for this data block |
bool icl::utils::MultiTypeMap::check_type_internal | ( | const std::string & | id, |
const std::string & | typestr | ||
) | const [protected] |
bool icl::utils::MultiTypeMap::checkType | ( | const std::string & | id | ) | const [inline] |
checks if the type-id associated with the template parameter T is compatible to the entry for id
id | name of the entry |
void icl::utils::MultiTypeMap::clear | ( | ) |
bool icl::utils::MultiTypeMap::contains | ( | const std::string & | id | ) | const |
returns whether a given value is already set
id | name of the parameter |
static const std::string& icl::utils::MultiTypeMap::get_type_name | ( | ) | [inline, static] |
internally used wrapper function for RTTI
T* icl::utils::MultiTypeMap::getArray | ( | const std::string & | id, |
int * | lenDst = 0 |
||
) | [inline] |
get a T* that is associated with the given id
id | name of the entry to get |
lenDst | pointer to store the array len (in T's) in if not NULL |
std::vector<Entry> icl::utils::MultiTypeMap::getEntryList | ( | ) | const |
returns a list of all entries
const std::string& icl::utils::MultiTypeMap::getType | ( | const std::string & | id | ) | const |
returns the RTTI string type identifier, for the entry associated with id
id | name of the entry |
T& icl::utils::MultiTypeMap::getValue | ( | const std::string & | id, |
bool | checkType = true |
||
) | [inline] |
get a T reference that is associated with the given id
id | name of the entry to get |
checkType |
const T& icl::utils::MultiTypeMap::getValue | ( | const std::string & | id, |
bool | checkType = true |
||
) | const [inline] |
bool icl::utils::MultiTypeMap::isArray | ( | const std::string & | id | ) | const |
returns whether an entry is an array or a value
id | name of the entry to check |
void icl::utils::MultiTypeMap::listContents | ( | ) | const |
shows a list of currently contained data
void icl::utils::MultiTypeMap::lock | ( | ) | const [inline] |
void icl::utils::MultiTypeMap::release | ( | const std::string & | id | ) | [inline] |
release the data element that is associated with the given id
id | name of the entry to release |
void icl::utils::MultiTypeMap::unlock | ( | ) | const [inline] |
internally unlocks the data store
SmartDataMapPtr icl::utils::MultiTypeMap::m_oDataMapPtr [mutable, protected] |
Smart-Pointer to the underlying data (allows shallow copies)
SmartMutexPtr icl::utils::MultiTypeMap::m_oMutexPtr [mutable, protected] |
mutex to handle syncronous calls