From 598eaa74e16016695792ac4d3eecf915e0814d9d Mon Sep 17 00:00:00 2001 From: Mitch Watrous Date: Tue, 20 Sep 2011 12:12:08 -0700 Subject: [PATCH] Make the source code introspection program output text --- utils/print-introspected-doxygen.cc | 253 ++++++++++++++++++++++------ 1 file changed, 202 insertions(+), 51 deletions(-) diff --git a/utils/print-introspected-doxygen.cc b/utils/print-introspected-doxygen.cc index 16fd992d3..1f548a7c1 100644 --- a/utils/print-introspected-doxygen.cc +++ b/utils/print-introspected-doxygen.cc @@ -1,5 +1,6 @@ #include #include +#include #include "ns3/object.h" #include "ns3/pointer.h" #include "ns3/object-vector.h" @@ -13,26 +14,55 @@ using namespace ns3; NS_LOG_COMPONENT_DEFINE ("PrintIntrospectedDoxygen"); +namespace +{ + std::string anchor; + std::string boldStart; + std::string boldStop; + std::string breakBoth; + std::string breakHtmlOnly; + std::string breakTextOnly; + std::string brief; + std::string commentStart; + std::string commentStop; + std::string defgroupAttributeListStart; + std::string defgroupAttributeListStop; + std::string defgroupGlobalValueListStart; + std::string defgroupGlobalValueListStop; + std::string defgroupTraceSourceListStart; + std::string defgroupTraceSourceListStop; + std::string functionStart; + std::string functionStop; + std::string indentHtmlOnly; + std::string ingroupConstructs; + std::string listStart; + std::string listStop; + std::string listLineStart; + std::string listLineStop; + std::string reference; + +} // anonymous namespace + void PrintAttributes (TypeId tid, std::ostream &os) { - os << "
    "<" << info.name << ": " + os << listLineStart << boldStart << info.name << boldStop << ": " << info.help << std::endl; - os << "
      " << std::endl - << "
    • Set with class: \\ref " << info.checker->GetValueTypeName () << "
    • " << std::endl; + os << " " << listStart << std::endl + << " " << listLineStart << "Set with class: " << reference << info.checker->GetValueTypeName () << listLineStop << std::endl; if (info.checker->HasUnderlyingTypeInformation ()) { - os << "
    • Underlying type: \\ref " << info.checker->GetUnderlyingTypeInformation () << "
    • " << std::endl; + os << " " << listLineStart << "Underlying type: " << reference << info.checker->GetUnderlyingTypeInformation () << listLineStop << std::endl; } if (info.flags & TypeId::ATTR_CONSTRUCT && info.accessor->HasSetter ()) { - os << "
    • Initial value: " << info.initialValue->SerializeToString (info.checker) << "
    • " << std::endl; + os << " " << listLineStart << "Initial value: " << info.initialValue->SerializeToString (info.checker) << listLineStop << std::endl; } - os << "
    • Flags: "; + os << " " << listLineStart << "Flags: "; if (info.flags & TypeId::ATTR_CONSTRUCT && info.accessor->HasSetter ()) { os << "construct "; @@ -45,26 +75,26 @@ PrintAttributes (TypeId tid, std::ostream &os) { os << "read "; } - os << "
    • " << std::endl; - os << "
    " << std::endl; + os << listLineStop << std::endl; + os << " " << listStop << " " << std::endl; } - os << "
" << std::endl; + os << listStop << std::endl; } void PrintTraceSources (TypeId tid, std::ostream &os) { - os << "
    "<" << info.name << ": " + os << listLineStart << boldStart << info.name << boldStop << ": " << info.help << std::endl; - os << "" << std::endl; + os << listLineStop << std::endl; } - os << "
