55 : m_parent (0), m_name (
""), m_object (0)
78 : m_parent (parent), m_name (name), m_object (object)
98 bool Rename (std::string oldpath, std::string newname);
99 bool Rename (std::string path, std::string oldname, std::string newname);
187 std::string namespaceName =
"/Names";
188 std::string::size_type offset = name.find (namespaceName);
195 offset = name.find (
"/");
198 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
202 name =
"/Names/" + name;
212 std::string::size_type i = name.rfind (
"/");
213 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
220 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
227 return Add (name.substr (0, i), name.substr (i + 1), object);
234 if (path ==
"/Names")
238 return Add (
Find (path), name,
object);
256 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
297 std::string namespaceName =
"/Names";
298 std::string::size_type offset = oldpath.find (namespaceName);
305 offset = oldpath.find (
"/");
308 NS_ASSERT_MSG (
false,
"NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
312 oldpath =
"/Names/" + oldpath;
322 std::string::size_type i = oldpath.rfind (
"/");
323 NS_ASSERT_MSG (i != std::string::npos,
"NamesPriv::Add(): Internal error. Can't find '/' in name");
330 NS_ASSERT_MSG (i != 0,
"NamesPriv::Add(): Can't find a name in the path string");
337 return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname);
344 if (path ==
"/Names")
348 return Rename (
Find (path), oldname, newname);
360 NS_ASSERT_MSG (node,
"NamesPriv::Name(): context must point to a previously named node");
373 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (oldname);
392 changeNode->
m_name = newname;
412 return i->second->m_name;
429 NS_ASSERT_MSG (p,
"NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map");
435 path =
"/" + p->
m_name + path;
463 std::string namespaceName =
"/Names/";
464 std::string remaining;
466 std::string::size_type offset = path.find (namespaceName);
470 remaining = path.substr (namespaceName.size ());
489 NS_LOG_LOGIC (
"Looking for the object of name " << remaining);
490 offset = remaining.find (
"/");
491 if (offset == std::string::npos)
497 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (remaining);
506 return i->second->m_object;
515 offset = remaining.find (
"/");
516 std::string segment = remaining.substr (0, offset);
518 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (segment);
527 remaining = remaining.substr (offset + 1);
534 NS_ASSERT_MSG (node,
"NamesPriv::Find(): Internal error: this can't happen");
543 if (path ==
"/Names")
567 NS_LOG_LOGIC (
"Context does not point to a previously named node");
572 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
581 return i->second->m_object;
593 NS_LOG_LOGIC (
"Object does not exist in object map, returning NameNode 0");
598 NS_LOG_LOGIC (
"Object exists in object map, returning NameNode " << &i->second);
608 std::map<std::string, NameNode *>::iterator i = node->
m_nameMap.find (name);
634 NS_ABORT_MSG_UNLESS (result,
"Names::Rename(): Error renaming " << oldpath <<
" to " << newname);
650 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << path <<
" " << oldname <<
" to " << newname);
658 NS_ABORT_MSG_UNLESS (result,
"Names::Add(): Error adding name " << name <<
" under context " << &context);
666 NS_ABORT_MSG_UNLESS (result,
"Names::Rename (): Error renaming " << oldname <<
" to " << newname <<
" under context " <<
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::map< std::string, NameNode * > m_nameMap
#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.
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)
std::string FindPath(Ptr< Object > object)
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
std::string FindName(Ptr< Object > object)
#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)
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
static NamesPriv * Get(void)
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.
NameNode * IsNamed(Ptr< Object >)
bool Add(std::string name, Ptr< Object > object)
static Ptr< Object > FindInternal(std::string path)
Non-templated internal version of Names::Find.
Ptr< Object > Find(std::string name)
bool IsDuplicateName(NameNode *node, std::string name)
NS_ABORT_x macro definitions.