175 bool Rename(std::string oldpath, std::string newname);
187 bool Rename(std::string path, std::string oldname, std::string newname);
339 std::string namespaceName =
"/Names";
340 std::string::size_type offset = name.find(namespaceName);
347 offset = name.find(
'/');
350 NS_ASSERT_MSG(
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
354 name =
"/Names/" + name;
364 std::string::size_type i = name.rfind(
'/');
366 "NamesPriv::Add(): Internal error. Can't find '/' in name");
373 NS_ASSERT_MSG(i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
380 return Add(name.substr(0, i), name.substr(i + 1),
object);
387 if (path ==
"/Names")
391 return Add(
Find(path), name,
object);
409 NS_ASSERT_MSG(node,
"NamesPriv::Name(): context must point to a previously named node");
422 auto newNode =
new NameNode(node, name,
object);
450 std::string namespaceName =
"/Names";
451 std::string::size_type offset = oldpath.find(namespaceName);
458 offset = oldpath.find(
'/');
461 NS_ASSERT_MSG(
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
465 oldpath =
"/Names/" + oldpath;
475 std::string::size_type i = oldpath.rfind(
'/');
477 "NamesPriv::Add(): Internal error. Can't find '/' in name");
484 NS_ASSERT_MSG(i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
491 return Rename(oldpath.substr(0, i), oldpath.substr(i + 1), newname);
498 if (path ==
"/Names")
514 NS_ASSERT_MSG(node,
"NamesPriv::Name(): context must point to a previously named node");
546 changeNode->
m_name = newname;
566 return i->second->m_name;
584 "NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
590 path =
"/" + p->
m_name + path;
592 }
while ((p = p->
m_parent) !=
nullptr);
616 std::string namespaceName =
"/Names/";
617 std::string remaining;
619 std::string::size_type offset = path.find(namespaceName);
623 remaining = path.substr(namespaceName.size());
642 NS_LOG_LOGIC(
"Looking for the object of name " << remaining);
643 offset = remaining.find(
'/');
644 if (offset == std::string::npos)
650 auto i = node->
m_nameMap.find(remaining);
659 return i->second->m_object;
668 offset = remaining.find(
'/');
669 std::string segment = remaining.substr(0, offset);
680 remaining = remaining.substr(offset + 1);
687 NS_ASSERT_MSG(node,
"NamesPriv::Find(): Internal error: this can't happen");
696 if (path ==
"/Names")
720 NS_LOG_LOGIC(
"Context does not point to a previously named node");
734 return i->second->m_object;
746 NS_LOG_LOGIC(
"Object does not exist in object map, returning NameNode 0");
751 NS_LOG_LOGIC(
"Object exists in object map, returning NameNode " << &i->second);
787 NS_ABORT_MSG_UNLESS(result,
"Names::Rename(): Error renaming " << oldpath <<
" to " << newname);
804 "Names::Rename (): Error renaming " << path <<
" " << oldname <<
" to "
814 "Names::Add(): Error adding name " << name <<
" under context "
824 "Names::Rename (): Error renaming " << oldname <<
" to " << newname
825 <<
" under context " << &context);
NS_ABORT_x macro definitions.
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
NameNode * m_parent
The parent NameNode.
NameNode()
Default constructor.
Ptr< Object > m_object
The object corresponding to this NameNode.
std::map< std::string, NameNode * > m_nameMap
Children of 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 void Clear()
Clear the list of objects associated with names.
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 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.
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)
std::string FindName(Ptr< Object > object)
Internal implementation for Names::FindName()
~NamesPriv() override
Destructor.
NameNode * IsNamed(Ptr< Object > object)
Check if an object has a name.
std::map< Ptr< Object >, NameNode * > m_objectMap
Map from object pointers to their NameNodes.
Ptr< Object > Find(std::string path)
Internal implementation for ns3::Names::Find(std::string)
void Clear()
Internal implementation for Names::Clear()
static NamesPriv * Get()
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.