A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
print-introspected-doxygen.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9/**
10 * @file
11 * @ingroup utils
12 * Generate documentation from the TypeId database.
13 */
14
15#include "ns3/command-line.h"
16#include "ns3/config.h"
17#include "ns3/global-value.h"
18#include "ns3/log.h"
19#include "ns3/node-container.h"
20#include "ns3/object-vector.h"
21#include "ns3/object.h"
22#include "ns3/pointer.h"
23#include "ns3/simple-channel.h"
24#include "ns3/string.h"
25#include "ns3/system-path.h"
26
27#include <algorithm>
28#include <climits> // CHAR_BIT
29#include <iomanip>
30#include <iostream>
31#include <map>
32#include <utility> // as_const
33
34using namespace ns3;
35
36NS_LOG_COMPONENT_DEFINE("PrintIntrospectedDoxygen");
37
38namespace
39{
40/** Are we generating text or Doxygen? */
41bool outputText = false;
42
43/**
44 * Markup tokens.
45 * @{
46 */
47std::string anchor; ///< hyperlink anchor
48std::string argument; ///< function argument
49std::string boldStart; ///< start of bold span
50std::string boldStop; ///< end of bold span
51std::string breakBoth; ///< linebreak
52std::string breakHtmlOnly; ///< linebreak for html output only
53std::string breakTextOnly; ///< linebreak for text output only
54std::string brief; ///< brief tag
55std::string classStart; ///< start of a class
56std::string classStop; ///< end of a class
57std::string codeWord; ///< format next word as source code
58std::string commentStart; ///< start of code comment
59std::string commentStop; ///< end of code comment
60std::string copyDoc; ///< copy (or refer) to docs elsewhere
61std::string file; ///< file
62std::string flagSpanStart; ///< start of Attribute flag value
63std::string flagSpanStop; ///< end of Attribute flag value
64std::string functionStart; ///< start of a method/function
65std::string functionStop; ///< end of a method/function
66std::string headingStart; ///< start of section heading (h3)
67std::string headingStop; ///< end of section heading (h3)
68// Linking: [The link text displayed](\ref TheTarget)
69std::string hrefStart; ///< start of a link
70std::string hrefMid; ///< middle part of a link
71std::string hrefStop; ///< end of a link
72std::string indentHtmlOnly; ///< small indent
73std::string listLineStart; ///< start unordered list item
74std::string listLineStop; ///< end unordered list item
75std::string listStart; ///< start unordered list
76std::string listStop; ///< end unordered list
77std::string note; ///< start a note section
78std::string page; ///< start a separate page
79std::string reference; ///< reference tag
80std::string referenceNo; ///< block automatic references
81std::string returns; ///< the return value
82std::string sectionStart; ///< start of a section or group
83std::string seeAlso; ///< Reference to other docs
84std::string subSectionStart; ///< start a new subsection
85std::string templArgDeduced; ///< template argument deduced from function
86std::string templArgExplicit; ///< template argument required
87std::string templateArgument; ///< template argument
88std::string variable; ///< variable or class member
89
90/** @} */
91
92/**
93 * Alphabetize the AttributeInformation for a TypeId by the Attribute name
94 * @param tid The TypeId to process.
95 * @return The ordered list of Attributes.
96 */
97std::map<std::string, ns3::TypeId::AttributeInformation>
99{
100 std::map<std::string, ns3::TypeId::AttributeInformation> index;
101 for (uint32_t j = 0; j < tid.GetAttributeN(); j++)
102 {
103 struct TypeId::AttributeInformation info = tid.GetAttribute(j);
104 index[info.name] = info;
105 }
106 return index;
107}
108
109/**
110 * Alphabetize the TraceSourceInformation for a TypeId by the
111 * TraceSource name.
112 * @param tid The TypeId to process.
113 * @return The ordered list of TraceSourceInformation
114 */
115std::map<std::string, ns3::TypeId::TraceSourceInformation>
117{
118 std::map<std::string, ns3::TypeId::TraceSourceInformation> index;
119 for (uint32_t j = 0; j < tid.GetTraceSourceN(); j++)
120 {
122 index[info.name] = info;
123 }
124 return index;
125}
126
127} // unnamed namespace
128
129/**
130 * Initialize the markup strings, for either doxygen or text.
131 */
132void
134{
136 if (outputText)
137 {
138 anchor = "";
139 argument = " Arg: ";
140 boldStart = "";
141 boldStop = "";
142 breakBoth = "\n";
143 breakHtmlOnly = "";
144 breakTextOnly = "\n";
145 brief = "";
146 classStart = "";
147 classStop = "\n\n";
148 codeWord = " ";
149 commentStart = "===============================================================\n";
150 commentStop = "";
151 copyDoc = " See: ";
152 file = "File: introspected-doxygen.txt";
153 flagSpanStart = "";
154 flagSpanStop = "";
155 functionStart = "";
156 functionStop = "\n\n";
157 headingStart = "";
158 headingStop = "";
159 // Linking: The link text displayed (see TheTarget)
160 hrefStart = "";
161 hrefMid = " (see ";
162 hrefStop = ")";
163 indentHtmlOnly = "";
164 listLineStart = " * ";
165 listLineStop = "";
166 listStart = "";
167 listStop = "";
168 note = "Note: ";
169 page = "Page ";
170 reference = " ";
171 referenceNo = " ";
172 returns = " Returns: ";
173 sectionStart = "Section: ";
174 seeAlso = " See: ";
175 subSectionStart = "Subsection ";
176 templArgDeduced = "[deduced] ";
177 templArgExplicit = "[explicit] ";
178 templateArgument = "Template Arg: ";
179 variable = "Variable: ";
180 }
181 else
182 {
183 anchor = "\\anchor ";
184 argument = "\\param ";
185 boldStart = "<b>";
186 boldStop = "</b>";
187 breakBoth = "<br>";
188 breakHtmlOnly = "<br>";
189 breakTextOnly = "";
190 brief = "\\brief ";
191 classStart = "\\class ";
192 classStop = "";
193 codeWord = "\\p ";
194 commentStart = "/*!\n";
195 commentStop = "*/\n";
196 copyDoc = "\\copydoc ";
197 file = "\\file";
198 flagSpanStart = "<span class=\"mlabel\">";
199 flagSpanStop = "</span>";
200 functionStart = "\\fn ";
201 functionStop = "";
202 headingStart = "<h3>";
203 headingStop = "</h3>";
204 // Linking: [The link text displayed](\ref TheTarget)
205 hrefStart = "[";
206 hrefMid = "](\\ref ";
207 hrefStop = ")";
208 indentHtmlOnly = " ";
209 listLineStart = "<li>";
210 listLineStop = "</li>";
211 listStart = "<ul>";
212 listStop = "</ul>";
213 note = "\\note ";
214 page = "\\page ";
215 reference = " \\ref ";
216 referenceNo = " %";
217 returns = "\\returns ";
218 sectionStart = "\\ingroup ";
219 seeAlso = "\\see ";
220 subSectionStart = "\\addtogroup ";
221 templArgDeduced = "\\deduced ";
222 templArgExplicit = "\\explicit ";
223 templateArgument = "\\tparam ";
224 variable = "\\var ";
225 }
226} // SetMarkup()
227
228/***************************************************************
229 * Aggregation and configuration paths
230 ***************************************************************/
231
232/**
233 * Gather aggregation and configuration path information from registered types.
234 */
236{
237 public:
238 /**
239 * Record the a -> b aggregation relation.
240 *
241 * @param a [in] the source(?) TypeId name
242 * @param b [in] the destination(?) TypeId name
243 */
244 void RecordAggregationInfo(std::string a, std::string b);
245 /**
246 * Gather aggregation and configuration path information for tid
247 *
248 * @param tid [in] the TypeId to gather information from
249 */
250 void Gather(TypeId tid);
251 /**
252 * Print output in "a -> b" form on the stream.
253 * @param [in,out] os The output stream.
254 */
255 void Print(std::ostream& os) const;
256
257 /**
258 * @return the configuration paths for tid
259 *
260 * @param tid [in] the TypeId to return information for
261 */
262 std::vector<std::string> Get(TypeId tid) const;
263
264 /**
265 * @return the type names we couldn't aggregate.
266 */
267 std::vector<std::string> GetNoTypeIds() const;
268
269 private:
270 /**
271 * @return the current configuration path
272 */
273 std::string GetCurrentPath() const;
274 /**
275 * Gather attribute, configuration path information for tid
276 *
277 * @param tid [in] the TypeId to gather information from
278 */
279 void DoGather(TypeId tid);
280 /**
281 * Record the current config path for tid.
282 *
283 * @param tid [in] the TypeId to record.
284 */
285 void RecordOutput(TypeId tid);
286 /**
287 * @return whether the tid has already been processed
288 *
289 * @param tid [in] the TypeId to check.
290 */
291 bool HasAlreadyBeenProcessed(TypeId tid) const;
292 /**
293 * Configuration path for each TypeId
294 */
295 std::vector<std::pair<TypeId, std::string>> m_output;
296 /**
297 * Current configuration path
298 */
299 std::vector<std::string> m_currentPath;
300 /**
301 * List of TypeIds we've already processed
302 */
303 std::vector<TypeId> m_alreadyProcessed;
304 /**
305 * List of aggregation relationships.
306 */
307 std::vector<std::pair<TypeId, TypeId>> m_aggregates;
308 /**
309 * List of type names without TypeIds, because those modules aren't enabled.
310 *
311 * This is mutable because GetNoTypeIds sorts and uniquifies this list
312 * before returning it.
313 */
314 mutable std::vector<std::string> m_noTids;
315
316 // end of class StaticInformation
317};
318
319void
320StaticInformation::RecordAggregationInfo(std::string a, std::string b)
321{
322 NS_LOG_FUNCTION(this << a << b);
323 TypeId aTid;
324 bool found = TypeId::LookupByNameFailSafe(a, &aTid);
325 if (!found)
326 {
327 m_noTids.push_back(a);
328 return;
329 }
330 TypeId bTid;
331 found = TypeId::LookupByNameFailSafe(b, &bTid);
332 if (!found)
333 {
334 m_noTids.push_back(b);
335 return;
336 }
337
338 m_aggregates.emplace_back(aTid, bTid);
339}
340
341void
342StaticInformation::Print(std::ostream& os) const
343{
344 NS_LOG_FUNCTION(this);
345 for (const auto& item : m_output)
346 {
347 os << item.first.GetName() << " -> " << item.second << std::endl;
348 }
349}
350
351std::string
353{
354 NS_LOG_FUNCTION(this);
355 std::ostringstream oss;
356 for (const auto& item : m_currentPath)
357 {
358 oss << "/" << item;
359 }
360 return oss.str();
361}
362
363void
365{
366 NS_LOG_FUNCTION(this << tid);
367 m_output.emplace_back(tid, GetCurrentPath());
368}
369
370bool
372{
373 NS_LOG_FUNCTION(this << tid);
374 for (const auto& it : m_alreadyProcessed)
375 {
376 if (it == tid)
377 {
378 return true;
379 }
380 }
381 return false;
382}
383
384std::vector<std::string>
386{
387 NS_LOG_FUNCTION(this << tid);
388 std::vector<std::string> paths;
389 for (const auto& item : m_output)
390 {
391 if (item.first == tid)
392 {
393 paths.push_back(item.second);
394 }
395 }
396 return paths;
397}
398
399/**
400 * Helper to keep only the unique items in a container.
401 *
402 * The container is modified in place; the elements end up sorted.
403 *
404 * The container must support \c begin(), \c end() and \c erase(),
405 * which, among the STL containers, limits this to
406 * \c std::vector, \c std::dequeue and \c std::list.
407 *
408 * The container elements must support \c operator< (for \c std::sort)
409 * and \c operator== (for \c std::unique).
410 *
411 * @tparam T \deduced The container type.
412 * @param t The container.
413 */
414template <typename T>
415void
417{
418 std::sort(t.begin(), t.end());
419 t.erase(std::unique(t.begin(), t.end()), t.end());
420}
421
422std::vector<std::string>
424{
425 NS_LOG_FUNCTION(this);
427 return m_noTids;
428}
429
430void
432{
433 NS_LOG_FUNCTION(this << tid);
434 DoGather(tid);
436}
437
438void
440{
441 NS_LOG_FUNCTION(this << tid);
443 {
444 return;
445 }
446 RecordOutput(tid);
447 for (uint32_t i = 0; i < tid.GetAttributeN(); ++i)
448 {
449 struct TypeId::AttributeInformation info = tid.GetAttribute(i);
450 const auto ptrChecker = dynamic_cast<const PointerChecker*>(PeekPointer(info.checker));
451 if (ptrChecker != nullptr)
452 {
453 TypeId pointee = ptrChecker->GetPointeeTypeId();
454
455 // See if this is a pointer to an Object.
457 TypeId objectTypeId = Object::GetTypeId();
458 if (objectTypeId == pointee)
459 {
460 // Stop the recursion at this attribute if it is a
461 // pointer to an Object, which create too many spurious
462 // paths in the list of attribute paths because any
463 // Object can be in that part of the path.
464 continue;
465 }
466
467 m_currentPath.push_back(info.name);
468 m_alreadyProcessed.push_back(tid);
469 DoGather(pointee);
470 m_alreadyProcessed.pop_back();
471 m_currentPath.pop_back();
472 continue;
473 }
474 // attempt to cast to an object vector.
475 const auto vectorChecker =
476 dynamic_cast<const ObjectPtrContainerChecker*>(PeekPointer(info.checker));
477 if (vectorChecker != nullptr)
478 {
479 TypeId item = vectorChecker->GetItemTypeId();
480 m_currentPath.push_back(info.name + "/[i]");
481 m_alreadyProcessed.push_back(tid);
482 DoGather(item);
483 m_alreadyProcessed.pop_back();
484 m_currentPath.pop_back();
485 continue;
486 }
487 }
488 for (uint32_t j = 0; j < TypeId::GetRegisteredN(); j++)
489 {
490 TypeId child = TypeId::GetRegistered(j);
491 if (child.IsChildOf(tid))
492 {
493 std::string childName = "$" + child.GetName();
494 m_currentPath.push_back(childName);
495 m_alreadyProcessed.push_back(tid);
496 DoGather(child);
497 m_alreadyProcessed.pop_back();
498 m_currentPath.pop_back();
499 }
500 }
501 for (const auto& item : m_aggregates)
502 {
503 if (item.first == tid || item.second == tid)
504 {
505 TypeId other;
506 if (item.first == tid)
507 {
508 other = item.second;
509 }
510 if (item.second == tid)
511 {
512 other = item.first;
513 }
514 std::string name = "$" + other.GetName();
515 m_currentPath.push_back(name);
516 m_alreadyProcessed.push_back(tid);
517 DoGather(other);
518 m_alreadyProcessed.pop_back();
519 m_currentPath.pop_back();
520 }
521 }
522} // StaticInformation::DoGather()
523
524/// Register aggregation relationships that are not automatically
525/// detected by this introspection program. Statements added here
526/// result in more configuration paths being added to the doxygen.
527/// @return instance of StaticInformation with the registered information
530{
532
533 static StaticInformation info;
534 static bool mapped = false;
535
536 if (mapped)
537 {
538 return info;
539 }
540
541 // Short circuit next call
542 mapped = true;
543
544 // The below statements register typical aggregation relationships
545 // in ns-3 programs, that otherwise aren't picked up automatically
546 // by the creation of the above node. To manually list other common
547 // aggregation relationships that you would like to see show up in
548 // the list of configuration paths in the doxygen, add additional
549 // statements below.
550 info.RecordAggregationInfo("ns3::Node", "ns3::TcpSocketFactory");
551 info.RecordAggregationInfo("ns3::Node", "ns3::UdpSocketFactory");
552 info.RecordAggregationInfo("ns3::Node", "ns3::PacketSocketFactory");
553 info.RecordAggregationInfo("ns3::Node", "ns3::MobilityModel");
554 info.RecordAggregationInfo("ns3::Node", "ns3::Ipv4L3Protocol");
555 info.RecordAggregationInfo("ns3::Node", "ns3::Ipv4NixVectorRouting");
556 info.RecordAggregationInfo("ns3::Node", "ns3::Icmpv4L4Protocol");
557 info.RecordAggregationInfo("ns3::Node", "ns3::ArpL3Protocol");
558 info.RecordAggregationInfo("ns3::Node", "ns3::Icmpv4L4Protocol");
559 info.RecordAggregationInfo("ns3::Node", "ns3::UdpL4Protocol");
560 info.RecordAggregationInfo("ns3::Node", "ns3::Ipv6L3Protocol");
561 info.RecordAggregationInfo("ns3::Node", "ns3::Icmpv6L4Protocol");
562 info.RecordAggregationInfo("ns3::Node", "ns3::TcpL4Protocol");
563 info.RecordAggregationInfo("ns3::Node", "ns3::RipNg");
564 info.RecordAggregationInfo("ns3::Node", "ns3::GlobalRouter");
565 info.RecordAggregationInfo("ns3::Node", "ns3::aodv::RoutingProtocol");
566 info.RecordAggregationInfo("ns3::Node", "ns3::dsdv::RoutingProtocol");
567 info.RecordAggregationInfo("ns3::Node", "ns3::dsr::DsrRouting");
568 info.RecordAggregationInfo("ns3::Node", "ns3::olsr::RoutingProtocol");
569 info.RecordAggregationInfo("ns3::Node", "ns3::energy::EnergyHarvesterContainer");
570 info.RecordAggregationInfo("ns3::Node", "ns3::energy::EnergySourceContainer");
571
572 // Create a channel object so that channels appear in the namespace
573 // paths that will be generated here.
574 Ptr<SimpleChannel> simpleChannel;
575 simpleChannel = CreateObject<SimpleChannel>();
576
577 for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN(); ++i)
578 {
580 info.Gather(object->GetInstanceTypeId());
581 }
582
583 return info;
584
585} // GetTypicalAggregations()
586
587/// Map from TypeId name to tid
588typedef std::map<std::string, int32_t> NameMap;
589typedef NameMap::const_iterator NameMapIterator; ///< NameMap iterator
590
591/**
592 * Create a map from the class names to their index in the vector of
593 * TypeId's so that the names will end up in alphabetical order.
594 *
595 * @returns NameMap
596 */
599{
601
602 static NameMap nameMap;
603 static bool mapped = false;
604
605 if (mapped)
606 {
607 return nameMap;
608 }
609
610 // Short circuit next call
611 mapped = true;
612
613 // Get typical aggregation relationships.
615
616 // Registered types
617 for (uint32_t i = 0; i < TypeId::GetRegisteredN(); i++)
618 {
621 {
622 continue;
623 }
624
625 // Capitalize all of letters in the name so that it sorts
626 // correctly in the map.
627 std::string name = tid.GetName();
628 std::transform(name.begin(), name.end(), name.begin(), ::toupper);
629
630 // Save this name's index.
631 nameMap[name] = i;
632 }
633
634 // Type names without TypeIds
635 std::vector<std::string> noTids = info.GetNoTypeIds();
636 for (const auto& item : noTids)
637 {
638 nameMap[item] = -1;
639 }
640
641 return nameMap;
642} // GetNameMap()
643
644/// List of TypeIds for a group
645using GroupList_t = std::set<TypeId>;
646/// Collection of group names with associated TypeIds
647using GroupsList_t = std::map<std::string, GroupList_t>;
648
649/**
650 * Get a sorted list of TypeId groups
651 * @returns a map of group name and associated TypeIds
652 */
655{
656 static GroupsList_t groups;
657 static bool mapped = false;
658 if (mapped)
659 {
660 return groups;
661 }
662
663 NameMap nameMap = GetNameMap();
664 for (const auto& item : nameMap)
665 {
666 // Handle only real TypeIds
667 if (item.second < 0)
668 {
669 continue;
670 }
671 // Get the class's index out of the map;
672 TypeId tid = TypeId::GetRegistered(item.second);
673 auto group = tid.GetGroupName();
674
675 if (!group.empty())
676 {
677 groups[group].insert(tid);
678 }
679 }
680 return groups;
681
682} // GetGroupsList()
683
684/***************************************************************
685 * Docs for a single TypeId
686 ***************************************************************/
687
688/**
689 * Print the support level for an Attribute or TraceSource
690 * @param os the output stream
691 * @param supportLevel the SupportLevel
692 * @param supportMsg optional support message
693 */
694void
696{
697 os << " " << listLineStart << "Support level: ";
699
700 if (!supportMsg.empty())
701 {
702 os << ": " << supportMsg;
703 }
704 os << listLineStop << std::endl;
705} // PrintSupportLevel
706
707/**
708 * Print config paths
709 * @param os the output stream
710 * @param tid the type ID
711 */
712void
713PrintConfigPaths(std::ostream& os, const TypeId tid)
714{
715 NS_LOG_FUNCTION(tid);
716 std::vector<std::string> paths = GetTypicalAggregations().Get(tid);
717
718 // Config --------------
719 if (paths.empty())
720 {
721 os << "Introspection did not find any typical Config paths." << breakBoth << std::endl;
722 }
723 else
724 {
725 os << headingStart << "Config Paths" << headingStop << std::endl;
726 os << std::endl;
727 os << tid.GetName() << " is accessible through the following paths"
728 << " with Config::Set and Config::Connect:" << std::endl;
729 os << listStart << std::endl;
730 for (const auto& path : paths)
731 {
732 os << listLineStart << "\"" << path << "\"" << listLineStop << breakTextOnly
733 << std::endl;
734 }
735 os << listStop << std::endl;
736 }
737} // PrintConfigPaths()
738
739/**
740 * Print direct Attributes for this TypeId.
741 *
742 * Only attributes defined directly by this TypeId will be printed.
743 *
744 * @param [in,out] os The output stream.
745 * @param [in] tid The TypeId to print.
746 */
747void
748PrintAttributesTid(std::ostream& os, const TypeId tid)
749{
750 NS_LOG_FUNCTION(tid);
751
752 auto index = SortedAttributeInfo(tid);
753
754 os << listStart << std::endl;
755 for (const auto& [name, info] : index)
756 {
757 os << listLineStart << boldStart << name << boldStop << ": " << info.help << std::endl;
758 os << indentHtmlOnly << listStart << std::endl;
759 os << " " << listLineStart << "Set with class: " << reference
760 << info.checker->GetValueTypeName() << listLineStop << std::endl;
761
762 std::string underType;
763 if (info.checker->HasUnderlyingTypeInformation())
764 {
765 os << " " << listLineStart << "Underlying type: ";
766
767 std::string valType = info.checker->GetValueTypeName();
768 underType = info.checker->GetUnderlyingTypeInformation();
769 bool handled = false;
770 if ((valType != "ns3::EnumValue") && (underType != "std::string"))
771 {
772 // Indirect cases to handle
773 if (valType == "ns3::PointerValue")
774 {
775 const auto ptrChecker =
776 dynamic_cast<const PointerChecker*>(PeekPointer(info.checker));
777 if (ptrChecker != nullptr)
778 {
779 os << reference << "ns3::Ptr"
780 << "< " << reference << ptrChecker->GetPointeeTypeId().GetName() << ">";
781 handled = true;
782 }
783 }
784 else if (valType == "ns3::ObjectPtrContainerValue")
785 {
786 const auto ptrChecker =
787 dynamic_cast<const ObjectPtrContainerChecker*>(PeekPointer(info.checker));
788 if (ptrChecker != nullptr)
789 {
790 os << reference << "ns3::Ptr"
791 << "< " << reference << ptrChecker->GetItemTypeId().GetName() << ">";
792 handled = true;
793 }
794 }
795
796 // Helper to match first part of string
797 auto match = [&uType = std::as_const(underType)](const std::string& s) {
798 return uType.rfind(s, 0) == 0; // only checks position 0
799 };
800
801 if (match("bool") || match("double") || match("int8_t") || match("uint8_t") ||
802 match("int16_t") || match("uint16_t") || match("int32_t") ||
803 match("uint32_t") || match("int64_t") || match("uint64_t"))
804 {
805 os << underType;
806 handled = true;
807 }
808 }
809 if (!handled)
810 {
811 os << codeWord << underType;
812 }
813 os << listLineStop << std::endl;
814 }
815 if (info.flags & TypeId::ATTR_CONSTRUCT && info.accessor->HasSetter())
816 {
817 std::string value = info.initialValue->SerializeToString(info.checker);
818 if (underType == "std::string" && value.empty())
819 {
820 value = "\"\"";
821 }
822 os << " " << listLineStart << "Initial value: " << value << listLineStop
823 << std::endl;
824 }
825 bool moreFlags{false};
826 os << " " << listLineStart << "Flags: ";
827
828 auto myInfo = info; // See GitLab #1142
829 auto flagWrite = [&os, &moreFlags, myInfo](TypeId::AttributeFlag flag,
830 bool hasFunc,
831 std::string msg) -> void {
832 if (myInfo.flags & flag && hasFunc)
833 {
834 os << (outputText && moreFlags ? ", " : "") << flagSpanStart << msg << flagSpanStop;
835 moreFlags = true;
836 }
837 };
838 flagWrite(TypeId::ATTR_CONSTRUCT, info.accessor->HasSetter(), "construct");
839 flagWrite(TypeId::ATTR_SET, info.accessor->HasSetter(), "write");
840 flagWrite(TypeId::ATTR_GET, info.accessor->HasGetter(), "read");
841 os << listLineStop << std::endl;
842
843 PrintSupportLevel(os, info.supportLevel, info.supportMsg);
844
845 os << indentHtmlOnly << listStop << std::endl;
846 }
847 os << listStop << std::endl;
848} // PrintAttributesTid()
849
850/**
851 * Print the Attributes block for tid,
852 * including Attributes declared in base classes.
853 *
854 * All Attributes of this TypeId will be printed,
855 * including those defined in parent classes.
856 *
857 * @param [in,out] os The output stream.
858 * @param [in] tid The TypeId to print.
859 */
860void
861PrintAttributes(std::ostream& os, const TypeId tid)
862{
863 NS_LOG_FUNCTION(tid);
864 if (tid.GetAttributeN() == 0)
865 {
866 os << "No Attributes are defined for this type." << breakBoth << std::endl;
867 }
868 else
869 {
870 os << headingStart << "Attributes" << headingStop << std::endl;
871 PrintAttributesTid(os, tid);
872 }
873
874 // Attributes from base classes
875 TypeId tmp = tid.GetParent();
876 while (tmp.GetParent() != tmp)
877 {
878 if (tmp.GetAttributeN() != 0)
879 {
880 os << headingStart << "Attributes defined in parent class " << tmp.GetName()
881 << headingStop << std::endl;
882 PrintAttributesTid(os, tmp);
883 }
884 tmp = tmp.GetParent();
885 }
886} // PrintAttributes()
887
888/**
889 * Print direct Trace sources for this TypeId.
890 *
891 * Only Trace sources defined directly by this TypeId will be printed.
892 *
893 * @param [in,out] os The output stream.
894 * @param [in] tid The TypeId to print.
895 */
896void
897PrintTraceSourcesTid(std::ostream& os, const TypeId tid)
898{
899 NS_LOG_FUNCTION(tid);
900
901 auto index = SortedTraceSourceInfo(tid);
902
903 os << listStart << std::endl;
904 for (const auto& [name, info] : index)
905 {
906 os << listLineStart << boldStart << name << boldStop << ": " << info.help << breakBoth;
907 os << indentHtmlOnly << listStart << std::endl;
908 os << " " << listLineStart;
909 if (!outputText)
910 {
911 // '%' prevents doxygen from linking to the Callback class...
912 os << " %";
913 }
914 os << "Callback signature: " << info.callback << std::endl;
915 os << listLineStop << std::endl;
916
917 PrintSupportLevel(os, info.supportLevel, info.supportMsg);
918 os << listStop << std::endl;
919 }
920 os << listStop << std::endl;
921} // PrintTraceSourcesTid()
922
923/**
924 * Print the Trace sources block for tid,
925 * including Trace sources declared in base classes.
926 *
927 * All Trace sources of this TypeId will be printed,
928 * including those defined in parent classes.
929 *
930 * @param [in,out] os The output stream.
931 * @param [in] tid The TypeId to print.
932 */
933void
934PrintTraceSources(std::ostream& os, const TypeId tid)
935{
936 NS_LOG_FUNCTION(tid);
937 if (tid.GetTraceSourceN() == 0)
938 {
939 os << "No TraceSources are defined for this type." << breakBoth << std::endl;
940 }
941 else
942 {
943 os << headingStart << "TraceSources" << headingStop << std::endl;
944 PrintTraceSourcesTid(os, tid);
945 }
946
947 // Trace sources from base classes
948 TypeId tmp = tid.GetParent();
949 while (tmp.GetParent() != tmp)
950 {
951 if (tmp.GetTraceSourceN() != 0)
952 {
953 os << headingStart << "TraceSources defined in parent class " << tmp.GetName()
954 << headingStop << std::endl;
955 PrintTraceSourcesTid(os, tmp);
956 }
957 tmp = tmp.GetParent();
958 }
959
960} // PrintTraceSources()
961
962/**
963 * Print the size of the type represented by this tid.
964 *
965 * @param [in,out] os The output stream.
966 * @param [in] tid The TypeId to print.
967 */
968void
969PrintSize(std::ostream& os, const TypeId tid)
970{
971 NS_LOG_FUNCTION(tid);
972 NS_ASSERT_MSG(CHAR_BIT != 0, "CHAR_BIT is zero");
973
974 std::size_t arch = (sizeof(void*) * CHAR_BIT);
975
976 os << boldStart << "Size" << boldStop << " of this type is " << tid.GetSize() << " bytes (on a "
977 << arch << "-bit architecture)." << std::endl;
978} // PrintSize()
979
980/**
981 * Print the doxy block for a single TypeId
982 *
983 * @param [in,out] os The output stream.
984 * @param [in] tid the TypeId
985 */
986void
987PrintTypeIdBlock(std::ostream& os, const TypeId tid)
988{
989 NS_LOG_FUNCTION(tid);
990
991 std::string name = tid.GetName();
992
993 os << commentStart << std::endl;
994
995 os << classStart << name << std::endl;
996 os << std::endl;
997
998 PrintConfigPaths(os, tid);
999 PrintAttributes(os, tid);
1000 PrintTraceSources(os, tid);
1001
1002 if (!tid.GetGroupName().empty())
1003 {
1004 os << boldStart << "Group:" << boldStop << " " << tid.GetGroupName() << "\n" << std::endl;
1005 }
1006
1007 PrintSize(os, tid);
1008
1009 os << commentStop << std::endl;
1010
1011} // PrintTypeIdBlock()
1012
1013/**
1014 * Print the doxy block for each TypeId
1015 *
1016 * @param [in,out] os The output stream.
1017 */
1018void
1019PrintTypeIdBlocks(std::ostream& os)
1020{
1022
1023 NameMap nameMap = GetNameMap();
1024
1025 // Iterate over the map, which will print the class names in
1026 // alphabetical order.
1027 for (const auto& item : nameMap)
1028 {
1029 // Handle only real TypeIds
1030 if (item.second < 0)
1031 {
1032 continue;
1033 }
1034 // Get the class's index out of the map;
1035 TypeId tid = TypeId::GetRegistered(item.second);
1036 PrintTypeIdBlock(os, tid);
1037 }
1038} // PrintTypeIdBlocks()
1039
1040/***************************************************************
1041 * Lists of All things
1042 ***************************************************************/
1043
1044/**
1045 * Print the list of all TypeIds
1046 *
1047 * @param [in,out] os The output stream.
1048 */
1049void
1050PrintAllTypeIds(std::ostream& os)
1051{
1053 os << commentStart << page << "TypeIdList All ns3::TypeId's\n" << std::endl;
1054 os << "This is a list of all" << reference << "ns3::TypeId's.\n"
1055 << "For more information see the" << reference << "ns3::TypeId "
1056 << "section of this API documentation and the" << referenceNo << "TypeId section "
1057 << "in the Configuration and " << referenceNo << "Attributes chapter of the Manual.\n"
1058 << std::endl;
1059
1060 os << listStart << std::endl;
1061
1062 NameMap nameMap = GetNameMap();
1063 // Iterate over the map, which will print the class names in
1064 // alphabetical order.
1065 for (const auto& item : nameMap)
1066 {
1067 // Handle only real TypeIds
1068 if (item.second < 0)
1069 {
1070 continue;
1071 }
1072 // Get the class's index out of the map;
1073 TypeId tid = TypeId::GetRegistered(item.second);
1074
1075 os << indentHtmlOnly << listLineStart << boldStart << tid.GetName() << boldStop
1076 << listLineStop << std::endl;
1077 }
1078 os << listStop << std::endl;
1079 os << commentStop << std::endl;
1080
1081} // PrintAllTypeIds()
1082
1083/**
1084 * Print the list of all Attributes.
1085 *
1086 * @param [in,out] os The output stream.
1087 *
1088 * @todo Print this sorted by class (the current version)
1089 * as well as by Attribute name.
1090 */
1091void
1092PrintAllAttributes(std::ostream& os)
1093{
1095 os << commentStart << page << "AttributeList All Attributes\n" << std::endl;
1096 os << "This is a list of all" << reference << "attributes classes. "
1097 << "For more information see the" << reference << "attributes "
1098 << "section of this API documentation and the Attributes sections "
1099 << "in the Tutorial and Manual.\n"
1100 << std::endl;
1101
1102 NameMap nameMap = GetNameMap();
1103 // Iterate over the map, which will print the class names in
1104 // alphabetical order.
1105 for (const auto& item : nameMap)
1106 {
1107 // Handle only real TypeIds
1108 if (item.second < 0)
1109 {
1110 continue;
1111 }
1112 // Get the class's index out of the map;
1113 TypeId tid = TypeId::GetRegistered(item.second);
1114
1115 if (tid.GetAttributeN() == 0)
1116 {
1117 continue;
1118 }
1119
1120 auto index = SortedAttributeInfo(tid);
1121
1122 os << boldStart << tid.GetName() << boldStop << breakHtmlOnly << std::endl;
1123 os << listStart << std::endl;
1124 for (const auto& [name, info] : index)
1125 {
1126 os << listLineStart << boldStart << name << boldStop << ": " << info.help
1127 << listLineStop << std::endl;
1128 }
1129 os << listStop << std::endl;
1130 }
1131 os << commentStop << std::endl;
1132
1133} // PrintAllAttributes()
1134
1135/**
1136 * Print the list of all global variables.
1137 *
1138 * @param [in,out] os The output stream.
1139 */
1140void
1141PrintAllGlobals(std::ostream& os)
1142{
1144 os << commentStart << page << "GlobalValueList All GlobalValues\n" << std::endl;
1145 os << "This is a list of all" << reference << "ns3::GlobalValue instances.\n"
1146 << "See ns3::GlobalValue for how to set these." << std::endl;
1147
1148 os << listStart << std::endl;
1149 for (auto i = GlobalValue::Begin(); i != GlobalValue::End(); ++i)
1150 {
1151 StringValue val;
1152 (*i)->GetValue(val);
1153 os << indentHtmlOnly << listLineStart << boldStart << hrefStart << (*i)->GetName()
1154 << hrefMid << "GlobalValue" << (*i)->GetName() << hrefStop << boldStop << ": "
1155 << (*i)->GetHelp() << ". Default value: " << val.Get() << "." << listLineStop
1156 << std::endl;
1157 }
1158 os << listStop << std::endl;
1159 os << commentStop << std::endl;
1160
1161} // PrintAllGlobals()
1162
1163/**
1164 * Print the list of all groups
1165 *
1166 * @param [in,out] os The output stream.
1167 */
1168void
1169PrintAllGroups(std::ostream& os)
1170{
1172 os << commentStart << page << "GroupsList All Object Groups\n" << std::endl;
1173 os << "This is a list of all Object Groups.\n"
1174 << "Objects are added to groups by " << hrefStart << "ns3::TypeId::SetGroupName()" << hrefMid
1175 << "ns3::TypeId::SetGroupName" << hrefStop << "\n"
1176 << std::endl;
1177
1178 auto groups = GetGroupsList();
1179
1180 for (const auto& g : groups)
1181 {
1182 os << boldStart << g.first << boldStop << breakHtmlOnly << std::endl;
1183
1184 os << listStart << std::endl;
1185 for (const auto& tid : g.second)
1186 {
1187 os << indentHtmlOnly << listLineStart << hrefStart << tid.GetName() << hrefMid
1188 << tid.GetName() << hrefStop << listLineStop << std::endl;
1189 }
1190 os << listStop << std::endl;
1191 }
1192 os << commentStop << std::endl;
1193}
1194
1195/**
1196 * Print the list of all LogComponents.
1197 *
1198 * @param [in,out] os The output stream.
1199 */
1200void
1201PrintAllLogComponents(std::ostream& os)
1202{
1204 os << commentStart << page << "LogComponentList All LogComponents\n" << std::endl;
1205 os << "This is a list of all" << reference << "ns3::LogComponent instances.\n" << std::endl;
1206
1207 /**
1208 * @todo Switch to a border-less table, so the file links align
1209 * See https://www.doxygen.nl/manual/htmlcmds.html
1210 */
1212 // Find longest log name
1213 std::size_t widthL = std::string("Log Component").size();
1214 std::size_t widthR = std::string("file").size();
1215 for (const auto& it : (*logs))
1216 {
1217 widthL = std::max(widthL, it.first.size());
1218 std::string file = it.second->File();
1219 // Strip leading "../" related to depth in build directory
1220 // since doxygen only sees the path starting with "src/", etc.
1221 while (file.find("../") == 0)
1222 {
1223 file = file.substr(3);
1224 }
1225 widthR = std::max(widthR, file.size());
1226 }
1227 const std::string tLeft("| ");
1228 const std::string tMid(" | ");
1229 const std::string tRight(" |");
1230
1231 // Header line has to be padded to same length as separator line
1232 os << tLeft << std::setw(widthL) << std::left << "Log Component" << tMid << std::setw(widthR)
1233 << std::left << "File" << tRight << std::endl;
1234 os << tLeft << ":" << std::string(widthL - 1, '-') << tMid << ":"
1235 << std::string(widthR - 1, '-') << tRight << std::endl;
1236
1237 for (const auto& it : (*logs))
1238 {
1239 std::string file = it.second->File();
1240 // Strip leading "../" related to depth in build directory
1241 // since doxygen only sees the path starting with "src/", etc.
1242 while (file.find("../") == 0)
1243 {
1244 file = file.substr(3);
1245 }
1246
1247 os << tLeft << std::setw(widthL) << std::left << it.first << tMid << std::setw(widthR)
1248 << file << tRight << std::endl;
1249 }
1250 os << std::right << std::endl;
1251 os << commentStop << std::endl;
1252} // PrintAllLogComponents()
1253
1254/**
1255 * Print the list of all Trace sources.
1256 *
1257 * @param [in,out] os The output stream.
1258 *
1259 * @todo Print this sorted by class (the current version)
1260 * as well as by TraceSource name.
1261 */
1262void
1263PrintAllTraceSources(std::ostream& os)
1264{
1266 os << commentStart << page << "TraceSourceList All TraceSources\n" << std::endl;
1267 os << "This is a list of all" << reference << "tracing sources. "
1268 << "For more information see the " << reference << "tracing "
1269 << "section of this API documentation and the Tracing sections "
1270 << "in the Tutorial and Manual.\n"
1271 << std::endl;
1272
1273 NameMap nameMap = GetNameMap();
1274
1275 // Iterate over the map, which will print the class names in
1276 // alphabetical order.
1277 for (const auto& item : nameMap)
1278 {
1279 // Handle only real TypeIds
1280 if (item.second < 0)
1281 {
1282 continue;
1283 }
1284 // Get the class's index out of the map;
1285 TypeId tid = TypeId::GetRegistered(item.second);
1286
1287 if (tid.GetTraceSourceN() == 0)
1288 {
1289 continue;
1290 }
1291
1292 auto index = SortedTraceSourceInfo(tid);
1293
1294 os << boldStart << tid.GetName() << boldStop << breakHtmlOnly << std::endl;
1295
1296 os << listStart << std::endl;
1297 for (const auto& [name, info] : index)
1298 {
1299 os << listLineStart << boldStart << name << boldStop << ": " << info.help
1300 << listLineStop << std::endl;
1301 }
1302 os << listStop << std::endl;
1303 }
1304 os << commentStop << std::endl;
1305
1306} // PrintAllTraceSources()
1307
1308/***************************************************************
1309 * Docs for Attribute classes
1310 ***************************************************************/
1311
1312/**
1313 * Print the section definition for an AttributeValue.
1314 *
1315 * In doxygen form this will print a comment block with
1316 * @verbatim
1317 * @ingroup attributes
1318 * @defgroup attribute_<name>Value <name>Value
1319 * @endverbatim
1320 *
1321 * @param [in,out] os The output stream.
1322 * @param [in] name The base name of the resulting AttributeValue type.
1323 * @param [in] seeBase Print a "see also" pointing to the base class.
1324 */
1325void
1326PrintAttributeValueSection(std::ostream& os, const std::string& name, const bool seeBase = true)
1327{
1329 std::string section = "attribute_" + name;
1330
1331 // \ingroup attributes
1332 // \defgroup attribute_<name>Value <name> Attribute
1333 os << commentStart << sectionStart << "attributes\n"
1334 << subSectionStart << "attribute_" << name << " " << name << " Attribute\n"
1335 << "AttributeValue implementation for " << name << "\n";
1336 if (seeBase)
1337 {
1338 os << seeAlso << "ns3::" << name << "\n";
1339 }
1340 os << commentStop;
1341
1342} // PrintAttributeValueSection()
1343
1344/**
1345 * Print the AttributeValue documentation for a class.
1346 *
1347 * This will print documentation for the \pname{AttributeValue} class and methods.
1348 *
1349 * @param [in,out] os The output stream.
1350 * @param [in] name The token to use in defining the accessor name.
1351 * @param [in] type The underlying type name.
1352 * @param [in] header The header file which contains this declaration.
1353 */
1354void
1356 const std::string& name,
1357 const std::string& type,
1358 const std::string& header)
1359{
1360 NS_LOG_FUNCTION(name << type << header);
1361 std::string sectAttr = sectionStart + "attribute_" + name;
1362
1363 // \ingroup attribute_<name>Value
1364 // \class ns3::<name>Value "header"
1365 std::string valClass = name + "Value";
1366 std::string qualClass = " ns3::" + valClass;
1367
1368 os << commentStart << sectAttr << std::endl;
1369 os << classStart << qualClass << " \"" << header << "\"" << std::endl;
1370 os << "AttributeValue implementation for " << name << "." << std::endl;
1371 os << seeAlso << "AttributeValue" << std::endl;
1372 os << commentStop;
1373
1374 // Ctor: <name>Value::<name>Value
1375 os << commentStart << functionStart << qualClass << "::" << valClass;
1376 // Constructors
1377 os << "(const " << type << " & value)\n"
1378 << "Constructor.\n"
1379 << argument << "[in] value The " << name << " value to use.\n";
1380 os << commentStop;
1381
1382 // <name>Value::Get() const
1383 os << commentStart << functionStart << type << qualClass << "::Get() const\n"
1384 << returns << "The " << name << " value.\n"
1385 << commentStop;
1386
1387 // <name>Value::GetAccessor(T & value) const
1388 os << commentStart << functionStart << "bool" << qualClass << "::GetAccessor(T & value) const\n"
1389 << "Access the " << name << " value as type " << codeWord << "T.\n"
1390 << templateArgument << "T " << templArgExplicit << "The type to cast to.\n"
1391 << argument << "[out] value The " << name << " value, as type " << codeWord << "T.\n"
1392 << returns << "true.\n"
1393 << commentStop;
1394
1395 // <name>Value::Set(const name & value)
1396 if (type != "Callback") // Yuck
1397 {
1398 os << commentStart << functionStart << "void" << qualClass << "::Set(const " << type
1399 << " & value)\n"
1400 << "Set the value.\n"
1401 << argument << "[in] value The value to adopt.\n"
1402 << commentStop;
1403 }
1404
1405 // <name>Value::m_value
1406 os << commentStart << variable << type << qualClass << "::m_value\n"
1407 << "The stored " << name << " instance.\n"
1408 << commentStop << std::endl;
1409
1410} // PrintAttributeValueWithName()
1411
1412/**
1413 * Print the AttributeValue MakeAccessor documentation for a class.
1414 *
1415 * This will print documentation for the \pname{Make<name>Accessor} functions.
1416 *
1417 * @param [in,out] os The output stream.
1418 * @param [in] name The token to use in defining the accessor name.
1419 */
1420void
1421PrintMakeAccessors(std::ostream& os, const std::string& name)
1422{
1424 std::string sectAttr = sectionStart + "attribute_" + name + "\n";
1425 std::string make = "ns3::Make" + name + "Accessor ";
1426
1427 // \ingroup attribute_<name>Value
1428 // Make<name>Accessor(T1 a1)
1429 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeAccessor> "
1430 << make << "(T1 a1)\n"
1431 << copyDoc << "ns3::MakeAccessorHelper(T1)\n"
1432 << seeAlso << "AttributeAccessor\n"
1433 << commentStop;
1434
1435 // \ingroup attribute_<name>Value
1436 // Make<name>Accessor(T1 a1)
1437 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeAccessor> "
1438 << make << "(T1 a1, T2 a2)\n"
1439 << copyDoc << "ns3::MakeAccessorHelper(T1,T2)\n"
1440 << seeAlso << "AttributeAccessor\n"
1441 << commentStop;
1442} // PrintMakeAccessors()
1443
1444/**
1445 * Print the AttributeValue MakeChecker documentation for a class.
1446 *
1447 * This will print documentation for the \pname{Make<name>Checker} function.
1448 *
1449 * @param [in,out] os The output stream.
1450 * @param [in] name The token to use in defining the accessor name.
1451 * @param [in] header The header file which contains this declaration.
1452 */
1453void
1454PrintMakeChecker(std::ostream& os, const std::string& name, const std::string& header)
1455{
1456 NS_LOG_FUNCTION(name << header);
1457 std::string sectAttr = sectionStart + "attribute_" + name + "\n";
1458 std::string make = "ns3::Make" + name + "Checker ";
1459
1460 // \ingroup attribute_<name>Value
1461 // class <name>Checker
1462 os << commentStart << sectAttr << std::endl;
1463 os << classStart << " ns3::" << name << "Checker"
1464 << " \"" << header << "\"" << std::endl;
1465 os << "AttributeChecker implementation for " << name << "Value." << std::endl;
1466 os << seeAlso << "AttributeChecker" << std::endl;
1467 os << commentStop;
1468
1469 // \ingroup attribute_<name>Value
1470 // Make<name>Checker()
1471 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeChecker> "
1472 << make << "()\n"
1473 << returns << "The AttributeChecker.\n"
1474 << seeAlso << "AttributeChecker\n"
1475 << commentStop;
1476} // PrintMakeChecker()
1477
1478/**Descriptor for an AttributeValue. */
1480{
1481 const std::string m_name; //!< The base name of the resulting AttributeValue type.
1482 const std::string m_type; //!< The name of the underlying type.
1483 const bool m_seeBase; //!< Print a "see also" pointing to the base class.
1484 const std::string m_header; //!< The header file name.
1485};
1486
1487/**
1488 * Print documentation corresponding to use of the
1489 * ATTRIBUTE_HELPER_HEADER macro or
1490 * ATTRIBUTE_VALUE_DEFINE_WITH_NAME macro.
1491 *
1492 * @param [in,out] os The output stream.
1493 * @param [in] attr The AttributeDescriptor.
1494 */
1495void
1496PrintAttributeHelper(std::ostream& os, const AttributeDescriptor& attr)
1497{
1498 NS_LOG_FUNCTION(attr.m_name << attr.m_type << attr.m_seeBase << attr.m_header);
1500 PrintAttributeValueWithName(os, attr.m_name, attr.m_type, attr.m_header);
1501 PrintMakeAccessors(os, attr.m_name);
1502 PrintMakeChecker(os, attr.m_name, attr.m_header);
1503} // PrintAttributeHelper()
1504
1505/**
1506 * Print documentation for Attribute implementations.
1507 * @param os The stream to print on.
1508 */
1509void
1511{
1513
1514 // clang-format off
1515 const AttributeDescriptor attributes [] =
1516 {
1517 // Name Type see Base header-file
1518 // Users of ATTRIBUTE_HELPER_HEADER
1519 //
1520 { "Address", "Address", true, "address.h" },
1521 { "Box", "Box", true, "box.h" },
1522 { "DataRate", "DataRate", true, "data-rate.h" },
1523 { "Length", "Length", true, "length.h" },
1524 { "Ipv4Address", "Ipv4Address", true, "ipv4-address.h" },
1525 { "Ipv4Mask", "Ipv4Mask", true, "ipv4-address.h" },
1526 { "Ipv6Address", "Ipv6Address", true, "ipv6-address.h" },
1527 { "Ipv6Prefix", "Ipv6Prefix", true, "ipv6-address.h" },
1528 { "Mac16Address", "Mac16Address", true, "mac16-address.h" },
1529 { "Mac48Address", "Mac48Address", true, "mac48-address.h" },
1530 { "Mac64Address", "Mac64Address", true, "mac64-address.h" },
1531 { "ObjectFactory", "ObjectFactory", true, "object-factory.h" },
1532 { "Priomap", "Priomap", true, "prio-queue-disc.h" },
1533 { "QueueSize", "QueueSize", true, "queue-size.h" },
1534 { "Rectangle", "Rectangle", true, "rectangle.h" },
1535 { "Ssid", "Ssid", true, "ssid.h" },
1536 { "TypeId", "TypeId", true, "type-id.h" },
1537 { "UanModesList", "UanModesList", true, "uan-tx-mode.h" },
1538 { "ValueClassTest", "ValueClassTest", false, "attribute-test-suite.cc" /* core/test/ */ },
1539 { "Vector2D", "Vector2D", true, "vector.h" },
1540 { "Vector3D", "Vector3D", true, "vector.h" },
1541 { "Waypoint", "Waypoint", true, "waypoint.h" },
1542 { "WifiMode", "WifiMode", true, "wifi-mode.h" },
1543
1544 // All three (Value, Access and Checkers) defined, but custom
1545 { "Boolean", "bool", false, "boolean.h" },
1546 { "Callback", "CallbackBase", true, "callback.h" },
1547 { "Double", "double", false, "double.h" },
1548 { "Enum", "T", false, "enum.h" },
1549 { "Integer", "int64_t", false, "integer.h" },
1550 { "String", "std::string", false, "string.h" },
1551 { "Time", "Time", true, "nstime.h" },
1552 { "Uinteger", "uint64_t", false, "uinteger.h" },
1553 { "", "", false, "last placeholder" }
1554 };
1555 // clang-format on
1556
1557 int i = 0;
1558 while (!attributes[i].m_name.empty())
1559 {
1560 PrintAttributeHelper(os, attributes[i]);
1561 ++i;
1562 }
1563
1564 PrintAttributeValueSection(os, "ObjectVector", false);
1565 PrintMakeAccessors(os, "ObjectVector");
1566 PrintMakeChecker(os, "ObjectVector", "object-vector.h");
1567
1568 PrintAttributeValueSection(os, "ObjectMap", false);
1569 PrintMakeAccessors(os, "ObjectMap");
1570 PrintMakeChecker(os, "ObjectMap", "object-map.h");
1571
1572} // PrintAttributeImplementations()
1573
1574/***************************************************************
1575 * Main
1576 ***************************************************************/
1577
1578int
1579main(int argc, char* argv[])
1580{
1582
1583 std::string typeId;
1584
1585 CommandLine cmd(__FILE__);
1586 cmd.Usage("Generate documentation for all ns-3 registered types, "
1587 "trace sources, attributes and global variables.");
1588 cmd.AddValue("output-text", "format output as plain text", outputText);
1589 cmd.AddValue("TypeId", "Print docs for just the given TypeId", typeId);
1590 cmd.Parse(argc, argv);
1591
1592 if (!typeId.empty())
1593 {
1594 outputText = true;
1595 SetMarkup();
1596
1597 TypeId tid;
1598
1599 bool validTypeId = TypeId::LookupByNameFailSafe(typeId, &tid);
1600 if (!validTypeId)
1601 {
1602 auto fqTypeId = "ns3::" + typeId;
1603 validTypeId = TypeId::LookupByNameFailSafe(fqTypeId, &tid);
1604 if (validTypeId)
1605 {
1606 std::cout << "\nFound fully qualified name " << fqTypeId << "\n\n";
1607 }
1608 }
1609 if (validTypeId)
1610 {
1611 PrintTypeIdBlock(std::cout, tid);
1612 return 0;
1613 }
1614 else
1615 {
1616 std::cerr << "Invalid TypeId name: " << typeId << "\n" << std::endl;
1617 std::cerr << cmd;
1618 exit(1);
1619 }
1620 }
1621
1622 SetMarkup();
1623
1624 // Create a Node, to force linking and instantiation of our TypeIds
1625 NodeContainer c;
1626 c.Create(1);
1627
1628 std::cout << std::endl;
1629 std::cout << commentStart << file << "\n"
1630 << sectionStart << "utils\n"
1631 << "Doxygen docs generated from the TypeId database.\n"
1632 << note << "This file is automatically generated by " << codeWord
1633 << "print-introspected-doxygen.cc. Do not edit this file! "
1634 << "Edit that file instead.\n"
1635 << commentStop << std::endl;
1636
1637 PrintTypeIdBlocks(std::cout);
1638
1639 PrintAllTypeIds(std::cout);
1640 PrintAllAttributes(std::cout);
1641 PrintAllGlobals(std::cout);
1642 PrintAllGroups(std::cout);
1643 PrintAllLogComponents(std::cout);
1644 PrintAllTraceSources(std::cout);
1646
1647 return 0;
1648}
Gather aggregation and configuration path information from registered types.
void DoGather(TypeId tid)
Gather attribute, configuration path information for tid.
std::vector< std::pair< TypeId, std::string > > m_output
Configuration path for each TypeId.
void Print(std::ostream &os) const
Print output in "a -> b" form on the stream.
std::vector< TypeId > m_alreadyProcessed
List of TypeIds we've already processed.
std::vector< std::string > m_noTids
List of type names without TypeIds, because those modules aren't enabled.
std::vector< std::string > m_currentPath
Current configuration path.
std::vector< std::string > GetNoTypeIds() const
bool HasAlreadyBeenProcessed(TypeId tid) const
void RecordAggregationInfo(std::string a, std::string b)
Record the a -> b aggregation relation.
std::vector< std::pair< TypeId, TypeId > > m_aggregates
List of aggregation relationships.
std::string GetCurrentPath() const
void Gather(TypeId tid)
Gather aggregation and configuration path information for tid.
std::vector< std::string > Get(TypeId tid) const
void RecordOutput(TypeId tid)
Record the current config path for tid.
Parse command-line arguments.
static Iterator Begin()
The Begin iterator.
static Iterator End()
The End iterator.
static ComponentList * GetComponentList()
Get the list of LogComponents.
Definition log.cc:132
std::unordered_map< std::string, LogComponent * > ComponentList
LogComponent name map.
Definition log.h:387
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static TypeId GetTypeId()
Register this type.
Definition object.cc:90
AttributeChecker implementation for ObjectPtrContainerValue.
AttributeChecker implementation for PointerValue.
Definition pointer.h:114
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Definition string.h:45
std::string Get() const
Definition string.cc:20
a unique identifier for an interface.
Definition type-id.h:49
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
Definition type-id.cc:1041
std::size_t GetTraceSourceN() const
Get the number of Trace sources.
Definition type-id.cc:1193
bool MustHideFromDocumentation() const
Check if this TypeId should not be listed in documentation.
Definition type-id.cc:1162
AttributeFlag
Flags describing when a given attribute can be read or written.
Definition type-id.h:53
@ ATTR_GET
The attribute can be read.
Definition type-id.h:54
@ ATTR_SET
The attribute can be written.
Definition type-id.h:55
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
Definition type-id.h:56
TypeId::TraceSourceInformation GetTraceSource(std::size_t i) const
Get the trace source by index.
Definition type-id.cc:1200
std::string GetGroupName() const
Get the group name.
Definition type-id.cc:1053
static uint16_t GetRegisteredN()
Get the number of registered TypeIds.
Definition type-id.cc:926
std::size_t GetAttributeN() const
Get the number of attributes.
Definition type-id.cc:1170
TypeId GetParent() const
Get the parent of this TypeId.
Definition type-id.cc:1025
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition type-id.cc:933
std::size_t GetSize() const
Get the size of this object.
Definition type-id.cc:1076
TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition type-id.cc:1178
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition type-id.cc:886
SupportLevel
The level of support or deprecation for attributes or trace sources.
Definition type-id.h:63
std::string GetName() const
Get the name.
Definition type-id.cc:1061
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition config.cc:1022
std::size_t GetRootNamespaceObjectN()
Definition config.cc:1015
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
std::string headingStart
start of section heading (h3)
std::string copyDoc
copy (or refer) to docs elsewhere
std::map< std::string, ns3::TypeId::TraceSourceInformation > SortedTraceSourceInfo(const TypeId tid)
Alphabetize the TraceSourceInformation for a TypeId by the TraceSource name.
std::string breakHtmlOnly
linebreak for html output only
std::map< std::string, ns3::TypeId::AttributeInformation > SortedAttributeInfo(const TypeId tid)
Alphabetize the AttributeInformation for a TypeId by the Attribute name.
std::string codeWord
format next word as source code
std::string breakTextOnly
linebreak for text output only
std::string flagSpanStart
start of Attribute flag value
std::string templArgDeduced
template argument deduced from function
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition ptr.h:443
StaticInformation GetTypicalAggregations()
Register aggregation relationships that are not automatically detected by this introspection program.
void PrintTraceSourcesTid(std::ostream &os, const TypeId tid)
Print direct Trace sources for this TypeId.
std::set< TypeId > GroupList_t
List of TypeIds for a group.
std::map< std::string, int32_t > NameMap
Map from TypeId name to tid.
void PrintMakeAccessors(std::ostream &os, const std::string &name)
Print the AttributeValue MakeAccessor documentation for a class.
void PrintAllTraceSources(std::ostream &os)
Print the list of all Trace sources.
void PrintAllLogComponents(std::ostream &os)
Print the list of all LogComponents.
void PrintAttributeHelper(std::ostream &os, const AttributeDescriptor &attr)
Print documentation corresponding to use of the ATTRIBUTE_HELPER_HEADER macro or ATTRIBUTE_VALUE_DEFI...
void PrintTypeIdBlock(std::ostream &os, const TypeId tid)
Print the doxy block for a single TypeId.
void PrintTypeIdBlocks(std::ostream &os)
Print the doxy block for each TypeId.
std::map< std::string, GroupList_t > GroupsList_t
Collection of group names with associated TypeIds.
void PrintAllAttributes(std::ostream &os)
Print the list of all Attributes.
void PrintAttributeValueWithName(std::ostream &os, const std::string &name, const std::string &type, const std::string &header)
Print the AttributeValue documentation for a class.
GroupsList_t GetGroupsList()
Get a sorted list of TypeId groups.
void PrintSupportLevel(std::ostream &os, TypeId::SupportLevel supportLevel, std::string supportMsg)
Print the support level for an Attribute or TraceSource.
void PrintSize(std::ostream &os, const TypeId tid)
Print the size of the type represented by this tid.
void Uniquefy(T t)
Helper to keep only the unique items in a container.
void PrintAttributeImplementations(std::ostream &os)
Print documentation for Attribute implementations.
NameMap GetNameMap()
Create a map from the class names to their index in the vector of TypeId's so that the names will end...
void PrintTraceSources(std::ostream &os, const TypeId tid)
Print the Trace sources block for tid, including Trace sources declared in base classes.
void SetMarkup()
Initialize the markup strings, for either doxygen or text.
NameMap::const_iterator NameMapIterator
NameMap iterator.
void PrintConfigPaths(std::ostream &os, const TypeId tid)
Print config paths.
void PrintAllTypeIds(std::ostream &os)
Print the list of all TypeIds.
void PrintAttributes(std::ostream &os, const TypeId tid)
Print the Attributes block for tid, including Attributes declared in base classes.
void PrintAllGroups(std::ostream &os)
Print the list of all groups.
void PrintAllGlobals(std::ostream &os)
Print the list of all global variables.
void PrintMakeChecker(std::ostream &os, const std::string &name, const std::string &header)
Print the AttributeValue MakeChecker documentation for a class.
void PrintAttributeValueSection(std::ostream &os, const std::string &name, const bool seeBase=true)
Print the section definition for an AttributeValue.
void PrintAttributesTid(std::ostream &os, const TypeId tid)
Print direct Attributes for this TypeId.
Descriptor for an AttributeValue.
const std::string m_header
The header file name.
const std::string m_type
The name of the underlying type.
const std::string m_name
The base name of the resulting AttributeValue type.
const bool m_seeBase
Print a "see also" pointing to the base class.
Attribute implementation.
Definition type-id.h:86
TypeId::SupportLevel supportLevel
Support level/deprecation.
Definition type-id.h:102
std::string name
Attribute name.
Definition type-id.h:88
Ptr< const AttributeChecker > checker
Checker object.
Definition type-id.h:100
std::string supportMsg
Support message.
Definition type-id.h:104
TraceSource implementation.
Definition type-id.h:109
std::string name
Trace name.
Definition type-id.h:111