DART  6.6.2
dart::common::NameManager< T > Class Template Reference

class NameManager More...

#include <NameManager.hpp>

Public Member Functions

 NameManager (const std::string &_managerName="default", const std::string &_defaultName="default")
 Constructor. More...
 
virtual ~NameManager ()=default
 Destructor. More...
 
bool setPattern (const std::string &_newPattern)
 Set a new pattern for name generation. More...
 
std::string issueNewName (const std::string &_name) const
 Issue new unique combined name of given base name and number suffix. More...
 
std::string issueNewNameAndAdd (const std::string &_name, const T &_obj)
 Call issueNewName() and add the result to the map. More...
 
bool addName (const std::string &_name, const T &_obj)
 Add an object to the map. More...
 
bool removeName (const std::string &_name)
 Remove an object from the Manager based on its name. More...
 
bool removeObject (const T &_obj)
 Remove an object from the Manager based on reverse lookup. More...
 
void removeEntries (const std::string &_name, const T &_obj)
 Remove _name using the forward lookup and _obj using the reverse lookup. More...
 
void clear ()
 Clear all the objects. More...
 
bool hasName (const std::string &_name) const
 Return true if the name is contained. More...
 
bool hasObject (const T &_obj) const
 Return true if the object is contained. More...
 
std::size_t getCount () const
 Get the number of the objects currently stored by the NameManager. More...
 
getObject (const std::string &_name) const
 Get object by given name. More...
 
std::string getName (const T &_obj) const
 Use a reverse lookup to get the name that the manager has _obj listed under. More...
 
std::string changeObjectName (const T &_obj, const std::string &_newName)
 Change the name of a currently held object. More...
 
void setDefaultName (const std::string &_defaultName)
 Set the name that will be provided to objects passed in with an empty string for a name. More...
 
const std::string & getDefaultName () const
 Get the name that will be provided to objects passed in with an empty string for a name. More...
 
void setManagerName (const std::string &_managerName)
 Set the name of this NameManager so that it can be printed in error reports. More...
 
const std::string & getManagerName () const
 Get the name of this NameManager. More...
 

Protected Attributes

std::string mManagerName
 Name of this NameManager. This is used to report errors. More...
 
std::map< std::string, T > mMap
 Map of objects that have been added to the NameManager. More...
 
std::map< T, std::string > mReverseMap
 Reverse map of objects that have been added to the NameManager. More...
 
std::string mDefaultName
 String which will be used as a name for any object which is passed in with an empty string name. More...
 
bool mNameBeforeNumber
 Internal variable used to arrange the text when resolving duplicate names. More...
 
std::string mPrefix
 The chunk of text that gets prepended to a duplicate name. More...
 
std::string mInfix
 The chunk of text that comes between a duplicate name and its duplication number. More...
 
std::string mAffix
 The chunk of text that gets appended to a duplicate name. More...
 

Detailed Description

template<typename T>
class dart::common::NameManager< T >

class NameManager

Typical usage:

using namespace dart;
NameManager<BodyNode*> nameMgr;
BodyNode* bodyNode = new BodyNode();
std::string name = "Link";
if (!nameMgr.hasName(name))
nameMgr.addName(name, bodyNode); // "Link"
else
name = nameMgr.issueNewNameAndAdd(name, bodyNode); // "Link1"
bodyNode->setName(name);
std::string * name
Definition: SkelParser.cpp:1642
Definition: BulletCollisionDetector.cpp:63

Constructor & Destructor Documentation

◆ NameManager()

template<class T >
dart::common::NameManager< T >::NameManager ( const std::string &  _managerName = "default",
const std::string &  _defaultName = "default" 
)

Constructor.

◆ ~NameManager()

template<typename T >
virtual dart::common::NameManager< T >::~NameManager ( )
virtualdefault

Destructor.

Member Function Documentation

◆ addName()

template<class T >
bool dart::common::NameManager< T >::addName ( const std::string &  _name,
const T &  _obj 
)

Add an object to the map.

◆ changeObjectName()

template<class T >
std::string dart::common::NameManager< T >::changeObjectName ( const T &  _obj,
const std::string &  _newName 
)

Change the name of a currently held object.

This will do nothing if the object is already using _newName or if the object is not held by this NameManager.

If the object is held, its new name is returned (which might be different than _newName if there was a duplicate naming conflict). If the object is not held, an empty string will be returned.

