DART
6.7.3
|
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... | |
T | 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... | |
class NameManager
Typical usage:
dart::common::NameManager< T >::NameManager | ( | const std::string & | _managerName = "default" , |
const std::string & | _defaultName = "default" |
||
) |
Constructor.
|
virtualdefault |
Destructor.
bool dart::common::NameManager< T >::addName | ( | const std::string & | _name, |
const T & | _obj | ||
) |
Add an object to the map.
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.
void dart::common::NameManager< T >::clear |
Clear all the objects.
std::size_t dart::common::NameManager< T >::getCount |
Get the number of the objects currently stored by the NameManager.
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.
const std::string & dart::common::NameManager< T >::getManagerName |
Get the name of this NameManager.
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.
T dart::common::NameManager< T >::getObject | ( | const std::string & | _name | ) | const |
Get object by given name.
[in] | _name | Name of the requested object |
bool dart::common::NameManager< T >::hasName | ( | const std::string & | _name | ) | const |
Return true if the name is contained.
bool dart::common::NameManager< T >::hasObject | ( | const T & | _obj | ) | const |
Return true if the object is contained.
std::string dart::common::NameManager< T >::issueNewName | ( | const std::string & | _name | ) | const |
Issue new unique combined name of given base name and number suffix.
std::string dart::common::NameManager< T >::issueNewNameAndAdd | ( | const std::string & | _name, |
const T & | _obj | ||
) |
Call issueNewName() and add the result to the map.
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
bool dart::common::NameManager< T >::removeName | ( | const std::string & | _name | ) |
Remove an object from the Manager based on its name.
bool dart::common::NameManager< T >::removeObject | ( | const T & | _obj | ) |
Remove an object from the Manager based on reverse lookup.
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.
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.
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)
|
protected |
The chunk of text that gets appended to a duplicate name.
|
protected |
String which will be used as a name for any object which is passed in with an empty string name.
|
protected |
The chunk of text that comes between a duplicate name and its duplication number.
|
protected |
Name of this NameManager. This is used to report errors.
|
protected |
Map of objects that have been added to the NameManager.
|
protected |
Internal variable used to arrange the text when resolving duplicate names.
|
protected |
The chunk of text that gets prepended to a duplicate name.
|
protected |
Reverse map of objects that have been added to the NameManager.