2 #include "ns3/object.h"
3 #include "ns3/pointer.h"
4 #include "ns3/object-vector.h"
5 #include "ns3/config.h"
7 #include "ns3/global-value.h"
8 #include "ns3/string.h"
9 #include "ns3/helper-module.h"
13 NS_LOG_COMPONENT_DEFINE ("Main");
16 PrintAttributes (TypeId tid, std::ostream &os)
18 os << "<ul>"<<std::endl;
19 for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
21 os << "<li><b>" << tid.GetAttributeName (j) << "</b>: "
22 << tid.GetAttributeHelp (j) << std::endl;
23 Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
24 os << " <ul>" << std::endl
25 << " <li>Set with class: \\ref " << checker->GetValueTypeName () << "</li>" << std::endl;
26 if (checker->HasUnderlyingTypeInformation ())
28 os << " <li>Underlying type: \\ref " << checker->GetUnderlyingTypeInformation () << "</li>" << std::endl;
30 uint32_t flags = tid.GetAttributeFlags (j);
31 Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
32 if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ())
34 Ptr<const AttributeValue> initial = tid.GetAttributeInitialValue (j);
35 os << " <li>Initial value: " << initial->SerializeToString (checker) << "</li>" << std::endl;
38 if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ())
42 if (flags & TypeId::ATTR_SET && accessor->HasSetter ())
46 if (flags & TypeId::ATTR_GET && accessor->HasGetter ())
50 os << "</li>" << std::endl;
51 os << " </ul> " << std::endl;
54 os << "</ul>" << std::endl;
58 PrintTraceSources (TypeId tid, std::ostream &os)
60 os << "<ul>"<<std::endl;
61 for (uint32_t i = 0; i < tid.GetTraceSourceN (); ++i)
63 os << "<li><b>" << tid.GetTraceSourceName (i) << "</b>: "
64 << tid.GetTraceSourceHelp (i)
66 os << "</li>" << std::endl;
68 os << "</ul>"<<std::endl;
72 class StaticInformation
75 void RecordAggregationInfo (std::string a, std::string b);
76 void Gather (TypeId tid);
77 void Print (void) const;
79 std::vector<std::string> Get (TypeId tid);
82 std::string GetCurrentPath (void) const;
83 void DoGather (TypeId tid);
84 void RecordOutput (TypeId tid);
85 bool HasAlreadyBeenProcessed (TypeId tid) const;
86 void find_and_replace (std::string &source, const std::string find, std::string replace );
87 std::vector<std::pair<TypeId,std::string> > m_output;
88 std::vector<std::string> m_currentPath;
89 std::vector<TypeId> m_alreadyProcessed;
90 std::vector<std::pair<TypeId,TypeId> > m_aggregates;
94 StaticInformation::RecordAggregationInfo (std::string a, std::string b)
96 m_aggregates.push_back (std::make_pair (TypeId::LookupByName (a), TypeId::LookupByName (b)));
100 StaticInformation::Print (void) const
102 for (std::vector<std::pair<TypeId,std::string> >::const_iterator i = m_output.begin (); i != m_output.end (); ++i)
104 std::pair<TypeId,std::string> item = *i;
105 std::cout << item.first.GetName () << " -> " << item.second << std::endl;
110 StaticInformation::GetCurrentPath (void) const
112 std::ostringstream oss;
113 for (std::vector<std::string>::const_iterator i = m_currentPath.begin (); i != m_currentPath.end (); ++i)
115 std::string item = *i;
122 StaticInformation::RecordOutput (TypeId tid)
124 m_output.push_back (std::make_pair (tid, GetCurrentPath ()));
128 StaticInformation::HasAlreadyBeenProcessed (TypeId tid) const
130 for (uint32_t i = 0; i < m_alreadyProcessed.size (); ++i)
132 if (m_alreadyProcessed[i] == tid)
140 std::vector<std::string>
141 StaticInformation::Get (TypeId tid)
143 std::vector<std::string> paths;
144 for (uint32_t i = 0; i < m_output.size (); ++i)
146 std::pair<TypeId,std::string> tmp = m_output[i];
147 if (tmp.first == tid)
149 paths.push_back (tmp.second);
156 StaticInformation::Gather (TypeId tid)
160 std::sort (m_output.begin (), m_output.end ());
161 m_output.erase (std::unique (m_output.begin (), m_output.end ()), m_output.end ());
165 StaticInformation::DoGather (TypeId tid)
167 NS_LOG_FUNCTION (this);
168 if (HasAlreadyBeenProcessed (tid))
173 for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
175 Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
176 const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
179 TypeId pointee = ptrChecker->GetPointeeTypeId ();
180 m_currentPath.push_back (tid.GetAttributeName (i));
181 m_alreadyProcessed.push_back (tid);
183 m_alreadyProcessed.pop_back ();
184 m_currentPath.pop_back ();
187 // attempt to cast to an object vector.
188 const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
189 if (vectorChecker != 0)
191 TypeId item = vectorChecker->GetItemTypeId ();
192 m_currentPath.push_back (tid.GetAttributeName (i) + "/[i]");
193 m_alreadyProcessed.push_back (tid);
195 m_alreadyProcessed.pop_back ();
196 m_currentPath.pop_back ();
200 for (uint32_t j = 0; j < TypeId::GetRegisteredN (); j++)
202 TypeId child = TypeId::GetRegistered (j);
203 if (child.IsChildOf (tid))
205 //please take a look at the following note for an explanation
206 std::string childName = "$%" + child.GetName ();
207 find_and_replace(childName,"::","::%");
208 m_currentPath.push_back (childName);
209 m_alreadyProcessed.push_back (tid);
211 m_alreadyProcessed.pop_back ();
212 m_currentPath.pop_back ();
215 for (uint32_t k = 0; k < m_aggregates.size (); ++k)
217 std::pair<TypeId,TypeId> tmp = m_aggregates[k];
218 if (tmp.first == tid || tmp.second == tid)
221 if (tmp.first == tid)
225 if (tmp.second == tid)
230 * Note: we insert a % in the path below to ensure that doxygen does not
231 * attempt to resolve the typeid names included in the string.
232 * if the name contains ::, using the % sign will remove that sign
233 * resulting for instance in $ns3MobilityModel instead of $ns3::MobilityModel
234 * hence the output must be in the form $%ns3::%MobilityModel in order to
235 * show correctly $ns3::MobilityModel
236 * We add at the beginning of the name $% and we replace all the :: in the
239 std::string name = "$%" + other.GetName ();
240 //finding and replacing :: by ::%
241 find_and_replace(name,"::","::%");
242 m_currentPath.push_back (name);
243 m_alreadyProcessed.push_back (tid);
245 m_alreadyProcessed.pop_back ();
246 m_currentPath.pop_back ();
252 StaticInformation::find_and_replace( std::string &source, const std::string find, std::string replace )
255 j = source.find (find);
256 while (j != std::string::npos )
258 source.replace (j, find.length (),replace);
259 j = source.find (find,j+1);
263 int main (int argc, char *argv[])
265 NodeContainer c; c.Create (1);
267 StaticInformation info;
268 info.RecordAggregationInfo ("ns3::Node", "ns3::TcpSocketFactory");
269 info.RecordAggregationInfo ("ns3::Node", "ns3::UdpSocketFactory");
270 info.RecordAggregationInfo ("ns3::Node", "ns3::PacketSocketFactory");
271 info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::RoutingProtocol");
272 info.RecordAggregationInfo ("ns3::Node", "ns3::MobilityModel");
273 info.RecordAggregationInfo ("ns3::Node", "ns3::Ipv4L3Protocol");
274 info.RecordAggregationInfo ("ns3::Node", "ns3::ArpL3Protocol");
276 for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i)
278 Ptr<Object> object = Config::GetRootNamespaceObject (i);
279 info.Gather (object->GetInstanceTypeId ());
282 for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
284 std::cout << "/*!" << std::endl;
285 TypeId tid = TypeId::GetRegistered (i);
286 if (tid.MustHideFromDocumentation ())
290 std::cout << "\\fn static TypeId " << tid.GetName () << "::GetTypeId (void)" << std::endl;
291 std::cout << "\\brief This method returns the TypeId associated to \\ref " << tid.GetName ()
292 << std::endl << std::endl;
293 std::vector<std::string> paths = info.Get (tid);
296 std::cout << "This object is accessible through the following paths with Config::Set and Config::Connect:"
298 std::cout << "<ul>" << std::endl;
299 for (uint32_t k = 0; k < paths.size (); ++k)
301 std::string path = paths[k];
302 std::cout << "<li>" << path << "</li>" << std::endl;
304 std::cout << "</ul>" << std::endl;
306 if (tid.GetAttributeN () == 0)
308 std::cout << "No Attributes defined for this type.<br>" << std::endl;
312 std::cout << "Attributes defined for this type:<br>" << std::endl;
313 PrintAttributes (tid, std::cout);
316 TypeId tmp = tid.GetParent ();
317 while (tmp.GetParent () != tmp)
319 if (tmp.GetAttributeN () != 0)
321 std::cout << "Attributes defined in parent class " << tmp.GetName () << ":<br>" << std::endl;
322 PrintAttributes (tmp, std::cout);
324 tmp = tmp.GetParent ();
327 if (tid.GetTraceSourceN () == 0)
329 std::cout << "No TraceSources defined for this type.<br>" << std::endl;
333 std::cout << "TraceSources defined for this type:<br>" << std::endl;
334 PrintTraceSources (tid, std::cout);
337 TypeId tmp = tid.GetParent ();
338 while (tmp.GetParent () != tmp)
340 if (tmp.GetTraceSourceN () != 0)
342 std::cout << "TraceSources defined in parent class " << tmp.GetName () << ":<br>" << std::endl;
343 PrintTraceSources (tmp, std::cout);
345 tmp = tmp.GetParent ();
348 std::cout << "*/" << std::endl;
352 std::cout << "/*!" << std::endl
353 << "\\ingroup core" << std::endl
354 << "\\defgroup TraceSourceList The list of all trace sources." << std::endl;
355 for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
357 TypeId tid = TypeId::GetRegistered (i);
358 if (tid.GetTraceSourceN () == 0 ||
359 tid.MustHideFromDocumentation ())
363 std::cout << "<b>" << tid.GetName () << "</b><br>" << std::endl
364 << "<ul>" << std::endl;
365 for (uint32_t j = 0; j < tid.GetTraceSourceN (); ++j)
367 std::cout << "<li>" << tid.GetTraceSourceName (j) << ": " << tid.GetTraceSourceHelp (j) << "</li>" << std::endl;
369 std::cout << "</ul>" << std::endl;
371 std::cout << "*/" << std::endl;
374 std::cout << "/*!" << std::endl
375 << "\\ingroup core" << std::endl
376 << "\\defgroup AttributeList The list of all attributes." << std::endl;
377 for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
379 TypeId tid = TypeId::GetRegistered (i);
380 if (tid.GetAttributeN () == 0 ||
381 tid.MustHideFromDocumentation ())
385 std::cout << "<b>" << tid.GetName () << "</b><br>" << std::endl
386 << "<ul>" << std::endl;
387 for (uint32_t j = 0; j < tid.GetAttributeN (); ++j)
389 std::cout << "<li>" << tid.GetAttributeName (j) << ": " << tid.GetAttributeHelp (j) << "</li>" << std::endl;
391 std::cout << "</ul>" << std::endl;
393 std::cout << "*/" << std::endl;
397 std::cout << "/*!" << std::endl
398 << "\\ingroup core" << std::endl
399 << "\\defgroup GlobalValueList The list of all global values." << std::endl
400 << "<ul>" << std::endl;
401 for (GlobalValue::Iterator i = GlobalValue::Begin (); i != GlobalValue::End (); ++i)
404 (*i)->GetValue (val);
405 std::cout << " <li><b>\\anchor GlobalValue" << (*i)->GetName () << " " << (*i)->GetName () << "</b>: " << (*i)->GetHelp () << "(" << val.Get () << ")</li>" << std::endl;
407 std::cout << "</ul>" << std::endl
408 << "*/" << std::endl;