cisst-saw
Loading...
Searching...
No Matches
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 GetNames (std::vector< std::string > &placeHolder) const
std::vector< std::string > GetNames (void) const
void ForEachVoid (VoidMethodPointer method)
const MapTypeGetMap (void) const
MapTypeGetMap (void)
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

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

◆ const_iterator

template<class _elementType>
typedef MapType::const_iterator cmnNamedMap< _elementType >::const_iterator

◆ const_reverse_iterator

template<class _elementType>
typedef MapType::const_reverse_iterator cmnNamedMap< _elementType >::const_reverse_iterator

◆ element_type

template<class _elementType>
typedef _elementType cmnNamedMap< _elementType >::element_type

◆ iterator

template<class _elementType>
typedef MapType::iterator cmnNamedMap< _elementType >::iterator

◆ MapType

template<class _elementType>
typedef std::map<std::string, _elementType *> cmnNamedMap< _elementType >::MapType

Type of the actual map

◆ reverse_iterator

template<class _elementType>
typedef MapType::reverse_iterator cmnNamedMap< _elementType >::reverse_iterator

◆ size_type

template<class _elementType>
typedef MapType::size_type cmnNamedMap< _elementType >::size_type

◆ VoidMethodPointer

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

Type of void method in class _elementType

Constructor & Destructor Documentation

◆ cmnNamedMap() [1/4]

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

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

◆ cmnNamedMap() [2/4]

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)

◆ cmnNamedMap() [3/4]

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

◆ cmnNamedMap() [4/4]

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.

◆ ~cmnNamedMap()

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

Destructor. Relies on std::map destructor.

Member Function Documentation

◆ AddItem()

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.

◆ begin() [1/2]

template<class _elementType>
iterator cmnNamedMap< _elementType >::begin ( void )
inline

◆ begin() [2/2]

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

◆ clear()

template<class _elementType>
void cmnNamedMap< _elementType >::clear ( void )
inline

◆ DeleteAll()

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.

◆ empty()

template<class _elementType>
bool cmnNamedMap< _elementType >::empty ( void ) const
inline

◆ end() [1/2]

template<class _elementType>
iterator cmnNamedMap< _elementType >::end ( void )
inline

◆ end() [2/2]

template<class _elementType>
const_iterator cmnNamedMap< _elementType >::end ( void ) const
inline

◆ FindItem()

template<class _elementType>
bool cmnNamedMap< _elementType >::FindItem ( const std::string & itemName) const

Find an item by name

◆ ForEachVoid()

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

Execute a method on all objects contained in the map

◆ GetItem()

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

Get an item by name

◆ GetLogMultiplexer()

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

◆ GetMap() [1/2]

template<class _elementType>
MapType & cmnNamedMap< _elementType >::GetMap ( void )
inline

◆ GetMap() [2/2]

template<class _elementType>
const MapType & cmnNamedMap< _elementType >::GetMap ( void ) const
inline

Reference on the internal map

◆ GetNames() [1/2]

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

◆ GetNames() [2/2]

template<class _elementType>
std::vector< std::string > cmnNamedMap< _elementType >::GetNames ( void ) const

◆ RemoveItem()

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.

◆ Services()

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

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

◆ SetOwner()

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

Set the map owner

◆ size()

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

STL compatible size

◆ ToStream()

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

◆ Map

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

Map data member, uses an std::map

◆ MapName

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

Name of the map, mostly for logging purposes.

◆ OwnerServices

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.

◆ TakesOwnership

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: