Image Component Library (ICL)
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
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

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

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

◆ DataMap

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

internal definition

◆ SmartDataMapPtr

internal definition

◆ SmartMutexPtr

internal definition

Constructor & Destructor Documentation

◆ MultiTypeMap()

icl::utils::MultiTypeMap::MultiTypeMap ( )

Default constructor (create a new MultiTypeMap object)

◆ ~MultiTypeMap()

icl::utils::MultiTypeMap::~MultiTypeMap ( )

Destructor (deletes all remaining data)

Member Function Documentation

◆ allocArray()

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

◆ allocValue()

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

◆ check_type_internal()

bool icl::utils::MultiTypeMap::check_type_internal ( const std::string &  id,
const std::string &  typestr 
) const
protected

◆ checkType()

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

◆ clear()

void icl::utils::MultiTypeMap::clear ( )

◆ contains()

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

◆ get_type_name()

template<class T >
static const std::string& icl::utils::MultiTypeMap::get_type_name ( )
inlinestatic

internally used wrapper function for RTTI

◆ getArray()

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

◆ getEntryList()

std::vector<Entry> icl::utils::MultiTypeMap::getEntryList ( ) const

returns a list of all entries

◆ getType()

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

◆ getValue() [1/2]

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

◆ getValue() [2/2]

template<class T >
const T& icl::utils::MultiTypeMap::getValue ( const std::string &  id,
bool  checkType = true 
) const
inline

◆ isArray()

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

◆ listContents()

void icl::utils::MultiTypeMap::listContents ( ) const

shows a list of currently contained data

◆ lock()

void icl::utils::MultiTypeMap::lock ( ) const
inline

◆ release()

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

◆ unlock()

void icl::utils::MultiTypeMap::unlock ( ) const
inline

internally unlocks the data store

Member Data Documentation

◆ m_oDataMapPtr

SmartDataMapPtr icl::utils::MultiTypeMap::m_oDataMapPtr
mutableprotected

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

◆ m_oMutexPtr

SmartMutexPtr icl::utils::MultiTypeMap::m_oMutexPtr
mutableprotected

mutex to handle syncronous calls


The documentation for this class was generated from the following file: