utils/print-introspected-doxygen.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 14 Apr 2008 16:19:17 -0700
changeset 2964 4e8cb1577144
parent 2951 2a3db8645225
child 2969 9d05d2a95dfa
permissions -rw-r--r--
generate list of trace sources and attributes in separate dox groups.
mathieu@2602
     1
#include <iostream>
mathieu@2602
     2
#include "ns3/object.h"
mathieu@2944
     3
#include "ns3/pointer.h"
mathieu@2944
     4
#include "ns3/object-vector.h"
mathieu@2944
     5
#include "ns3/config.h"
mathieu@2944
     6
#include "ns3/log.h"
mathieu@2944
     7
#include "ns3/helper-module.h"
mathieu@1368
     8
mathieu@1368
     9
using namespace ns3;
mathieu@1368
    10
mathieu@2944
    11
NS_LOG_COMPONENT_DEFINE ("Main");
mathieu@2944
    12
mathieu@2602
    13
void
mathieu@2602
    14
PrintAttributes (TypeId tid, std::ostream &os)
mathieu@2602
    15
{
mathieu@2602
    16
  os << "<ul>"<<std::endl;
mathieu@2693
    17
  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
mathieu@2602
    18
    {
mathieu@2602
    19
      os << "<li><b>" << tid.GetAttributeName (j) << "</b>: "
mathieu@2602
    20
		<< tid.GetAttributeHelp (j) << std::endl;
mathieu@2602
    21
      Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (j);
mathieu@2931
    22
      os << "  <ul>" << std::endl << "    <li>Type: \\ref " <<  checker->GetType ();
mathieu@2602
    23
      if (checker->HasTypeConstraints ())
mathieu@2602
    24
	{
mathieu@2602
    25
	  os << " -> " << checker->GetTypeConstraints ();
mathieu@2602
    26
	}
mathieu@2602
    27
      os << "</li>" << std::endl;
mathieu@2602
    28
      uint32_t flags = tid.GetAttributeFlags (j);
mathieu@2951
    29
      Ptr<const AttributeAccessor> accessor = tid.GetAttributeAccessor (j);
mathieu@2944
    30
      os << "    <li>Flags: ";
mathieu@2951
    31
      if (flags & TypeId::ATTR_SET && accessor->HasSetter ())
mathieu@2602
    32
	{
mathieu@2602
    33
	  os << "write ";
mathieu@2602
    34
	}
mathieu@2951
    35
      if (flags & TypeId::ATTR_GET && accessor->HasGetter ())
mathieu@2602
    36
	{
mathieu@2602
    37
	  os << "read ";
mathieu@2602
    38
	}
mathieu@2951
    39
      if (flags & TypeId::ATTR_CONSTRUCT && accessor->HasSetter ())
mathieu@2602
    40
	{
mathieu@2602
    41
	  os << "construct ";
mathieu@2602
    42
	}
mathieu@2944
    43
      os << "</li>" << std::endl;
mathieu@2602
    44
      os << "  </ul> " << std::endl;
mathieu@2602
    45
      
mathieu@2602
    46
    }
mathieu@2602
    47
  os << "</ul>" << std::endl;
mathieu@2602
    48
}
mathieu@1399
    49
mathieu@2945
    50
void
mathieu@2945
    51
PrintTraceSources (TypeId tid, std::ostream &os)
mathieu@2945
    52
{
mathieu@2945
    53
  os << "<ul>"<<std::endl;
mathieu@2945
    54
  for (uint32_t i = 0; i < tid.GetTraceSourceN (); ++i)
mathieu@2945
    55
    {
mathieu@2945
    56
      os << "<li><b>" << tid.GetTraceSourceName (i) << "</b>: "
mathieu@2945
    57
	 << tid.GetTraceSourceHelp (i)
mathieu@2945
    58
	 << std::endl;
mathieu@2945
    59
      os << "</li>" << std::endl;
mathieu@2945
    60
    }
mathieu@2945
    61
  os << "</ul>"<<std::endl;
mathieu@2945
    62
}
mathieu@2945
    63
mathieu@2945
    64
mathieu@2944
    65
class StaticInformation
mathieu@2944
    66
{
mathieu@2944
    67
public:
mathieu@2944
    68
  void RecordAggregationInfo (std::string a, std::string b);
mathieu@2944
    69
  void Gather (TypeId tid);
mathieu@2944
    70
  void Print (void) const;
mathieu@2944
    71
mathieu@2944
    72
  std::vector<std::string> Get (TypeId tid);
mathieu@2944
    73
mathieu@2944
    74
private:
mathieu@2944
    75
  std::string GetCurrentPath (void) const;
mathieu@2944
    76
  void DoGather (TypeId tid);
mathieu@2944
    77
  void RecordOutput (TypeId tid);
mathieu@2944
    78
  bool HasAlreadyBeenProcessed (TypeId tid) const;
mathieu@2944
    79
  std::vector<std::pair<TypeId,std::string> > m_output;
mathieu@2944
    80
  std::vector<std::string> m_currentPath;
mathieu@2944
    81
  std::vector<TypeId> m_alreadyProcessed;
mathieu@2944
    82
  std::vector<std::pair<TypeId,TypeId> > m_aggregates;
mathieu@2944
    83
};
mathieu@2944
    84
mathieu@2944
    85
void 
mathieu@2944
    86
StaticInformation::RecordAggregationInfo (std::string a, std::string b)
mathieu@2944
    87
{
mathieu@2944
    88
  m_aggregates.push_back (std::make_pair (TypeId::LookupByName (a), TypeId::LookupByName (b)));
mathieu@2944
    89
}
mathieu@2944
    90
mathieu@2944
    91
void 
mathieu@2944
    92
StaticInformation::Print (void) const
mathieu@2944
    93
{
mathieu@2944
    94
  for (std::vector<std::pair<TypeId,std::string> >::const_iterator i = m_output.begin (); i != m_output.end (); ++i)
mathieu@2944
    95
    {
mathieu@2944
    96
      std::pair<TypeId,std::string> item = *i;
mathieu@2944
    97
      std::cout << item.first.GetName () << " -> " << item.second << std::endl;
mathieu@2944
    98
    }
mathieu@2944
    99
}
mathieu@2944
   100
mathieu@2944
   101
std::string
mathieu@2944
   102
StaticInformation::GetCurrentPath (void) const
mathieu@2944
   103
{
mathieu@2944
   104
  std::ostringstream oss;
mathieu@2944
   105
  for (std::vector<std::string>::const_iterator i = m_currentPath.begin (); i != m_currentPath.end (); ++i)
mathieu@2944
   106
    {
mathieu@2944
   107
      std::string item = *i;
mathieu@2944
   108
      oss << "/" << item;
mathieu@2944
   109
    }
mathieu@2944
   110
  return oss.str ();
mathieu@2944
   111
}
mathieu@2944
   112
mathieu@2944
   113
void
mathieu@2944
   114
StaticInformation::RecordOutput (TypeId tid)
mathieu@2944
   115
{
mathieu@2944
   116
  m_output.push_back (std::make_pair (tid, GetCurrentPath ()));
mathieu@2944
   117
}
mathieu@2944
   118
mathieu@2944
   119
bool
mathieu@2944
   120
StaticInformation::HasAlreadyBeenProcessed (TypeId tid) const
mathieu@2944
   121
{
mathieu@2944
   122
  for (uint32_t i = 0; i < m_alreadyProcessed.size (); ++i)
mathieu@2944
   123
    {
mathieu@2944
   124
      if (m_alreadyProcessed[i] == tid)
mathieu@2944
   125
	{
mathieu@2944
   126
	  return true;
mathieu@2944
   127
	}
mathieu@2944
   128
    }
mathieu@2944
   129
  return false;
mathieu@2944
   130
}
mathieu@2944
   131
mathieu@2944
   132
std::vector<std::string> 
mathieu@2944
   133
StaticInformation::Get (TypeId tid)
mathieu@2944
   134
{
mathieu@2944
   135
  std::vector<std::string> paths;
mathieu@2944
   136
  for (uint32_t i = 0; i < m_output.size (); ++i)
mathieu@2944
   137
    {
mathieu@2944
   138
      std::pair<TypeId,std::string> tmp = m_output[i];
mathieu@2944
   139
      if (tmp.first == tid)
mathieu@2944
   140
	{
mathieu@2944
   141
	  paths.push_back (tmp.second);
mathieu@2944
   142
	}
mathieu@2944
   143
    }
mathieu@2944
   144
  return paths;
mathieu@2944
   145
}
mathieu@2944
   146
mathieu@2944
   147
void
mathieu@2944
   148
StaticInformation::Gather (TypeId tid)
mathieu@2944
   149
{
mathieu@2944
   150
  DoGather (tid);
mathieu@2944
   151
mathieu@2944
   152
  std::sort (m_output.begin (), m_output.end ());
mathieu@2944
   153
  m_output.erase (std::unique (m_output.begin (), m_output.end ()), m_output.end ());
mathieu@2944
   154
}
mathieu@2944
   155
mathieu@2944
   156
void 
mathieu@2944
   157
StaticInformation::DoGather (TypeId tid)
mathieu@2944
   158
{
mathieu@2944
   159
  NS_LOG_FUNCTION;
mathieu@2944
   160
  if (HasAlreadyBeenProcessed (tid))
mathieu@2944
   161
    {
mathieu@2944
   162
      return;
mathieu@2944
   163
    }
mathieu@2944
   164
  RecordOutput (tid);
mathieu@2944
   165
  for (uint32_t i = 0; i < tid.GetAttributeN (); ++i)
mathieu@2944
   166
    {
mathieu@2944
   167
      Ptr<const AttributeChecker> checker = tid.GetAttributeChecker (i);
mathieu@2944
   168
      const PointerChecker *ptrChecker = dynamic_cast<const PointerChecker *> (PeekPointer (checker));
mathieu@2944
   169
      if (ptrChecker != 0)
mathieu@2944
   170
	{
mathieu@2944
   171
	  TypeId pointee = ptrChecker->GetPointeeTypeId ();
mathieu@2944
   172
	  m_currentPath.push_back (tid.GetAttributeName (i));
mathieu@2944
   173
	  m_alreadyProcessed.push_back (tid);
mathieu@2944
   174
	  DoGather (pointee);
mathieu@2944
   175
	  m_alreadyProcessed.pop_back ();
mathieu@2944
   176
	  m_currentPath.pop_back ();
mathieu@2944
   177
	  continue;
mathieu@2944
   178
	}
mathieu@2944
   179
      // attempt to cast to an object vector.
mathieu@2944
   180
      const ObjectVectorChecker *vectorChecker = dynamic_cast<const ObjectVectorChecker *> (PeekPointer (checker));
mathieu@2944
   181
      if (vectorChecker != 0)
mathieu@2944
   182
	{
mathieu@2944
   183
	  TypeId item = vectorChecker->GetItemTypeId ();
mathieu@2944
   184
	  m_currentPath.push_back (tid.GetAttributeName (i) + "/[i]");
mathieu@2944
   185
	  m_alreadyProcessed.push_back (tid);
mathieu@2944
   186
	  DoGather (item);
mathieu@2944
   187
	  m_alreadyProcessed.pop_back ();
mathieu@2944
   188
	  m_currentPath.pop_back ();
mathieu@2944
   189
	  continue;
mathieu@2944
   190
	}
mathieu@2944
   191
    }
mathieu@2944
   192
  for (uint32_t j = 0; j < TypeId::GetRegisteredN (); j++)
mathieu@2944
   193
    {
mathieu@2944
   194
      TypeId child = TypeId::GetRegistered (j);
mathieu@2944
   195
      if (child.IsChildOf (tid))
mathieu@2944
   196
	{
mathieu@2944
   197
	  m_currentPath.push_back ("$%" + child.GetName ());
mathieu@2944
   198
	  m_alreadyProcessed.push_back (tid);
mathieu@2944
   199
	  DoGather (child);
mathieu@2944
   200
	  m_alreadyProcessed.pop_back ();
mathieu@2944
   201
	  m_currentPath.pop_back ();
mathieu@2944
   202
	}
mathieu@2944
   203
    }
mathieu@2944
   204
  for (uint32_t k = 0; k < m_aggregates.size (); ++k)
mathieu@2944
   205
    {
mathieu@2944
   206
      std::pair<TypeId,TypeId> tmp = m_aggregates[k];
mathieu@2944
   207
      if (tmp.first == tid || tmp.second == tid)
mathieu@2944
   208
	{
mathieu@2944
   209
	  TypeId other;
mathieu@2944
   210
	  if (tmp.first == tid)
mathieu@2944
   211
	    {
mathieu@2944
   212
	      other = tmp.second;
mathieu@2944
   213
	    }
mathieu@2944
   214
	  if (tmp.second == tid)
mathieu@2944
   215
	    {
mathieu@2944
   216
	      other = tmp.first;
mathieu@2944
   217
	    }
mathieu@2944
   218
	  // Note: we insert a % in the path below to ensure that doxygen does not
mathieu@2944
   219
	  // attempt to resolve the typeid names included in the string.
mathieu@2944
   220
	  m_currentPath.push_back ("$%" + other.GetName ());
mathieu@2944
   221
	  m_alreadyProcessed.push_back (tid);
mathieu@2944
   222
	  DoGather (other);
mathieu@2944
   223
	  m_alreadyProcessed.pop_back ();
mathieu@2944
   224
	  m_currentPath.pop_back ();	  
mathieu@2944
   225
	}
mathieu@2944
   226
    }
mathieu@2944
   227
}
mathieu@1399
   228
mathieu@1368
   229
int main (int argc, char *argv[])
mathieu@1368
   230
{
mathieu@2944
   231
  NodeContainer c; c.Create (1);
mathieu@2944
   232
mathieu@2944
   233
  StaticInformation info;
mathieu@2944
   234
  info.RecordAggregationInfo ("ns3::Node", "ns3::Tcp");
mathieu@2944
   235
  info.RecordAggregationInfo ("ns3::Node", "ns3::Udp");
mathieu@2944
   236
  info.RecordAggregationInfo ("ns3::Node", "ns3::PacketSocketFactory");
mathieu@2944
   237
  info.RecordAggregationInfo ("ns3::Node", "ns3::olsr::Agent");
mathieu@2944
   238
  info.RecordAggregationInfo ("ns3::Node", "ns3::MobilityModel");
mathieu@2944
   239
  info.RecordAggregationInfo ("ns3::Node", "ns3::Ipv4L4Demux");
mathieu@2944
   240
  info.RecordAggregationInfo ("ns3::Node", "ns3::Ipv4L3Protocol");
mathieu@2944
   241
  info.RecordAggregationInfo ("ns3::Node", "ns3::ArpL3Protocol");
mathieu@2944
   242
mathieu@2944
   243
  for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN (); ++i)
mathieu@2944
   244
    {
mathieu@2944
   245
      Ptr<Object> object = Config::GetRootNamespaceObject (i);
mathieu@2944
   246
      info.Gather (object->GetInstanceTypeId ());
mathieu@2944
   247
    }
mathieu@1368
   248
mathieu@2602
   249
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
mathieu@2602
   250
    {
mathieu@2602
   251
      std::cout << "/*!" << std::endl;
mathieu@2602
   252
      TypeId tid = TypeId::GetRegistered (i);
mathieu@2602
   253
      if (tid.MustHideFromDocumentation ())
mathieu@2602
   254
	{
mathieu@2602
   255
	  continue;
mathieu@2602
   256
	}
mathieu@2602
   257
      std::cout << "\\fn static TypeId " << tid.GetName () << "::GetTypeId (void)" << std::endl;
mathieu@2944
   258
      std::cout << "\\brief This method returns the TypeId associated to \\ref " << tid.GetName () 
mathieu@2944
   259
		<< std::endl << std::endl;
mathieu@2944
   260
      std::vector<std::string> paths = info.Get (tid);
mathieu@2944
   261
      if (!paths.empty ())
mathieu@2944
   262
	{
mathieu@2944
   263
	  std::cout << "This object is accessible through the following paths with Config::Set and Config::Connect:" 
mathieu@2944
   264
		    << std::endl;
mathieu@2944
   265
	  std::cout << "<ul>" << std::endl;
mathieu@2944
   266
	  for (uint32_t k = 0; k < paths.size (); ++k)
mathieu@2944
   267
	    {
mathieu@2944
   268
	      std::string path = paths[k];
mathieu@2944
   269
	      std::cout << "<li>" << path << "</li>" << std::endl;
mathieu@2944
   270
	    }
mathieu@2944
   271
	  std::cout << "</ul>" << std::endl;
mathieu@2944
   272
	}
mathieu@2693
   273
      if (tid.GetAttributeN () == 0)
mathieu@2602
   274
	{
mathieu@2602
   275
	  std::cout << "No Attributes defined for this type." << std::endl;
mathieu@2602
   276
	}
mathieu@2602
   277
      else
mathieu@2602
   278
	{
mathieu@2602
   279
	  std::cout << "Attributes defined for this type:" << std::endl;
mathieu@2602
   280
	  PrintAttributes (tid, std::cout);
mathieu@2602
   281
	}
mathieu@2945
   282
      {
mathieu@2945
   283
	TypeId tmp = tid.GetParent ();
mathieu@2945
   284
	while (tmp.GetParent () != tmp)
mathieu@2945
   285
	  {
mathieu@2945
   286
	    if (tmp.GetAttributeN () != 0)
mathieu@2945
   287
	      {
mathieu@2945
   288
		std::cout << "Attributes defined in parent class " << tmp.GetName () << ":<br>" << std::endl;
mathieu@2945
   289
		PrintAttributes (tmp, std::cout);
mathieu@2945
   290
	      }
mathieu@2945
   291
	    tmp = tmp.GetParent ();
mathieu@2945
   292
	  }
mathieu@2945
   293
      }
mathieu@2945
   294
      if (tid.GetTraceSourceN () == 0)
mathieu@2602
   295
	{
mathieu@2945
   296
	  std::cout << "No TraceSources defined for this type." << std::endl;
mathieu@2602
   297
	}
mathieu@2945
   298
      else
mathieu@2602
   299
	{
mathieu@2945
   300
	  std::cout << "TraceSources defined for this type:" << std::endl;
mathieu@2945
   301
	  PrintTraceSources (tid, std::cout);
mathieu@2602
   302
	}
mathieu@2945
   303
      {
mathieu@2945
   304
	TypeId tmp = tid.GetParent ();
mathieu@2945
   305
	while (tmp.GetParent () != tmp)
mathieu@2945
   306
	  {
mathieu@2945
   307
	    if (tmp.GetTraceSourceN () != 0)
mathieu@2945
   308
	      {
mathieu@2945
   309
		std::cout << "TraceSources defined in parent class " << tmp.GetName () << ":<br>" << std::endl;
mathieu@2945
   310
		PrintTraceSources (tmp, std::cout);
mathieu@2945
   311
	      }
mathieu@2945
   312
	    tmp = tmp.GetParent ();
mathieu@2945
   313
	  }
mathieu@2945
   314
      }
mathieu@2602
   315
      std::cout << "*/" << std::endl;
mathieu@2602
   316
    }