◆ clear()

template<class T >
void dart::common::NameManager< T >::clear

Clear all the objects.

◆ getCount()

template<class T >
std::size_t dart::common::NameManager< T >::getCount

Get the number of the objects currently stored by the NameManager.

◆ getDefaultName()

template<class T >
const std::string & dart::common::NameManager< T >::getDefaultName

Get the name that will be provided to objects passed in with an empty string for a name.

◆ getManagerName()

template<class T >
const std::string & dart::common::NameManager< T >::getManagerName

Get the name of this NameManager.

◆ getName()

template<class T >
std::string dart::common::NameManager< T >::getName ( const T &  _obj) const

Use a reverse lookup to get the name that the manager has _obj listed under.

Returns an empty string if it is not in the list.

◆ getObject()

template<class T >
T dart::common::NameManager< T >::getObject ( const std::string &  _name) const

Get object by given name.

Parameters
[in]_nameName of the requested object
Returns
The object if it exists, or nullptr if it does not exist

◆ hasName()

template<class T >
bool dart::common::NameManager< T >::hasName ( const std::string &  _name) const

Return true if the name is contained.

◆ hasObject()

template<class T >
bool dart::common::NameManager< T >::hasObject ( const T &  _obj) const

Return true if the object is contained.

◆ issueNewName()

template<class T >
std::string dart::common::NameManager< T >::issueNewName ( const std::string &  _name) const

Issue new unique combined name of given base name and number suffix.

◆ issueNewNameAndAdd()

template<class T >
std::string dart::common::NameManager< T >::issueNewNameAndAdd ( const std::string &  _name,
const T &  _obj 
)

Call issueNewName() and add the result to the map.

◆ removeEntries()

template<class T >
void dart::common::NameManager< T >::removeEntries ( const std::string &  _name,
const T &  _obj 
)

Remove _name using the forward lookup and _obj using the reverse lookup.

This will allow you to add _obj under the name _name without any conflicts

◆ removeName()

template<class T >
bool dart::common::NameManager< T >::removeName ( const std::string &  _name)

Remove an object from the Manager based on its name.

◆ removeObject()

template<class T >
bool dart::common::NameManager< T >::removeObject ( const T &  _obj)

Remove an object from the Manager based on reverse lookup.

◆ setDefaultName()

template<class T >
void dart::common::NameManager< T >::setDefaultName ( const std::string &  _defaultName)

Set the name that will be provided to objects passed in with an empty string for a name.

◆ setManagerName()

template<class T >
void dart::common::NameManager< T >::setManagerName ( const std::string &  _managerName)

Set the name of this NameManager so that it can be printed in error reports.

◆ setPattern()

template<class T >
bool dart::common::NameManager< T >::setPattern ( const std::string &  _newPattern)

Set a new pattern for name generation.

Use s to indicate the base name and use d to indicate where the number belongs. The pattern must contain both a s and a d.

Examples: "%s(%d)" : name -> name(1) -> name(2) "%d-%s" : name -> 1-name -> 2-name

returns false if the pattern was invalid (i.e. did not contain b oth s and d)

Member Data Documentation

◆ mAffix

template<typename T >
std::string dart::common::NameManager< T >::mAffix
protected

The chunk of text that gets appended to a duplicate name.

◆ mDefaultName

template<typename T >
std::string dart::common::NameManager< T >::mDefaultName
protected

String which will be used as a name for any object which is passed in with an empty string name.

◆ mInfix

template<typename T >
std::string dart::common::NameManager< T >::mInfix
protected

The chunk of text that comes between a duplicate name and its duplication number.

◆ mManagerName

template<typename T >
std::string dart::common::NameManager< T >::mManagerName
protected

Name of this NameManager. This is used to report errors.

◆ mMap

template<typename T >
std::map<std::string, T> dart::common::NameManager< T >::mMap
protected

Map of objects that have been added to the NameManager.

◆ mNameBeforeNumber

template<typename T >
bool dart::common::NameManager< T >::mNameBeforeNumber
protected

Internal variable used to arrange the text when resolving duplicate names.

◆ mPrefix

template<typename T >
std::string dart::common::NameManager< T >::mPrefix
protected

The chunk of text that gets prepended to a duplicate name.

◆ mReverseMap

template<typename T >
std::map<T, std::string> dart::common::NameManager< T >::mReverseMap
protected

Reverse map of objects that have been added to the NameManager.