cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
cmnNamedMap< _elementType > Class Template Reference

#include <cmnNamedMap.h>

Public Types

typedef std::map< std::string,
_elementType * > 
MapType
 
typedef MapType::iterator iterator
 
typedef MapType::const_iterator const_iterator
 
typedef MapType::reverse_iterator reverse_iterator
 
typedef
MapType::const_reverse_iterator 
const_reverse_iterator
 
typedef MapType::size_type size_type
 
typedef _elementType element_type
 
typedef void(_elementType::* VoidMethodPointer )(void)
 

Public Member Functions

 cmnNamedMap (bool takesOwnership=false)
 
 cmnNamedMap (const char *mapName, bool takesOwnership=false)
 
 cmnNamedMap (const std::string &mapName, bool takesOwnership=false)
 
 cmnNamedMap (const std::string &mapName, const cmnGenericObject &owner, bool takesOwnership=false)
 
 ~cmnNamedMap ()
 
void SetOwner (const cmnGenericObject &owner)
 
bool AddItem (const std::string &name, _elementType *item, cmnLogLevel lod=CMN_LOG_LEVEL_RUN_ERROR)
 
_elementType * GetItem (const std::string &name, cmnLogLevel lod=CMN_LOG_LEVEL_RUN_DEBUG) const
 
bool FindItem (const std::string &itemName) const
 
bool RemoveItem (const std::string &name, cmnLogLevel lod=CMN_LOG_LEVEL_RUN_ERROR)
 
void ForEachVoid (VoidMethodPointer method)
 
void ToStream (std::ostream &outputStream) const
 
void DeleteAll (void)
 
size_type size (void) const
 
bool empty (void) const
 
void clear (void)
 
iterator begin (void)
 
const_iterator begin (void) const
 
iterator end (void)
 
const_iterator end (void) const
 
void GetNames (std::vector< std::string > &placeHolder) const
 
std::vector< std::string > GetNames (void) const
 
const MapTypeGetMap (void) const
 
MapTypeGetMap (void)
 

Protected Member Functions

const cmnClassServicesBaseServices (void) const
 
cmnLogger::StreamBufTypeGetLogMultiplexer (void) const
 

Protected Attributes

MapType Map
 
bool TakesOwnership
 
std::string MapName
 
const cmnClassServicesBaseOwnerServices
 

Detailed Description

template<class _elementType>
class cmnNamedMap< _elementType >

cmnNamedMap provides a map (lookup table), where the key is a string and the value (item) is specified by the template parameter. The map actually contains a pointer to the value. In cisstMultiTask, this class is used to maintain the lists of interfaces per task/device, as well as the lists of commands per interface.

The cmnNamedMap class is a small "wrapper" around std::map that was created to factorize some code that would otherwise be duplicated.

Member Typedef Documentation

template<class _elementType>
typedef MapType::const_iterator cmnNamedMap< _elementType >::const_iterator
template<class _elementType>
typedef MapType::const_reverse_iterator cmnNamedMap< _elementType >::const_reverse_iterator
template<class _elementType>
typedef _elementType cmnNamedMap< _elementType >::element_type
template<class _elementType>
typedef MapType::iterator cmnNamedMap< _elementType >::iterator
template<class _elementType>
typedef std::map<std::string, _elementType *> cmnNamedMap< _elementType >::MapType

Type of the actual map

template<class _elementType>
typedef MapType::reverse_iterator cmnNamedMap< _elementType >::reverse_iterator
template<class _elementType>
typedef MapType::size_type cmnNamedMap< _elementType >::size_type
template<class _elementType>
typedef void(_elementType::* cmnNamedMap< _elementType >::VoidMethodPointer)(void)

Type of void method in class _elementType

Constructor & Destructor Documentation

template<class _elementType>
cmnNamedMap< _elementType >::cmnNamedMap ( bool  takesOwnership = false)
inline

Default constructor, initialize the internal map and set the map name to "undefined"

template<class _elementType>
cmnNamedMap< _elementType >::cmnNamedMap ( const char *  mapName,
bool  takesOwnership = false 
)
inline

Constructor with a map name. The map name is useful for all human readable log messages as well as string streaming (e.g. std::cout)

template<class _elementType>
cmnNamedMap< _elementType >::cmnNamedMap ( const std::string &  mapName,
bool  takesOwnership = false 
)
inline
template<class _elementType>
cmnNamedMap< _elementType >::cmnNamedMap ( const std::string &  mapName,
const cmnGenericObject owner,
bool  takesOwnership = false 
)
inline