mathieu@1368
   317
mathieu@1853
   318
mathieu@2964
   319
  std::cout << "/*!" << std::endl
mathieu@2964
   320
	    << "\\ingroup core" << std::endl
mathieu@2964
   321
	    << "\\defgroup TraceSourceList The list of all trace sources." << std::endl;
mathieu@2964
   322
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
mathieu@2964
   323
    {
mathieu@2964
   324
      TypeId tid = TypeId::GetRegistered (i);
mathieu@2964
   325
      if (tid.GetTraceSourceN () == 0 ||
mathieu@2964
   326
	  tid.MustHideFromDocumentation ())
mathieu@2964
   327
	{
mathieu@2964
   328
	  continue;
mathieu@2964
   329
	}
mathieu@2964
   330
      std::cout << "<b>" << tid.GetName () << "</b><br>" << std::endl
mathieu@2964
   331
		<< "<ul>" << std::endl;
mathieu@2964
   332
      for (uint32_t j = 0; j < tid.GetTraceSourceN (); ++j)
mathieu@2964
   333
	{
mathieu@2964
   334
	  std::cout << "<li>" << tid.GetTraceSourceName (j) << ": " << tid.GetTraceSourceHelp (j) << "</li>" << std::endl;
mathieu@2964
   335
	}
mathieu@2964
   336
      std::cout << "</ul>" << std::endl;
mathieu@2964
   337
    }
mathieu@2964
   338
  std::cout << "*/" << std::endl;
mathieu@2964
   339
mathieu@2964
   340
mathieu@2964
   341
  std::cout << "/*!" << std::endl
mathieu@2964
   342
	    << "\\ingroup core" << std::endl
mathieu@2964
   343
	    << "\\defgroup AttributeList The list of all attributes." << std::endl;
mathieu@2964
   344
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
mathieu@2964
   345
    {
mathieu@2964
   346
      TypeId tid = TypeId::GetRegistered (i);
mathieu@2964
   347
      if (tid.GetAttributeN () == 0 ||
mathieu@2964
   348
	  tid.MustHideFromDocumentation ())
mathieu@2964
   349
	{
mathieu@2964
   350
	  continue;
mathieu@2964
   351
	}
mathieu@2964
   352
      std::cout << "<b>" << tid.GetName () << "</b><br>" << std::endl
mathieu@2964
   353
		<< "<ul>" << std::endl;
mathieu@2964
   354
      for (uint32_t j = 0; j < tid.GetAttributeN (); ++j)
mathieu@2964
   355
	{
mathieu@2964
   356
	  std::cout << "<li>" << tid.GetAttributeName (j) << ": " << tid.GetAttributeHelp (j) << "</li>" << std::endl;
mathieu@2964
   357
	}
mathieu@2964
   358
      std::cout << "</ul>" << std::endl;
mathieu@2964
   359
    }
mathieu@2964
   360
  std::cout << "*/" << std::endl;
mathieu@2964
   361
mathieu@2964
   362
mathieu@2964
   363
mathieu@1368
   364
  return 0;
mathieu@1368
   365
}