83 : m_parent (0), m_name (
""), m_object (0)
106 : m_parent (parent), m_name (name), m_object (object)
148 bool Add (std::string path, std::string name,
Ptr<Object> object);
169 bool Rename (std::string oldpath, std::string newname);
181 bool Rename (std::string path, std::string oldname, std::string newname);
335 std::string namespaceName =
"/Names";
336 std::string::size_type offset = name.find (namespaceName);
343 offset = name.find (
"/");
346 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
350 name =
"/Names/" + name;
360 std::string::size_type i = name.rfind (
"/");
361 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
368 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
375 return Add (name.substr (0, i), name.substr (i + 1), object);
382 if (path ==
"/Names")
386 return Add (
Find (path), name,
object);
404 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
445 std::string namespaceName =
"/Names";
446 std::string::size_type offset = oldpath.find (namespaceName);
453 offset = oldpath.find (
"/");
456 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
460 oldpath =
"/Names/" + oldpath;
470 std::string::size_type i = oldpath.rfind (
"/");
471 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
478 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
485 return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname);
492 if (path ==
"/Names")
496 return Rename (
Find (path), oldname, newname);
508 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
521 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (oldname);
540 changeNode->
m_name = newname;
560 return i->second->m_name;
577 NS_ASSERT_MSG (p,
"NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
583 path =
"/" + p->
m_name + path;
611 std::string namespaceName =
"/Names/";
612 std::string remaining;
614 std::string::size_type offset = path.find (namespaceName);
618 remaining = path.substr (namespaceName.size ());
637 NS_LOG_LOGIC (
"Looking for the object of name " << remaining);
638 offset = remaining.find (
"/");
639 if (offset == std::string::npos)
645 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (remaining);
654 return i->second->m_object;
663 offset = remaining.find (
"/");
664 std::string segment = remaining.substr (0, offset);
666 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (segment);
675 remaining = remaining.substr (offset + 1);
682 NS_ASSERT_MSG (node,
"NamesPriv::Find(): Internal error: this can't happen");
691 if (path ==
"/Names")
715 NS_LOG_LOGIC (
"Context does not point to a previously named node");
720 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
729 return i->second->m_object;
741 NS_LOG_LOGIC (
"Object does not exist in object map, returning NameNode 0");
746 NS_LOG_LOGIC (
"Object exists in object map, returning NameNode " << &i->second);
756 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
782 NS_ABORT_MSG_UNLESS (result,
"Names::Rename(): Error renaming " << oldpath <<
" to " << newname);
794 Names::Rename (std::string path, std::string oldname, std::string newname)
798 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << path <<
" " << oldname <<
" to " << newname);
806 NS_ABORT_MSG_UNLESS (result,
"Names::Add(): Error adding name " << name <<
" under context " << &context);
814 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.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
#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)
Internal implementation for ns3::Names::Find(std::string)
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...
static void Clear(void)
Clear the list of objects associated with names.
bool Rename(std::string oldpath, std::string newname)
Internal implementation for Names::Rename(std::string,std::string)
std::string FindPath(Ptr< Object > object)
Internal implementation of Names::FindPath()
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
std::string m_name
The name of this NameNode.
void Clear(void)
Internal implementation for Names::Clear()
std::string FindName(Ptr< Object > object)
Internal implementation for Names::FindName()
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
static void Rename(std::string oldpath, std::string newname)
Rename a previously associated name.
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)
Internal implementation for Names::Add(std::string,Ptr<Object>)
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.