83 : m_parent (0), m_name (
""), m_object (0)
105 : m_parent (parent), m_name (name), m_object (
object)
147 bool Add (std::string path, std::string name,
Ptr<Object> object);
168 bool Rename (std::string oldpath, std::string newname);
180 bool Rename (std::string path, std::string oldname, std::string newname);
333 std::string namespaceName =
"/Names";
334 std::string::size_type offset = name.find (namespaceName);
341 offset = name.find (
"/");
344 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
348 name =
"/Names/" + name;
358 std::string::size_type i = name.rfind (
"/");
359 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
366 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
373 return Add (name.substr (0, i), name.substr (i + 1),
object);
380 if (path ==
"/Names")
384 return Add (
Find (path), name,
object);
402 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
443 std::string namespaceName =
"/Names";
444 std::string::size_type offset = oldpath.find (namespaceName);
451 offset = oldpath.find (
"/");
454 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
458 oldpath =
"/Names/" + oldpath;
468 std::string::size_type i = oldpath.rfind (
"/");
469 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
476 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
483 return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname);
490 if (path ==
"/Names")
494 return Rename (
Find (path), oldname, newname);
506 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
519 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (oldname);
538 changeNode->
m_name = newname;
558 return i->second->m_name;
575 NS_ASSERT_MSG (p,
"NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
581 path =
"/" + p->
m_name + path;
609 std::string namespaceName =
"/Names/";
610 std::string remaining;
612 std::string::size_type offset = path.find (namespaceName);
616 remaining = path.substr (namespaceName.size ());
635 NS_LOG_LOGIC (
"Looking for the object of name " << remaining);
636 offset = remaining.find (
"/");
637 if (offset == std::string::npos)
643 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (remaining);
652 return i->second->m_object;
661 offset = remaining.find (
"/");
662 std::string segment = remaining.substr (0, offset);
664 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (segment);
673 remaining = remaining.substr (offset + 1);
680 NS_ASSERT_MSG (node,
"NamesPriv::Find(): Internal error: this can't happen");
689 if (path ==
"/Names")
713 NS_LOG_LOGIC (
"Context does not point to a previously named node");
718 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
727 return i->second->m_object;
739 NS_LOG_LOGIC (
"Object does not exist in object map, returning NameNode 0");
744 NS_LOG_LOGIC (
"Object exists in object map, returning NameNode " << &i->second);
754 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
NS_ABORT_x macro definitions.
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
NameNode * m_parent
The parent NameNode.
std::map< std::string, NameNode * > m_nameMap
Children of this NameNode.
NameNode()
Default constructor.
Ptr< Object > m_object
The object corresponding to this NameNode.
NameNode & operator=(const NameNode &rhs)
Assignment operator.
std::string m_name
The name of this NameNode.
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr<Object> obj.
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and,...
static void Clear(void)
Clear the list of objects associated with names.
static std::string FindPath(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and return the...
The singleton root Names object.
std::map< Ptr< Object >, NameNode * > m_objectMap
Map from object pointers to their NameNodes.
bool Add(std::string name, Ptr< Object > object)
Internal implementation for Names::Add(std::string,Ptr<Object>)
NameNode m_root
The root NameNode.
bool IsDuplicateName(NameNode *node, std::string name)
Check if a name already exists as a child of a NameNode.
std::string FindPath(Ptr< Object > object)
Internal implementation of Names::FindPath()
bool Rename(std::string oldpath, std::string newname)
Internal implementation for Names::Rename(std::string,std::string)
void Clear(void)
Internal implementation for Names::Clear()
std::string FindName(Ptr< Object > object)
Internal implementation for Names::FindName()
NameNode * IsNamed(Ptr< Object > object)
Check if an object has a name.
Ptr< Object > Find(std::string path)
Internal implementation for ns3::Names::Find(std::string)
static NamesPriv * Get(void)
Get a pointer to the singleton instance.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Declaration of class ns3::Names.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::Singleton declaration and template implementation.