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