33 #ifndef DART_COMMON_DETAIL_NAMEMANAGER_HPP_
34 #define DART_COMMON_DETAIL_NAMEMANAGER_HPP_
47 const std::string& _defaultName)
48 : mManagerName(_managerName),
49 mDefaultName(_defaultName),
50 mNameBeforeNumber(true),
51 mPrefix(
""), mInfix(
"("), mAffix(
")")
60 std::size_t name_start = _newPattern.find(
"%s");
61 std::size_t number_start = _newPattern.find(
"%d");
63 if(name_start == std::string::npos || number_start == std::string::npos)
66 if(name_start < number_start)
67 mNameBeforeNumber =
true;
69 mNameBeforeNumber =
false;
71 std::size_t prefix_end = std::min(name_start, number_start);
72 std::size_t infix_end = std::max(name_start, number_start);
74 mPrefix = _newPattern.substr(0, prefix_end);
75 mInfix = _newPattern.substr(prefix_end+2, infix_end-prefix_end-2);
76 mAffix = _newPattern.substr(infix_end+2);
94 ss << mPrefix << _name << mInfix << count++ << mAffix;
96 ss << mPrefix << count++ << mInfix << _name << mAffix;
98 }
while (hasName(newName));
100 dtmsg <<
"[NameManager::issueNewName] (" << mManagerName <<
") The name ["
101 << _name <<
"] is a duplicate, so it has been renamed to ["
112 const std::string& checkEmpty = _name.empty()? mDefaultName : _name;
113 const std::string& newName = issueNewName(checkEmpty);
114 addName(newName, _obj);
125 dtwarn <<
"[NameManager::addName] (" << mManagerName
126 <<
") Empty name is not allowed!\n";
132 dtwarn <<
"[NameManager::addName] (" << mManagerName <<
") The name ["
133 << _name <<
"] already exists!\n";
137 mMap.insert(std::pair<std::string, T>(_name, _obj));
138 mReverseMap.insert(std::pair<T, std::string>(_obj, _name));
140 assert(mReverseMap.size() == mMap.size());
149 assert(mReverseMap.size() == mMap.size());
153 if (it == mMap.end())
157 mReverseMap.find(it->second);
159 if (rit != mReverseMap.end())
160 mReverseMap.erase(rit);
171 assert(mReverseMap.size() == mMap.size());
175 if (rit == mReverseMap.end())
179 if (it != mMap.end())
182 mReverseMap.erase(rit);
207 return (mMap.find(_name) != mMap.end());
214 return (mReverseMap.find(_obj) != mReverseMap.end());
228 typename std::map<std::string, T>::const_iterator
result =
241 assert(mReverseMap.size() == mMap.size());
243 typename std::map<T, std::string>::const_iterator
result =
244 mReverseMap.find(_obj);
246 if (
result != mReverseMap.end())
255 const std::string& _newName)
257 assert(mReverseMap.size() == mMap.size());
260 if(rit == mReverseMap.end())
263 if(rit->second == _newName)
266 removeName(rit->second);
267 return issueNewNameAndAdd(_newName, _obj);
274 mDefaultName = _defaultName;
288 mManagerName = _managerName;
#define dtmsg
Output a message.
Definition: Console.hpp:40
#define dtwarn
Output a warning message.
Definition: Console.hpp:46
CollisionResult * result
Collision result of DART.
Definition: FCLCollisionDetector.cpp:157
void clear()
Clear all the objects.
Definition: NameManager.hpp:197
NameManager(const std::string &_managerName="default", const std::string &_defaultName="default")
Constructor.
Definition: NameManager.hpp:46
bool hasObject(const T &_obj) const
Return true if the object is contained.
Definition: NameManager.hpp:212
bool removeObject(const T &_obj)
Remove an object from the Manager based on reverse lookup.
Definition: NameManager.hpp:169
void setManagerName(const std::string &_managerName)
Set the name of this NameManager so that it can be printed in error reports.
Definition: NameManager.hpp:286
bool removeName(const std::string &_name)
Remove an object from the Manager based on its name.
Definition: NameManager.hpp:147
const std::string & getManagerName() const
Get the name of this NameManager.
Definition: NameManager.hpp:293
bool setPattern(const std::string &_newPattern)
Set a new pattern for name generation.
Definition: NameManager.hpp:58
T getObject(const std::string &_name) const
Get object by given name.
Definition: NameManager.hpp:226
void removeEntries(const std::string &_name, const T &_obj)
Remove _name using the forward lookup and _obj using the reverse lookup.
Definition: NameManager.hpp:189
std::string changeObjectName(const T &_obj, const std::string &_newName)
Change the name of a currently held object.
Definition: NameManager.hpp:254
bool addName(const std::string &_name, const T &_obj)
Add an object to the map.
Definition: NameManager.hpp:121
std::string getName(const T &_obj) const
Use a reverse lookup to get the name that the manager has _obj listed under.
Definition: NameManager.hpp:239
std::string issueNewName(const std::string &_name) const
Issue new unique combined name of given base name and number suffix.
Definition: NameManager.hpp:83
std::size_t getCount() const
Get the number of the objects currently stored by the NameManager.
Definition: NameManager.hpp:219
std::string issueNewNameAndAdd(const std::string &_name, const T &_obj)
Call issueNewName() and add the result to the map.
Definition: NameManager.hpp:109
bool hasName(const std::string &_name) const
Return true if the name is contained.
Definition: NameManager.hpp:205
void setDefaultName(const std::string &_defaultName)
Set the name that will be provided to objects passed in with an empty string for a name.
Definition: NameManager.hpp:272
const std::string & getDefaultName() const
Get the name that will be provided to objects passed in with an empty string for a name.
Definition: NameManager.hpp:279
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:622
Definition: BulletCollisionDetector.cpp:63