Constructor with a map name and a pointer a cmnGenericObject (in most cases, use "*this"). The map name is useful for all human readable log messages as well as string streaming (e.g. std::cout). The cmnGenericObject level of detail will be used to filter the messages.

template<class _elementType>
cmnNamedMap< _elementType >::~cmnNamedMap ( )
inline

Destructor. Relies on std::map destructor.

Member Function Documentation

template<class _elementType>
bool cmnNamedMap< _elementType >::AddItem ( const std::string &  name,
_elementType *  item,
cmnLogLevel  lod = CMN_LOG_LEVEL_RUN_ERROR 
)

Add an item to the internal map. The log level of details is used to determine the lod of a message if the item can not be added.

template<class _elementType>
iterator cmnNamedMap< _elementType >::begin ( void  )
inline
template<class _elementType>
const_iterator cmnNamedMap< _elementType >::begin ( void  ) const
inline
template<class _elementType>
void cmnNamedMap< _elementType >::clear ( void  )
inline
template<class _elementType >
void cmnNamedMap< _elementType >::DeleteAll ( void  )

Delete all content while preserving keys, i.e. the map contains pairs of names and null pointers.

template<class _elementType>
bool cmnNamedMap< _elementType >::empty ( void  ) const
inline
template<class _elementType>
iterator cmnNamedMap< _elementType >::end ( void  )
inline
template<class _elementType>
const_iterator cmnNamedMap< _elementType >::end ( void  ) const
inline
template<class _elementType >
bool cmnNamedMap< _elementType >::FindItem ( const std::string &  itemName) const

Find an item by name

template<class _elementType >
void cmnNamedMap< _elementType >::ForEachVoid ( VoidMethodPointer  method)

Execute a method on all objects contained in the map

template<class _elementType >
_elementType * cmnNamedMap< _elementType >::GetItem ( const std::string &  name,
cmnLogLevel  lod = CMN_LOG_LEVEL_RUN_DEBUG 
) const

Get an item by name

template<class _elementType>
cmnLogger::StreamBufType* cmnNamedMap< _elementType >::GetLogMultiplexer ( void  ) const
inlineprotected
template<class _elementType>
const MapType& cmnNamedMap< _elementType >::GetMap ( void  ) const
inline

Reference on the internal map

template<class _elementType>
MapType& cmnNamedMap< _elementType >::GetMap ( void  )
inline
template<class _elementType >
void cmnNamedMap< _elementType >::GetNames ( std::vector< std::string > &  placeHolder) const

List of names used, i.e. list of keys in the map

template<class _elementType >
std::vector< std::string > cmnNamedMap< _elementType >::GetNames ( void  ) const
template<class _elementType >
bool cmnNamedMap< _elementType >::RemoveItem ( const std::string &  name,
cmnLogLevel  lod = CMN_LOG_LEVEL_RUN_ERROR 
)

Remove an item from the internal map. The log level of details is used to determine the lod of a message if the item can not be removed.

template<class _elementType>
const cmnClassServicesBase* cmnNamedMap< _elementType >::Services ( void  ) const
inlineprotected

Method use to emulate the cmnGenericObject interface used by CMN_LOG_CLASS macros.

template<class _elementType>
void cmnNamedMap< _elementType >::SetOwner ( const cmnGenericObject owner)
inline

Set the map owner

template<class _elementType>
size_type cmnNamedMap< _elementType >::size ( void  ) const
inline

STL compatible size

template<class _elementType >
void cmnNamedMap< _elementType >::ToStream ( std::ostream &  outputStream) const

Print the content of the map as well as its name

Member Data Documentation

template<class _elementType>
MapType cmnNamedMap< _elementType >::Map
protected

Map data member, uses an std::map

template<class _elementType>
std::string cmnNamedMap< _elementType >::MapName
protected

Name of the map, mostly for logging purposes.

template<class _elementType>
const cmnClassServicesBase* cmnNamedMap< _elementType >::OwnerServices
protected

Pointer on existing services. This allows to use the class name and level of detail of another class, e.g. the class that owns this map. To set the "Owner", use the method SetOwner after the cmnNamedMap is constructed.

template<class _elementType>
bool cmnNamedMap< _elementType >::TakesOwnership
protected

Flag set to determine if the map "takes ownership" of data. If the map takes ownership it will perform the required delete on its data when necessary. The default is false, i.e. the map destructor will not attempt to delete its objects.


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