"<GetInstanceTypeId ()); } + std::map< std::string, uint32_t> nameMap; + std::map< std::string, uint32_t>::const_iterator nameMapIterator; + + // Create a map from the class names to their index in the vector of + // TypeId's so that the names will end up in alphabetical order. for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++) { - std::cout << "/*!" << std::endl; TypeId tid = TypeId::GetRegistered (i); if (tid.MustHideFromDocumentation ()) { continue; } - std::cout << "\\fn static TypeId " << tid.GetName () << "::GetTypeId (void)" << std::endl; - std::cout << "\\brief This method returns the TypeId associated to \\ref " << tid.GetName () + + // Capitalize all of letters in the name so that it sorts + // correctly in the map. + std::string name = tid.GetName (); + for (uint32_t j = 0; j < name.length (); j++) + { + name[j] = toupper (name[j]); + } + + // Save this name's index. + nameMap[name] = i; + } + + // Iterate over the map, which will print the class names in + // alphabetical order. + for (nameMapIterator = nameMap.begin (); nameMapIterator != nameMap.end (); nameMapIterator++) + { + // Get the class's index out of the map; + uint32_t i = nameMapIterator->second; + + std::cout << commentStart << std::endl; + TypeId tid = TypeId::GetRegistered (i); + if (tid.MustHideFromDocumentation ()) + { + continue; + } + std::cout << functionStart << "static TypeId " << tid.GetName () << "::GetTypeId (void)" << functionStop << std::endl; + std::cout << brief << "This method returns the TypeId associated to " << reference << tid.GetName () << "." << std::endl << std::endl; std::vector paths = info.Get (tid); if (!paths.empty ()) { std::cout << "This object is accessible through the following paths with Config::Set and Config::Connect:" << std::endl; - std::cout << "
    " << std::endl; + std::cout << listStart << std::endl; for (uint32_t k = 0; k < paths.size (); ++k) { std::string path = paths[k]; - std::cout << "
  • " << path << "
  • " << std::endl; + std::cout << listLineStart << path << listLineStop << breakTextOnly << std::endl; } - std::cout << "
" << std::endl; + std::cout << listStop << std::endl; } if (tid.GetAttributeN () == 0) { - std::cout << "No Attributes defined for this type.
" << std::endl; + std::cout << "No Attributes defined for this type." << breakBoth << std::endl; } else { - std::cout << "Attributes defined for this type:
" << std::endl; + std::cout << "Attributes defined for this type:" << breakHtmlOnly << std::endl; PrintAttributes (tid, std::cout); } { @@ -317,7 +469,7 @@ int main (int argc, char *argv[]) { if (tmp.GetAttributeN () != 0) { - std::cout << "Attributes defined in parent class " << tmp.GetName () << ":
" << std::endl; + std::cout << "Attributes defined in parent class " << tmp.GetName () << ":" << breakHtmlOnly << std::endl; PrintAttributes (tmp, std::cout); } tmp = tmp.GetParent (); @@ -325,11 +477,11 @@ int main (int argc, char *argv[]) } if (tid.GetTraceSourceN () == 0) { - std::cout << "No TraceSources defined for this type.
" << std::endl; + std::cout << "No TraceSources defined for this type." << breakBoth << std::endl; } else { - std::cout << "TraceSources defined for this type:
" << std::endl; + std::cout << "TraceSources defined for this type:" << breakHtmlOnly << std::endl; PrintTraceSources (tid, std::cout); } { @@ -338,19 +490,19 @@ int main (int argc, char *argv[]) { if (tmp.GetTraceSourceN () != 0) { - std::cout << "TraceSources defined in parent class " << tmp.GetName () << ":
" << std::endl; + std::cout << "TraceSources defined in parent class " << tmp.GetName () << ":" << breakHtmlOnly << std::endl; PrintTraceSources (tmp, std::cout); } tmp = tmp.GetParent (); } } - std::cout << "*/" << std::endl; + std::cout << commentStop << std::endl; } - std::cout << "/*!" << std::endl - << "\\ingroup constructs" << std::endl - << "\\defgroup TraceSourceList The list of all trace sources." << std::endl; + std::cout << commentStart << std::endl + << ingroupConstructs + << defgroupTraceSourceListStart << "The list of all trace sources." << defgroupTraceSourceListStop << std::endl; for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) { TypeId tid = TypeId::GetRegistered (i); @@ -359,21 +511,20 @@ int main (int argc, char *argv[]) { continue; } - std::cout << "" << tid.GetName () << "
" << std::endl - << "
    " << std::endl; + std::cout << boldStart << tid.GetName () << boldStop << breakHtmlOnly << std::endl + << listStart << std::endl; for (uint32_t j = 0; j < tid.GetTraceSourceN (); ++j) { struct TypeId::TraceSourceInformation info = tid.GetTraceSource(j); - std::cout << "
  • " << info.name << ": " << info.help << "
  • " << std::endl; + std::cout << listLineStart << info.name << ": " << info.help << listLineStop << std::endl; } - std::cout << "
" << std::endl; + std::cout << listStop << std::endl; } - std::cout << "*/" << std::endl; + std::cout << commentStop << std::endl; - - std::cout << "/*!" << std::endl - << "\\ingroup constructs" << std::endl - << "\\defgroup AttributeList The list of all attributes." << std::endl; + std::cout << commentStart << std::endl + << ingroupConstructs + << defgroupAttributeListStart << "The list of all attributes." << defgroupAttributeListStop << std::endl; for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) { TypeId tid = TypeId::GetRegistered (i); @@ -382,31 +533,31 @@ int main (int argc, char *argv[]) { continue; } - std::cout << "" << tid.GetName () << "
" << std::endl - << "
    " << std::endl; + std::cout << boldStart << tid.GetName () << boldStop << breakHtmlOnly << std::endl + << listStart << std::endl; for (uint32_t j = 0; j < tid.GetAttributeN (); ++j) { struct TypeId::AttributeInformation info = tid.GetAttribute(j); - std::cout << "
  • " << info.name << ": " << info.help << "
  • " << std::endl; + std::cout << listLineStart << info.name << ": " << info.help << listLineStop << std::endl; } - std::cout << "
" << std::endl; + std::cout << listStop << std::endl; } - std::cout << "*/" << std::endl; + std::cout << commentStop << std::endl; - std::cout << "/*!" << std::endl - << "\\ingroup constructs" << std::endl - << "\\defgroup GlobalValueList The list of all global values." << std::endl - << "
    " << std::endl; + std::cout << commentStart << std::endl + << ingroupConstructs + << defgroupGlobalValueListStart << "The list of all global values." << defgroupGlobalValueListStop << std::endl + << listStart << std::endl; for (GlobalValue::Iterator i = GlobalValue::Begin (); i != GlobalValue::End (); ++i) { StringValue val; (*i)->GetValue (val); - std::cout << "
  • \\anchor GlobalValue" << (*i)->GetName () << " " << (*i)->GetName () << ": " << (*i)->GetHelp () << "(" << val.Get () << ")
  • " << std::endl; + std::cout << indentHtmlOnly << listLineStart << boldStart << anchor << "GlobalValue" << (*i)->GetName () << " " << (*i)->GetName () << boldStop << ": " << (*i)->GetHelp () << "(" << val.Get () << ")" << listLineStop << std::endl; } - std::cout << "
" << std::endl - << "*/" << std::endl; + std::cout << listStop << std::endl + << commentStop << std::endl; return 0;