175 bool Rename(std::string oldpath, std::string newname);
187 bool Rename(std::string path, std::string oldname, std::string newname);
340 std::string namespaceName =
"/Names";
341 std::string::size_type offset = name.find(namespaceName);
348 offset = name.find(
'/');
351 NS_ASSERT_MSG(
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
355 name =
"/Names/" + name;
365 std::string::size_type i = name.rfind(
'/');
367 "NamesPriv::Add(): Internal error. Can't find '/' in name");
374 NS_ASSERT_MSG(i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
381 return Add(name.substr(0, i), name.substr(i + 1),
object);
388 if (path ==
"/Names")
392 return Add(
Find(path), name,
object);
410 NS_ASSERT_MSG(node,
"NamesPriv::Name(): context must point to a previously named node");
451 std::string namespaceName =
"/Names";
452 std::string::size_type offset = oldpath.find(namespaceName);
459 offset = oldpath.find(
'/');
462 NS_ASSERT_MSG(
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
466 oldpath =
"/Names/" + oldpath;
476 std::string::size_type i = oldpath.rfind(
'/');
478 "NamesPriv::Add(): Internal error. Can't find '/' in name");
485 NS_ASSERT_MSG(i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
492 return Rename(oldpath.substr(0, i), oldpath.substr(i + 1), newname);
499 if (path ==
"/Names")
515 NS_ASSERT_MSG(node,
"NamesPriv::Name(): context must point to a previously named node");
528 std::map<std::string, NameNode*>::iterator i = node->
m_nameMap.find(oldname);
547 changeNode->
m_name = newname;
567 return i->second->m_name;
585 "NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
591 path =
"/" + p->
m_name + path;
593 }
while ((p = p->
m_parent) !=
nullptr);
617 std::string namespaceName =
"/Names/";
618 std::string remaining;
620 std::string::size_type offset = path.find(namespaceName);
624 remaining = path.substr(namespaceName.size());
643 NS_LOG_LOGIC(
"Looking for the object of name " << remaining);
644 offset = remaining.find(
'/');
645 if (offset == std::string::npos)
651 std::map<std::string, NameNode*>::iterator i = node->
m_nameMap.find(remaining);
660 return i->second->m_object;
669 offset = remaining.find(
'/');
670 std::string segment = remaining.substr(0, offset);
672 std::map<std::string, NameNode*>::iterator i = node->
m_nameMap.find(segment);
681 remaining = remaining.substr(offset + 1);
688 NS_ASSERT_MSG(node,
"NamesPriv::Find(): Internal error: this can't happen");
697 if (path ==
"/Names")
721 NS_LOG_LOGIC(
"Context does not point to a previously named node");
726 std::map<std::string, NameNode*>::iterator i = node->
m_nameMap.find(name);
735 return i->second->m_object;
747 NS_LOG_LOGIC(
"Object does not exist in object map, returning NameNode 0");
752 NS_LOG_LOGIC(
"Object exists in object map, returning NameNode " << &i->second);
762 std::map<std::string, NameNode*>::iterator i = node->
m_nameMap.find(name);
788 NS_ABORT_MSG_UNLESS(result,
"Names::Rename(): Error renaming " << oldpath <<
" to " << newname);
805 "Names::Rename (): Error renaming " << path <<
" " << oldname <<
" to "
815 "Names::Add(): Error adding name " << name <<
" under context "
825 "Names::Rename (): Error renaming " << oldname <<
" to " << newname
826 <<
" 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()
Smart pointer class similar to boost::intrusive_ptr.
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.