48 : m_parent (0), m_name (
""), m_object (0)
71 : m_parent (parent), m_name (name), m_object (object)
91 bool Rename (std::string oldpath, std::string newname);
92 bool Rename (std::string path, std::string oldname, std::string newname);
180 std::string namespaceName =
"/Names";
181 std::string::size_type offset = name.find (namespaceName);
188 offset = name.find (
"/");
191 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
195 name =
"/Names/" + name;
205 std::string::size_type i = name.rfind (
"/");
206 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
213 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
220 return Add (name.substr (0, i), name.substr (i + 1), object);
227 if (path ==
"/Names")
231 return Add (
Find (path), name,
object);
249 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
290 std::string namespaceName =
"/Names";
291 std::string::size_type offset = oldpath.find (namespaceName);
298 offset = oldpath.find (
"/");
301 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
305 oldpath =
"/Names/" + oldpath;
315 std::string::size_type i = oldpath.rfind (
"/");
316 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
323 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
330 return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname);
337 if (path ==
"/Names")
341 return Rename (
Find (path), oldname, newname);
353 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
366 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (oldname);
385 changeNode->
m_name = newname;
405 return i->second->m_name;
422 NS_ASSERT_MSG (p,
"NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
428 path =
"/" + p->
m_name + path;
456 std::string namespaceName =
"/Names/";
457 std::string remaining;
459 std::string::size_type offset = path.find (namespaceName);
463 remaining = path.substr (namespaceName.size ());
482 NS_LOG_LOGIC (
"Looking for the object of name " << remaining);
483 offset = remaining.find (
"/");
484 if (offset == std::string::npos)
490 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (remaining);
499 return i->second->m_object;
508 offset = remaining.find (
"/");
509 std::string segment = remaining.substr (0, offset);
511 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (segment);
520 remaining = remaining.substr (offset + 1);
527 NS_ASSERT_MSG (node,
"NamesPriv::Find(): Internal error: this can't happen");
536 if (path ==
"/Names")
560 NS_LOG_LOGIC (
"Context does not point to a previously named node");
565 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
574 return i->second->m_object;
586 NS_LOG_LOGIC (
"Object does not exist in object map, returning NameNode 0");
591 NS_LOG_LOGIC (
"Object exists in object map, returning NameNode " << &i->second);
601 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
627 NS_ABORT_MSG_UNLESS (result,
"Names::Rename(): Error renaming " << oldpath <<
" to " << newname);
643 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << path <<
" " << oldname <<
" to " << newname);
651 NS_ABORT_MSG_UNLESS (result,
"Names::Add(): Error adding name " << name <<
" under context " << &context);
659 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << oldname <<
" to " << newname <<
" under context " <<
#define NS_LOG_FUNCTION(parameters)
std::map< std::string, NameNode * > m_nameMap
#define NS_LOG_FUNCTION_NOARGS()
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
A directory of name and Ptr<Object> associations that allows us to give any ns3 Object a name...
bool Rename(std::string oldpath, std::string newname)
std::string FindPath(Ptr< Object > object)
std::string FindName(Ptr< Object > object)
#define NS_LOG_LOGIC(msg)
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
NameNode & operator=(const NameNode &rhs)
static std::string FindPath(Ptr< Object > object)
#define NS_ASSERT_MSG(condition, message)
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
std::map< Ptr< Object >, NameNode * > m_objectMap
static NamesPriv * Get(void)
static std::string FindName(Ptr< Object > object)
NameNode * IsNamed(Ptr< Object >)
bool Add(std::string name, Ptr< Object > object)
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
Ptr< Object > Find(std::string name)
bool IsDuplicateName(NameNode *node, std::string name)