Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
icl::utils::MultiTypeMap Class Reference

Abstract and associative Data Container for Data of different types. More...

#include <MultiTypeMap.h>

Inheritance diagram for icl::utils::MultiTypeMap:
icl::qt::DataStore

List of all members.

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< EntrygetEntryList () 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< DataMapSmartDataMapPtr
 internal definition
typedef SmartPtr< MutexSmartMutexPtr
 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

Detailed Description

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!.


Member Typedef Documentation

typedef std::map<std::string,DataArray> icl::utils::MultiTypeMap::DataMap [protected]

internal definition

internal definition

internal definition


Constructor & Destructor Documentation

Default constructor (create a new MultiTypeMap object)

Destructor (deletes all remaining data)


Member Function Documentation

template<class T >
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.

Parameters:
idname of this data block
ncount of elements (min 1)
Returns:
data pointer that was just created
template<class T >
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.

Parameters:
idname of this data block
valinitial value for this data block
Returns:
reference the the data element, that was just created
bool icl::utils::MultiTypeMap::check_type_internal ( const std::string &  id,
const std::string &  typestr 
) const [protected]
template<class T >
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

Parameters:
idname of the entry
Returns:
whether the entry associated with id has type T
bool icl::utils::MultiTypeMap::contains ( const std::string &  id) const

returns whether a given value is already set

Parameters:
idname of the parameter
Returns:
whether a parameter with that id is contained
template<class T >
static const std::string& icl::utils::MultiTypeMap::get_type_name ( ) [inline, static]

internally used wrapper function for RTTI

template<class T >
T* icl::utils::MultiTypeMap::getArray ( const std::string &  id,
int *  lenDst = 0 
) [inline]

get a T* that is associated with the given id

Parameters:
idname of the entry to get
lenDstpointer to store the array len (in T's) in if not NULL
Returns:
data pointer that is associated with id or NULL if the id is invalid

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

Parameters:
idname of the entry
Returns:
RTTI string type identifier
template<class T >
T& icl::utils::MultiTypeMap::getValue ( const std::string &  id,
bool  checkType = true 
) [inline]

get a T reference that is associated with the given id

Parameters:
idname of the entry to get
checkType
Returns:
reference to the value that is associated with the given id
template<class T >
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

Parameters:
idname of the entry to check
Returns:
whether the entry for id is an array

shows a list of currently contained data

void icl::utils::MultiTypeMap::lock ( ) const [inline]
template<class T >
void icl::utils::MultiTypeMap::release ( const std::string &  id) [inline]

release the data element that is associated with the given id

Parameters:
idname of the entry to release
void icl::utils::MultiTypeMap::unlock ( ) const [inline]

internally unlocks the data store


Member Data Documentation

Smart-Pointer to the underlying data (allows shallow copies)

mutex to handle syncronous calls


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines