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