utils/print-introspected-doxygen.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 02 Mar 2008 21:57:28 +0100
changeset 2533 80cdc3eec057
parent 2502 50d0da37f02f
child 2540 4e9ba43f7b9e
permissions -rw-r--r--
do not use Queue::CreateDefault
     1 #include "ns3/internet-node.h"
     2 #include "ns3/ptr.h"
     3 #include "ns3/trace-resolver.h"
     4 #include "ns3/node-list.h"
     5 #include "ns3/point-to-point-net-device.h"
     6 #include "ns3/csma-net-device.h"
     7 #include "ns3/queue.h"
     8 #include "ns3/drop-tail-queue.h"
     9 #include "ns3/mobility-model-notifier.h"
    10 #include "ns3/default-value.h"
    11 #include "ns3/string.h"
    12 
    13 using namespace ns3;
    14 
    15 void
    16 PrintSimpleText (const TraceResolver::SourceCollection *sources, std::ostream &os)
    17 {
    18   for (TraceResolver::SourceCollection::Iterator i = sources->Begin (); i != sources->End (); i++)
    19     {
    20       os << "source=" << i->path << std::endl;
    21       os << "TraceContext=[";
    22       i->context.PrintAvailable (os, ",");
    23       os << "]" << std::endl;
    24       os << "help=\"" << i->doc.GetHelp () << "\"" << std::endl;
    25       os << "void TraceSinkCallback (const TraceContext &";
    26       for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++)
    27         {
    28           os << ", " << k->first;
    29         }
    30       os << ")" << std::endl;
    31       os << "argument 1  --  the trace context associated to the connected trace source." << std::endl;
    32       uint32_t k = 2;
    33       for (TraceDoc::Iterator j = i->doc.ArgsBegin (); j != i->doc.ArgsEnd (); j++)
    34         {
    35           os << "argument " << k << "  --  " << j->second << "." << std::endl;
    36           k++;
    37         }
    38       os << std::endl;
    39     }
    40 }
    41 static void
    42 PrintDoxygenText (const TraceResolver::SourceCollection *sources, std::ostream &os)
    43 {
    44   uint32_t z = 0;
    45   for (TraceResolver::SourceCollection::Iterator i = sources->Begin (); i != sources->End (); i++)
    46     {
    47       os << "///" << std::endl;
    48       os << "/// \\ingroup TraceSourceList" << std::endl; 
    49       os << "/// \\brief " << i->doc.GetHelp () << std::endl;
    50       os << "/// \\param arg1 the trace context associated to the connected trace source." << std::endl;
    51       uint32_t j = 2;
    52       for (TraceDoc::Iterator l = i->doc.ArgsBegin (); l != i->doc.ArgsEnd (); l++)
    53         {
    54           os << "/// \\param arg" << j << " " << l->second << "." << std::endl;
    55           j++;
    56         }
    57       os << "///" << std::endl;
    58       os << "///" << std::endl;
    59       os << "/// The path to this trace source is: <b><tt>\"" << i->path << "\"</tt></b>." << std::endl;
    60       os << "///" << std::endl;
    61       if (i->context.Begin ().IsLast ())
    62         {
    63           os << "/// No data can be extracted from \\p arg1 with ns3::TraceContext::GetElement." << std::endl;
    64         }
    65       else
    66         {
    67           os << "/// The following classes can be extracted from \\p arg1 with " << std::endl;
    68           os << "/// ns3::TraceContext::GetElement:" << std::endl;
    69           for (TraceContext::Iterator m = i->context.Begin (); !m.IsLast (); m.Next ())
    70             {
    71               os << "///  - " << m.Get () << std::endl;
    72             }
    73         }
    74       os << "void TraceSinkCallback" << z << " (const TraceContext & arg1" ;
    75       j = 2;
    76       for (TraceDoc::Iterator k = i->doc.ArgsBegin (); k != i->doc.ArgsEnd (); k++)
    77         {
    78           os << ", " << k->first << " arg" << j;
    79           j++;
    80         }
    81       os << ");" << std::endl;
    82       os << std::endl;
    83       z++;
    84     }
    85 }
    86 
    87 static void
    88 PrintOneDefaultValue (DefaultValueBase *value, std::ostream &os)
    89 {
    90   os << "///  <li> \\anchor DefaultValue" << value->GetName ()
    91      << " " << value->GetName () << std::endl;
    92   os << "///    <ul>" << std::endl;
    93   os << "///         <li>Type: " << value->GetType () << "</td></tr>" << std::endl;
    94   os << "///         <li>Default value: " << value->GetDefaultValue () << "</td></tr>" << std::endl;
    95   os << "///         <li>Description: " << value->GetHelp () << "</td></tr>" << std::endl;
    96   os << "///    </ul>" << std::endl;
    97   os << "///  </li>" << std::endl;
    98 }
    99 
   100 static void
   101 PrintDefaultValuesDoxygen (std::ostream &os)
   102 {
   103   os << "/// \\page ListOfDefaultValues The list of default values" << std::endl;
   104   os << "/// \\defgroup ListOfDefaultValuesGroup The list of default values" << std::endl;
   105   os << "/// <ul>" << std::endl;
   106   for (DefaultValueList::Iterator i = DefaultValueList::Begin ();
   107        i != DefaultValueList::End (); i++)
   108     {
   109       if ((*i)->GetName () == "help")
   110 	{
   111 	  continue;
   112 	}
   113       PrintOneDefaultValue (*i, os);
   114     }
   115   os << "/// </ul>" << std::endl;
   116 }
   117 
   118 
   119 int main (int argc, char *argv[])
   120 {
   121   Ptr<Node> node = CreateObject<InternetNode> ();
   122   node->AggregateObject (CreateObject<MobilityModelNotifier> ());
   123 
   124   Ptr<PointToPointNetDevice> p2p = CreateObjectWith<PointToPointNetDevice> ("Node", node, 
   125 									    "Address", Mac48Address::Allocate ());
   126   node->AddDevice (p2p);
   127   p2p->AddQueue (CreateObject<DropTailQueue> ());
   128   Ptr<CsmaNetDevice> csma = CreateObjectWith<CsmaNetDevice> ("Node", node, 
   129 							     "Address", Mac48Address::Allocate (),
   130 							     "EncapsulationMode", String ("Llc"));
   131   node->AddDevice (csma);
   132   csma->AddQueue (CreateObject<DropTailQueue> ());
   133 
   134   TraceResolver::SourceCollection collection;
   135   NodeList::GetTraceResolver ()->CollectSources ("", TraceContext (), &collection);
   136   PrintDoxygenText (&collection, std::cout);
   137 
   138 
   139   PrintDefaultValuesDoxygen (std::cout);
   140 
   141   return 0;
   142 }