author | Josh Pelkey <jpelkey@gatech.edu> |
Fri, 13 May 2011 14:52:27 -0400 | |
changeset 7169 | 358f71a624d8 |
parent 6821 | 203367ae7433 |
child 7256 | b04ba6772f8c |
permissions | -rw-r--r-- |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
2 |
/* |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
3 |
* Copyright (c) 2009 University of Washington |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
4 |
* |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
8 |
* |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
13 |
* |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
17 |
*/ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
18 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
19 |
#include <map> |
4145
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
20 |
#include "object.h" |
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
21 |
#include "log.h" |
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
22 |
#include "assert.h" |
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
23 |
#include "abort.h" |
4147
5d8530130930
rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents:
4145
diff
changeset
|
24 |
#include "names.h" |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
25 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
26 |
namespace ns3 { |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
27 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
28 |
NS_LOG_COMPONENT_DEFINE ("Names"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
29 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
30 |
class NameNode |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
31 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
32 |
public: |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
33 |
NameNode (); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
34 |
NameNode (const NameNode &nameNode); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
35 |
NameNode (NameNode *parent, std::string name, Ptr<Object> object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
36 |
NameNode &operator = (const NameNode &rhs); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
37 |
|
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6821
diff
changeset
|
38 |
~NameNode (); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
39 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
40 |
NameNode *m_parent; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
41 |
std::string m_name; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
42 |
Ptr<Object> m_object; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
43 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
44 |
std::map<std::string, NameNode *> m_nameMap; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
45 |
}; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
46 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
47 |
NameNode::NameNode () |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
48 |
: m_parent (0), m_name (""), m_object (0) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
49 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
50 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
51 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
52 |
NameNode::NameNode (const NameNode &nameNode) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
53 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
54 |
m_parent = nameNode.m_parent; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
55 |
m_name = nameNode.m_name; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
56 |
m_object = nameNode.m_object; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
57 |
m_nameMap = nameNode.m_nameMap; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
58 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
59 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
60 |
NameNode & |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
61 |
NameNode::operator = (const NameNode &rhs) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
62 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
63 |
m_parent = rhs.m_parent; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
64 |
m_name = rhs.m_name; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
65 |
m_object = rhs.m_object; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
66 |
m_nameMap = rhs.m_nameMap; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
67 |
return *this; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
68 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
69 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
70 |
NameNode::NameNode (NameNode *parent, std::string name, Ptr<Object> object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
71 |
: m_parent (parent), m_name (name), m_object (object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
72 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
73 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
74 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
75 |
NameNode::~NameNode () |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
76 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
77 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
78 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
79 |
class NamesPriv |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
80 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
81 |
public: |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
82 |
NamesPriv (); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
83 |
~NamesPriv (); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
84 |
|
4481 | 85 |
bool Add (std::string name, Ptr<Object> object); |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
86 |
bool Add (std::string path, std::string name, Ptr<Object> object); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
87 |
bool Add (Ptr<Object> context, std::string name, Ptr<Object> object); |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
88 |
|
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
89 |
bool Rename (std::string oldpath, std::string newname); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
90 |
bool Rename (std::string path, std::string oldname, std::string newname); |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
91 |
bool Rename (Ptr<Object> context, std::string oldname, std::string newname); |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
92 |
|
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
93 |
std::string FindName (Ptr<Object> object); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
94 |
std::string FindPath (Ptr<Object> object); |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
95 |
|
5277 | 96 |
void Clear (void); |
97 |
||
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
98 |
Ptr<Object> Find (std::string name); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
99 |
Ptr<Object> Find (std::string path, std::string name); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
100 |
Ptr<Object> Find (Ptr<Object> context, std::string name); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
101 |
|
5276
7ec4f2d74fef
get rid of names silly singleton and rescan
Craig Dowell <craigdo@ee.washington.edu>
parents:
5253
diff
changeset
|
102 |
private: |
7ec4f2d74fef
get rid of names silly singleton and rescan
Craig Dowell <craigdo@ee.washington.edu>
parents:
5253
diff
changeset
|
103 |
friend class Names; |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
104 |
static NamesPriv *Get (void); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
105 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
106 |
NameNode *IsNamed (Ptr<Object>); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
107 |
bool IsDuplicateName (NameNode *node, std::string name); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
108 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
109 |
NameNode m_root; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
110 |
std::map<Ptr<Object>, NameNode *> m_objectMap; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
111 |
}; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
112 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
113 |
NamesPriv * |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
114 |
NamesPriv::Get (void) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
115 |
{ |
5276
7ec4f2d74fef
get rid of names silly singleton and rescan
Craig Dowell <craigdo@ee.washington.edu>
parents:
5253
diff
changeset
|
116 |
static NamesPriv namesPriv; |
7ec4f2d74fef
get rid of names silly singleton and rescan
Craig Dowell <craigdo@ee.washington.edu>
parents:
5253
diff
changeset
|
117 |
return &namesPriv; |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
118 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
119 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
120 |
NamesPriv::NamesPriv () |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
121 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
122 |
NS_LOG_FUNCTION_NOARGS (); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
123 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
124 |
m_root.m_parent = 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
125 |
m_root.m_name = "Names"; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
126 |
m_root.m_object = 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
127 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
128 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
129 |
NamesPriv::~NamesPriv () |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
130 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
131 |
NS_LOG_FUNCTION_NOARGS (); |
5277 | 132 |
Clear (); |
5278
ef65dbb51385
fix name service unit test
Craig Dowell <craigdo@ee.washington.edu>
parents:
5277
diff
changeset
|
133 |
m_root.m_name = ""; |
5277 | 134 |
} |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
135 |
|
5277 | 136 |
void |
137 |
NamesPriv::Clear (void) |
|
138 |
{ |
|
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
139 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
140 |
// Every name is associated with an object in the object map, so freeing the |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
141 |
// NameNodes in this map will free all of the memory allocated for the NameNodes |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
142 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
143 |
for (std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.begin (); i != m_objectMap.end (); ++i) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
144 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
145 |
delete i->second; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
146 |
i->second = 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
147 |
} |
4145
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
148 |
|
5277 | 149 |
m_objectMap.clear (); |
150 |
||
4145
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
151 |
m_root.m_parent = 0; |
5278
ef65dbb51385
fix name service unit test
Craig Dowell <craigdo@ee.washington.edu>
parents:
5277
diff
changeset
|
152 |
m_root.m_name = "Names"; |
4145
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
153 |
m_root.m_object = 0; |
5277 | 154 |
m_root.m_nameMap.clear (); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
155 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
156 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
157 |
bool |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
158 |
NamesPriv::Add (std::string name, Ptr<Object> object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
159 |
{ |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
160 |
NS_LOG_FUNCTION (name << object); |
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
161 |
// |
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
162 |
// This is the simple, easy to use version of Add, so we want it to be flexible. |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
163 |
// We don't want to force a user to always type the fully qualified namespace |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
164 |
// name, so we allow the namespace name to be omitted. For example, calling |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
165 |
// Add ("Client/ath0", obj) should result in exactly the same behavior as |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
166 |
// Add ("/Names/Client/ath0", obj). Calling Add ("Client", obj) should have |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
167 |
// the same effect as Add ("Names/Client", obj) |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
168 |
// |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
169 |
// The first thing to do, then, is to "canonicalize" the input string to always |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
170 |
// be a fully qualified name. |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
171 |
// |
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
172 |
// If we are given a name that begins with "/Names/" we assume that this is a |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
173 |
// fully qualified path name to the object we want to create. We split the name |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
174 |
// into a path string and and a final segment (name) and then call the "Real" Add. |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
175 |
// |
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
176 |
std::string namespaceName = "/Names"; |
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
177 |
std::string::size_type offset = name.find (namespaceName); |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
178 |
if (offset != 0) |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
179 |
{ |
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
180 |
// |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6821
diff
changeset
|
181 |
// This must be a name that has the "/Names" namespace prefix omitted. |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
182 |
// Do some reasonableness checking on the rest of the name. |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
183 |
// |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
184 |
offset = name.find ("/"); |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
185 |
if (offset == 0) |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
186 |
{ |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
187 |
NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\""); |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
188 |
return false; |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
189 |
} |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
190 |
|
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
191 |
name = "/Names/" + name; |
4141
3f7f08d9daad
make simple version of Names:Add even simpler. Use that in examples/names.cc
Craig Dowell <craigdo@ee.washington.edu>
parents:
4139
diff
changeset
|
192 |
} |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6821
diff
changeset
|
193 |
|
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
194 |
// |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
195 |
// There must now be a fully qualified path in the string. All fully |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
196 |
// qualified names begin with "/Names". We have to split off the final |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
197 |
// segment which will become the name of the object. A '/' that |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
198 |
// separates the path from the final segment had better be there since |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
199 |
// we just made sure that at least the namespace name was there. |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
200 |
// |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
201 |
std::string::size_type i = name.rfind ("/"); |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
202 |
NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error. Can't find '/' in name"); |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
203 |
|
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
204 |
// |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
205 |
// The slash we found cannot be the slash at the start of the namespaceName. |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
206 |
// This would indicate there is no name in the path at all. It can be |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
207 |
// any other index. |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
208 |
// |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
209 |
NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a name in the path string"); |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
210 |
|
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
211 |
// |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
212 |
// We now know where the path string starts and ends, and where the |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
213 |
// name starts and ends. All we have to do is to call our available |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
214 |
// function for adding a name under a path string. |
4151
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
215 |
// |
682a4cae7a5f
Testmeister Tom found a bug in Names::Add for his shortcut semantics
Craig Dowell <craigdo@ee.washington.edu>
parents:
4149
diff
changeset
|
216 |
return Add (name.substr (0, i), name.substr (i + 1), object); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
217 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
218 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
219 |
bool |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
220 |
NamesPriv::Add (std::string path, std::string name, Ptr<Object> object) |
4148
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
221 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
222 |
if (path == "/Names") |
4148
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
223 |
{ |
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
224 |
return Add (Ptr<Object> (0, false), name, object); |
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
225 |
} |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
226 |
return Add (Find (path), name, object); |
4148
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
227 |
} |
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
228 |
|
7f1a5bd869e5
move a function definition in names.cc for a little more clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4147
diff
changeset
|
229 |
bool |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
230 |
NamesPriv::Add (Ptr<Object> context, std::string name, Ptr<Object> object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
231 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
232 |
NS_LOG_FUNCTION (context << name << object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
233 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
234 |
if (IsNamed (object)) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
235 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
236 |
NS_LOG_LOGIC ("Object is already named"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
237 |
return false; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
238 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
239 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
240 |
NameNode *node = 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
241 |
if (context) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
242 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
243 |
node = IsNamed (context); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
244 |
NS_ASSERT_MSG (node, "NamesPriv::Name(): context must point to a previously named node"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
245 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
246 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
247 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
248 |
node = &m_root; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
249 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
250 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
251 |
if (IsDuplicateName (node, name)) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
252 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
253 |
NS_LOG_LOGIC ("Name is already taken"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
254 |
return false; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
255 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
256 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
257 |
NameNode *newNode = new NameNode(node, name, object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
258 |
node->m_nameMap[name] = newNode; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
259 |
m_objectMap[object] = newNode; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
260 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
261 |
return true; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
262 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
263 |
|
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
264 |
bool |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
265 |
NamesPriv::Rename (std::string oldpath, std::string newname) |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
266 |
{ |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
267 |
NS_LOG_FUNCTION (oldpath << newname); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
268 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
269 |
// This is the simple, easy to use version of Rename, so we want it to be |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
270 |
// flexible. We don't want to force a user to always type the fully |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
271 |
// qualified namespace name, so we allow the namespace name to be omitted. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
272 |
// For example, calling Rename ("Client/ath0", "eth0") should result in |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
273 |
// exactly the same behavior as Rename ("/Names/Client/ath0", "eth0"). |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
274 |
// Calling Rename ("Client", "Router") should have the same effect as |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
275 |
// Rename ("Names/Client", "Router") |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
276 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
277 |
// The first thing to do, then, is to "canonicalize" the input string to always |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
278 |
// be a fully qualified path. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
279 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
280 |
// If we are given a name that begins with "/Names/" we assume that this is a |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
281 |
// fully qualified path to the object we want to change. We split the path into |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
282 |
// path string (cf directory) and and a final segment (cf filename) and then call |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
283 |
// the "Real" Rename. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
284 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
285 |
std::string namespaceName = "/Names"; |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
286 |
std::string::size_type offset = oldpath.find (namespaceName); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
287 |
if (offset != 0) |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
288 |
{ |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
289 |
// |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6821
diff
changeset
|
290 |
// This must be a name that has the "/Names" namespace prefix omitted. |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
291 |
// Do some reasonableness checking on the rest of the name. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
292 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
293 |
offset = oldpath.find ("/"); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
294 |
if (offset == 0) |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
295 |
{ |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
296 |
NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\""); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
297 |
return false; |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
298 |
} |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
299 |
|
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
300 |
oldpath = "/Names/" + oldpath; |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
301 |
} |
7169
358f71a624d8
core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6821
diff
changeset
|
302 |
|
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
303 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
304 |
// There must now be a fully qualified path in the oldpath string. All |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
305 |
// fully qualified names begin with "/Names". We have to split off the final |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
306 |
// segment which will become the name we want to rename. A '/' that |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
307 |
// separates the path from the final segment (name) had better be there since |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
308 |
// we just made sure that at least the namespace name was there. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
309 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
310 |
std::string::size_type i = oldpath.rfind ("/"); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
311 |
NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error. Can't find '/' in name"); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
312 |
|
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
313 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
314 |
// The slash we found cannot be the slash at the start of the namespaceName. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
315 |
// This would indicate there is no name in the path at all. It can be |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
316 |
// any other index. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
317 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
318 |
NS_ASSERT_MSG (i != 0, "NamesPriv::Add(): Can't find a name in the path string"); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
319 |
|
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
320 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
321 |
// We now know where the path part of the string starts and ends, and where the |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
322 |
// name part starts and ends. All we have to do is to call our available |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
323 |
// function for creating adding a name under a path string. |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
324 |
// |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
325 |
return Rename (oldpath.substr (0, i), oldpath.substr (i + 1), newname); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
326 |
} |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
327 |
|
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
328 |
bool |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
329 |
NamesPriv::Rename (std::string path, std::string oldname, std::string newname) |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
330 |
{ |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
331 |
if (path == "/Names") |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
332 |
{ |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
333 |
return Rename (Ptr<Object> (0, false), oldname, newname); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
334 |
} |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
335 |
return Rename (Find (path), oldname, newname); |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
336 |
} |
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
337 |
|
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
338 |
bool |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
339 |
NamesPriv::Rename (Ptr<Object> context, std::string oldname, std::string newname) |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
340 |
{ |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
341 |
NS_LOG_FUNCTION (context << oldname << newname); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
342 |
|
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
343 |
NameNode *node = 0; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
344 |
if (context) |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
345 |
{ |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
346 |
node = IsNamed (context); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
347 |
NS_ASSERT_MSG (node, "NamesPriv::Name(): context must point to a previously named node"); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
348 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
349 |
else |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
350 |
{ |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
351 |
node = &m_root; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
352 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
353 |
|
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
354 |
if (IsDuplicateName (node, newname)) |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
355 |
{ |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
356 |
NS_LOG_LOGIC ("New name is already taken"); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
357 |
return false; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
358 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
359 |
|
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
360 |
std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (oldname); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
361 |
if (i == node->m_nameMap.end ()) |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
362 |
{ |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
363 |
NS_LOG_LOGIC ("Old name does not exist in name map"); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
364 |
return false; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
365 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
366 |
else |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
367 |
{ |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
368 |
NS_LOG_LOGIC ("Old name exists in name map"); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
369 |
|
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
370 |
// |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
371 |
// The rename process consists of: |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
372 |
// 1. Geting the pointer to the name node from the map and remembering it; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
373 |
// 2. Removing the map entry corresponding to oldname from the map; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
374 |
// 3. Changing the name string in the name node; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
375 |
// 4. Adding the name node back in the map under the newname. |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
376 |
// |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
377 |
NameNode *changeNode = i->second; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
378 |
node->m_nameMap.erase (i); |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
379 |
changeNode->m_name = newname; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
380 |
node->m_nameMap[newname] = changeNode; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
381 |
return true; |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
382 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
383 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
384 |
|
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
385 |
std::string |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
386 |
NamesPriv::FindName (Ptr<Object> object) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
387 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
388 |
NS_LOG_FUNCTION (object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
389 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
390 |
std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
391 |
if (i == m_objectMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
392 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
393 |
NS_LOG_LOGIC ("Object does not exist in object map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
394 |
return ""; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
395 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
396 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
397 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
398 |
NS_LOG_LOGIC ("Object exists in object map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
399 |
return i->second->m_name; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
400 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
401 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
402 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
403 |
std::string |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
404 |
NamesPriv::FindPath (Ptr<Object> object) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
405 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
406 |
NS_LOG_FUNCTION (object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
407 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
408 |
std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
409 |
if (i == m_objectMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
410 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
411 |
NS_LOG_LOGIC ("Object does not exist in object map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
412 |
return ""; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
413 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
414 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
415 |
NameNode *p = i->second; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
416 |
NS_ASSERT_MSG (p, "NamesPriv::FindFullName(): Internal error: Invalid NameNode pointer from map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
417 |
|
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
418 |
std::string path; |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
419 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
420 |
do |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
421 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
422 |
path = "/" + p->m_name + path; |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
423 |
NS_LOG_LOGIC ("path is " << path); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
424 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
425 |
while ((p = p->m_parent) != 0); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
426 |
|
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
427 |
return path; |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
428 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
429 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
430 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
431 |
Ptr<Object> |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
432 |
NamesPriv::Find (std::string path) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
433 |
{ |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
434 |
// |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
435 |
// This is hooked in from simple, easy to use version of Find, so we want it |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
436 |
// to be flexible. |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
437 |
// |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
438 |
// If we are provided a path that doesn't begin with "/Names", we assume |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
439 |
// that the caller has simply given us a path starting with a name that |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
440 |
// is in the root namespace. This allows peole to omit the "/Names" prefix. |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
441 |
// and simply do a Find ("Client/eth0") instead of having to always do a |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
442 |
// Find ("/Names/Client/eth0"); |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
443 |
// |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
444 |
// So, if we are given a name that begins with "/Names/" the upshot is that we |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
445 |
// just remove that prefix and treat the rest of the string as starting with a |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
446 |
// name in the root namespace. |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
447 |
// |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
448 |
std::string namespaceName = "/Names/"; |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
449 |
std::string remaining; |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
450 |
|
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
451 |
std::string::size_type offset = path.find (namespaceName); |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
452 |
if (offset == 0) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
453 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
454 |
NS_LOG_LOGIC (path << " is a fully qualified name"); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
455 |
remaining = path.substr (namespaceName.size ()); |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
456 |
} |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
457 |
else |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
458 |
{ |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
459 |
NS_LOG_LOGIC (path << " begins with a relative name"); |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
460 |
remaining = path; |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
461 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
462 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
463 |
NameNode *node = &m_root; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
464 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
465 |
// |
4149
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
466 |
// The string <remaining> is now composed entirely of path segments in the |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
467 |
// /Names name space and we have eaten the leading slash. e.g., |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
468 |
// remaining = "ClientNode/eth0" |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
469 |
// |
6a3dbc49cfa9
Alloc clients to omit /Names/ in Names::Find
Craig Dowell <craigdo@ee.washington.edu>
parents:
4148
diff
changeset
|
470 |
// The start of the search is always at the root of the name space. |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
471 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
472 |
for (;;) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
473 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
474 |
NS_LOG_LOGIC ("Looking for the object of name " << remaining); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
475 |
offset = remaining.find ("/"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
476 |
if (offset == std::string::npos) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
477 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
478 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
479 |
// There are no remaining slashes so this is the last segment of the |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
480 |
// specified name. We're done when we find it |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
481 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
482 |
std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (remaining); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
483 |
if (i == node->m_nameMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
484 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
485 |
NS_LOG_LOGIC ("Name does not exist in name map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
486 |
return 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
487 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
488 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
489 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
490 |
NS_LOG_LOGIC ("Name parsed, found object"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
491 |
return i->second->m_object; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
492 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
493 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
494 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
495 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
496 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
497 |
// There are more slashes so this is an intermediate segment of the |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
498 |
// specified name. We need to "recurse" when we find this segment. |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
499 |
// |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
500 |
offset = remaining.find ("/"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
501 |
std::string segment = remaining.substr(0, offset); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
502 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
503 |
std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (segment); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
504 |
if (i == node->m_nameMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
505 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
506 |
NS_LOG_LOGIC ("Name does not exist in name map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
507 |
return 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
508 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
509 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
510 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
511 |
node = i->second; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
512 |
remaining = remaining.substr (offset + 1); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
513 |
NS_LOG_LOGIC ("Intermediate segment parsed"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
514 |
continue; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
515 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
516 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
517 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
518 |
|
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
519 |
NS_ASSERT_MSG (node, "NamesPriv::Find(): Internal error: this can't happen"); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
520 |
return 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
521 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
522 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
523 |
Ptr<Object> |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
524 |
NamesPriv::Find (std::string path, std::string name) |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
525 |
{ |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
526 |
NS_LOG_FUNCTION (path << name); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
527 |
|
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
528 |
if (path == "/Names") |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
529 |
{ |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
530 |
return Find (Ptr<Object> (0, false), name); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
531 |
} |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
532 |
return Find (Find (path), name); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
533 |
} |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
534 |
|
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
535 |
Ptr<Object> |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
536 |
NamesPriv::Find (Ptr<Object> context, std::string name) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
537 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
538 |
NS_LOG_FUNCTION (context << name); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
539 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
540 |
NameNode *node = 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
541 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
542 |
if (context == 0) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
543 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
544 |
NS_LOG_LOGIC ("Zero context implies root NameNode"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
545 |
node = &m_root; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
546 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
547 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
548 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
549 |
node = IsNamed (context); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
550 |
if (node == 0) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
551 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
552 |
NS_LOG_LOGIC ("Context does not point to a previously named node"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
553 |
return 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
554 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
555 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
556 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
557 |
std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (name); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
558 |
if (i == node->m_nameMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
559 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
560 |
NS_LOG_LOGIC ("Name does not exist in name map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
561 |
return 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
562 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
563 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
564 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
565 |
NS_LOG_LOGIC ("Name exists in name map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
566 |
return i->second->m_object; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
567 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
568 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
569 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
570 |
NameNode * |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
571 |
NamesPriv::IsNamed (Ptr<Object> object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
572 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
573 |
NS_LOG_FUNCTION (object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
574 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
575 |
std::map<Ptr<Object>, NameNode *>::iterator i = m_objectMap.find (object); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
576 |
if (i == m_objectMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
577 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
578 |
NS_LOG_LOGIC ("Object does not exist in object map, returning NameNode 0"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
579 |
return 0; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
580 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
581 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
582 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
583 |
NS_LOG_LOGIC ("Object exists in object map, returning NameNode " << &i->second); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
584 |
return i->second; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
585 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
586 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
587 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
588 |
bool |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
589 |
NamesPriv::IsDuplicateName (NameNode *node, std::string name) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
590 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
591 |
NS_LOG_FUNCTION (node << name); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
592 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
593 |
std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (name); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
594 |
if (i == node->m_nameMap.end ()) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
595 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
596 |
NS_LOG_LOGIC ("Name does not exist in name map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
597 |
return false; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
598 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
599 |
else |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
600 |
{ |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
601 |
NS_LOG_LOGIC ("Name exists in name map"); |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
602 |
return true; |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
603 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
604 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
605 |
|
4145
bb930262e55c
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
Craig Dowell <craigdo@ee.washington.edu>
parents:
4141
diff
changeset
|
606 |
void |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
607 |
Names::Add (std::string name, Ptr<Object> object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
608 |
{ |
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
609 |
bool result = NamesPriv::Get ()->Add (name, object); |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
610 |
NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding name " << name); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
611 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
612 |
|
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
613 |
void |
4159
76a72bc63d06
a few tests, a little reorganization for clarity
Craig Dowell <craigdo@ee.washington.edu>
parents:
4158
diff
changeset
|
614 |
Names::Rename (std::string oldpath, std::string newname) |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
615 |
{ |
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
616 |
bool result = NamesPriv::Get ()->Rename (oldpath, newname); |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
617 |
NS_ABORT_MSG_UNLESS (result, "Names::Rename(): Error renaming " << oldpath << " to " << newname); |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
618 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
619 |
|
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
620 |
void |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
621 |
Names::Add (std::string path, std::string name, Ptr<Object> object) |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
622 |
{ |
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
623 |
bool result = NamesPriv::Get ()->Add (path, name, object); |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
624 |
NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding " << path << " " << name); |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
625 |
} |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
626 |
|
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
627 |
void |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
628 |
Names::Rename (std::string path, std::string oldname, std::string newname) |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
629 |
{ |
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
630 |
bool result = NamesPriv::Get ()->Rename (path, oldname, newname); |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
631 |
NS_ABORT_MSG_UNLESS (result, "Names::Rename (): Error renaming " << path << " " << oldname << " to " << newname); |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
632 |
} |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
633 |
|
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
634 |
void |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
635 |
Names::Add (Ptr<Object> context, std::string name, Ptr<Object> object) |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
636 |
{ |
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
637 |
bool result = NamesPriv::Get ()->Add (context, name, object); |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
638 |
NS_ABORT_MSG_UNLESS (result, "Names::Add(): Error adding name " << name << " under context " << &context); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
639 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
640 |
|
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
641 |
void |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
642 |
Names::Rename (Ptr<Object> context, std::string oldname, std::string newname) |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
643 |
{ |
4298
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
644 |
bool result = NamesPriv::Get ()->Rename (context, oldname, newname); |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
645 |
NS_ABORT_MSG_UNLESS (result, "Names::Rename (): Error renaming " << oldname << " to " << newname << " under context " << |
cc2db3e6bcae
Make Names API return void not bool, rescan for Python Bindings
Craig Dowell <craigdo@ee.washington.edu>
parents:
4161
diff
changeset
|
646 |
&context); |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
647 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
648 |
|
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
649 |
std::string |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
650 |
Names::FindName (Ptr<Object> object) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
651 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
652 |
return NamesPriv::Get ()->FindName (object); |
4153
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
653 |
} |
93bb91eae5cd
add a Rename function to the object name service to facilitate auto naming
Craig Dowell <craigdo@ee.washington.edu>
parents:
4151
diff
changeset
|
654 |
|
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
655 |
std::string |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
656 |
Names::FindPath (Ptr<Object> object) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
657 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
658 |
return NamesPriv::Get ()->FindPath (object); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
659 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
660 |
|
5277 | 661 |
void |
662 |
Names::Clear (void) |
|
663 |
{ |
|
664 |
return NamesPriv::Get ()->Clear (); |
|
665 |
} |
|
666 |
||
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
667 |
Ptr<Object> |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
668 |
Names::FindInternal (std::string name) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
669 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
670 |
return NamesPriv::Get ()->Find (name); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
671 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
672 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
673 |
Ptr<Object> |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
674 |
Names::FindInternal (std::string path, std::string name) |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
675 |
{ |
4158
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
676 |
return NamesPriv::Get ()->Find (path, name); |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
677 |
} |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
678 |
|
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
679 |
Ptr<Object> |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
680 |
Names::FindInternal (Ptr<Object> context, std::string name) |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
681 |
{ |
2b6dba4062e1
some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents:
4153
diff
changeset
|
682 |
return NamesPriv::Get ()->Find (context, name); |
4139
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
683 |
} |
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
684 |
|
d45e62c78504
add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff
changeset
|
685 |
} //namespace ns3 |