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) More... | |
~MultiTypeMap () | |
Destructor (deletes all remaining data) More... | |
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. More... | |
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. More... | |
template<class T > | |
void | release (const std::string &id) |
release the data element that is associated with the given id More... | |
template<class T > | |
T * | getArray (const std::string &id, int *lenDst=0) |
get a T* that is associated with the given id More... | |
template<class T > | |
T & | getValue (const std::string &id, bool checkType=true) |
get a T reference that is associated with the given id More... | |
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 More... | |
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 More... | |
bool | isArray (const std::string &id) const |
returns whether an entry is an array or a value More... | |
bool | contains (const std::string &id) const |
returns whether a given value is already set More... | |
void | lock () const |
void | unlock () const |
internally unlocks the data store More... | |
void | listContents () const |
shows a list of currently contained data More... | |
void | clear () |
std::vector< Entry > | getEntryList () const |
returns a list of all entries More... | |
Static Public Member Functions | |
template<class T > | |
static const std::string & | get_type_name () |
internally used wrapper function for RTTI More... | |
Protected Types | |
typedef std::map< std::string, DataArray > | DataMap |
internal definition More... | |
typedef SmartPtr< DataMap > | SmartDataMapPtr |
internal definition More... | |
typedef SmartPtr< Mutex > | SmartMutexPtr |
internal definition More... | |
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) More... | |
SmartMutexPtr | m_oMutexPtr |
mutex to handle syncronous calls More... | |
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!.
|
protected |
internal definition
|
protected |
internal definition
|
protected |
internal definition
icl::utils::MultiTypeMap::MultiTypeMap | ( | ) |
Default constructor (create a new MultiTypeMap object)
icl::utils::MultiTypeMap::~MultiTypeMap | ( | ) |
Destructor (deletes all remaining data)
|
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) |
|
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 |
|
protected |
|
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 |
|
inlinestatic |
internally used wrapper function for RTTI
|
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 |
|
inline |
get a T reference that is associated with the given id
id | name of the entry to get |
checkType |
|
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
|
inline |
|
inline |
release the data element that is associated with the given id
id | name of the entry to release |
|
inline |
internally unlocks the data store
|
mutableprotected |
Smart-Pointer to the underlying data (allows shallow copies)
|
mutableprotected |
mutex to handle syncronous calls