84 : m_parent (0), m_name (
""), m_object (0)
107 : m_parent (parent), m_name (name), m_object (object)
138 bool Add (std::string path, std::string name,
Ptr<Object> object);
149 bool Rename (std::string oldpath, std::string newname);
154 bool Rename (std::string path, std::string oldname, std::string newname);
259 std::string namespaceName =
"/Names";
260 std::string::size_type offset = name.find (namespaceName);
267 offset = name.find (
"/");
270 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
274 name =
"/Names/" + name;
284 std::string::size_type i = name.rfind (
"/");
285 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
292 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
299 return Add (name.substr (0, i), name.substr (i + 1), object);
306 if (path ==
"/Names")
310 return Add (
Find (path), name,
object);
328 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
369 std::string namespaceName =
"/Names";
370 std::string::size_type offset = oldpath.find (namespaceName);
377 offset = oldpath.find (
"/");
380 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
384 oldpath =
"/Names/" + oldpath;
394 std::string::size_type i = oldpath.rfind (
"/");
395 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
402 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
409 return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname);
416 if (path ==
"/Names")
420 return Rename (
Find (path), oldname, newname);
432 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
445 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (oldname);
464 changeNode->
m_name = newname;
484 return i->second->m_name;
501 NS_ASSERT_MSG (p,
"NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
507 path =
"/" + p->
m_name + path;
535 std::string namespaceName =
"/Names/";
536 std::string remaining;
538 std::string::size_type offset = path.find (namespaceName);
542 remaining = path.substr (namespaceName.size ());
561 NS_LOG_LOGIC (
"Looking for the object of name " << remaining);
562 offset = remaining.find (
"/");
563 if (offset == std::string::npos)
569 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (remaining);
578 return i->second->m_object;
587 offset = remaining.find (
"/");
588 std::string segment = remaining.substr (0, offset);
590 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (segment);
599 remaining = remaining.substr (offset + 1);
606 NS_ASSERT_MSG (node,
"NamesPriv::Find(): Internal error: this can't happen");
615 if (path ==
"/Names")
639 NS_LOG_LOGIC (
"Context does not point to a previously named node");
644 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
653 return i->second->m_object;
665 NS_LOG_LOGIC (
"Object does not exist in object map, returning NameNode 0");
670 NS_LOG_LOGIC (
"Object exists in object map, returning NameNode " << &i->second);
680 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
706 NS_ABORT_MSG_UNLESS (result,
"Names::Rename(): Error renaming " << oldpath <<
" to " << newname);
722 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << path <<
" " << oldname <<
" to " << newname);
730 NS_ABORT_MSG_UNLESS (result,
"Names::Add(): Error adding name " << name <<
" under context " << &context);
738 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << oldname <<
" to " << newname <<
" under context " <<
Ptr< Object > m_object
The object corresponding to this NameNode.
The singleton root Names object.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ns3::Singleton declaration and template implementation.
std::map< std::string, NameNode * > m_nameMap
Children of this NameNode.
NameNode * IsNamed(Ptr< Object > object)
Check if an object has a name.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
NameNode * m_parent
The parent NameNode.
static NamesPriv * Get(void)
Get a pointer to the singleton instance.
Ptr< Object > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it...
static void Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr
A directory of name and Ptr
static void Clear(void)
Clear the list of objects associated with names.
bool Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
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...
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
std::string m_name
The name of this NameNode.
void Clear(void)
Clear the list of objects associated with names.
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
NameNode & operator=(const NameNode &rhs)
Assignment operator.
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...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
std::map< Ptr< Object >, NameNode * > m_objectMap
Map from object pointers to their NameNodes.
NameNode m_root
The root NameNode.
NameNode()
Default constructor.
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...
Declaration of class ns3::Names.
bool Add(std::string name, Ptr< Object > object)
Add the association between the string "name" and the Ptr
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
bool IsDuplicateName(NameNode *node, std::string name)
Check if a name already exists as a child of a NameNode.
NS_ABORT_x macro definitions.