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}; // class StaticInformation
317
318void
319StaticInformation::RecordAggregationInfo(std::string a, std::string b)
320{
321 NS_LOG_FUNCTION(this << a << b);
322 TypeId aTid;
323 bool found = TypeId::LookupByNameFailSafe(a, &aTid);
324 if (!found)
325 {
326 m_noTids.push_back(a);
327 return;
328 }
329 TypeId bTid;
330 found = TypeId::LookupByNameFailSafe(b, &bTid);
331 if (!found)
332 {
333 m_noTids.push_back(b);
334 return;
335 }
336
337 m_aggregates.emplace_back(aTid, bTid);
338}
339
340void
341StaticInformation::Print(std::ostream& os) const
342{
343 NS_LOG_FUNCTION(this);
344 for (const auto& item : m_output)
345 {
346 os << item.first.GetName() << " -> " << item.second << std::endl;
347 }
348}
349
350std::string
352{
353 NS_LOG_FUNCTION(this);
354 std::ostringstream oss;
355 for (const auto& item : m_currentPath)
356 {
357 oss << "/" << item;
358 }
359 return oss.str();
360}
361
362void
364{
365 NS_LOG_FUNCTION(this << tid);
366 m_output.emplace_back(tid, GetCurrentPath());
367}
368
369bool
371{
372 NS_LOG_FUNCTION(this << tid);
373 for (const auto& it : m_alreadyProcessed)
374 {
375 if (it == tid)
376 {
377 return true;
378 }
379 }
380 return false;
381}
382
383std::vector<std::string>
385{
386 NS_LOG_FUNCTION(this << tid);
387 std::vector<std::string> paths;
388 for (const auto& item : m_output)
389 {
390 if (item.first == tid)
391 {
392 paths.push_back(item.second);
393 }
394 }
395 return paths;
396}
397
398/**
399 * Helper to keep only the unique items in a container.
400 *
401 * The container is modified in place; the elements end up sorted.
402 *
403 * The container must support \c begin(), \c end() and \c erase(),
404 * which, among the STL containers, limits this to
405 * \c std::vector, \c std::dequeue and \c std::list.
406 *
407 * The container elements must support \c operator< (for \c std::sort)
408 * and \c operator== (for \c std::unique).
409 *
410 * @tparam T \deduced The container type.
411 * @param t The container.
412 */
413template <typename T>
414void
416{
417 std::sort(t.begin(), t.end());
418 t.erase(std::unique(t.begin(), t.end()), t.end());
419}
420
421std::vector<std::string>
423{
424 NS_LOG_FUNCTION(this);
426 return m_noTids;
427}
428
429void
431{
432 NS_LOG_FUNCTION(this << tid);
433 DoGather(tid);
435}
436
437void
439{
440 NS_LOG_FUNCTION(this << tid);
442 {
443 return;
444 }
445 RecordOutput(tid);
446 for (uint32_t i = 0; i < tid.GetAttributeN(); ++i)
447 {
448 struct TypeId::AttributeInformation info = tid.GetAttribute(i);
449 const auto ptrChecker = dynamic_cast<const PointerChecker*>(PeekPointer(info.checker));
450 if (ptrChecker != nullptr)
451 {
452 TypeId pointee = ptrChecker->GetPointeeTypeId();
453
454 // See if this is a pointer to an Object.
456 TypeId objectTypeId = Object::GetTypeId();
457 if (objectTypeId == pointee)
458 {
459 // Stop the recursion at this attribute if it is a
460 // pointer to an Object, which create too many spurious
461 // paths in the list of attribute paths because any
462 // Object can be in that part of the path.
463 continue;
464 }
465
466 m_currentPath.push_back(info.name);
467 m_alreadyProcessed.push_back(tid);
468 DoGather(pointee);
469 m_alreadyProcessed.pop_back();
470 m_currentPath.pop_back();
471 continue;
472 }
473 // attempt to cast to an object vector.
474 const auto vectorChecker =
475 dynamic_cast<const ObjectPtrContainerChecker*>(PeekPointer(info.checker));
476 if (vectorChecker != nullptr)
477 {
478 TypeId item = vectorChecker->GetItemTypeId();
479 m_currentPath.push_back(info.name + "/[i]");
480 m_alreadyProcessed.push_back(tid);
481 DoGather(item);
482 m_alreadyProcessed.pop_back();
483 m_currentPath.pop_back();
484 continue;
485 }
486 }
487 for (uint32_t j = 0; j < TypeId::GetRegisteredN(); j++)
488 {
489 TypeId child = TypeId::GetRegistered(j);
490 if (child.IsChildOf(tid))
491 {
492 std::string childName = "$" + child.GetName();
493 m_currentPath.push_back(childName);
494 m_alreadyProcessed.push_back(tid);
495 DoGather(child);
496 m_alreadyProcessed.pop_back();
497 m_currentPath.pop_back();
498 }
499 }
500 for (const auto& item : m_aggregates)
501 {
502 if (item.first == tid || item.second == tid)
503 {
504 TypeId other;
505 if (item.first == tid)
506 {
507 other = item.second;
508 }
509 if (item.second == tid)
510 {
511 other = item.first;
512 }
513 std::string name = "$" + other.GetName();
514 m_currentPath.push_back(name);
515 m_alreadyProcessed.push_back(tid);
516 DoGather(other);
517 m_alreadyProcessed.pop_back();
518 m_currentPath.pop_back();
519 }
520 }
521} // StaticInformation::DoGather()
522
523/// Register aggregation relationships that are not automatically
524/// detected by this introspection program. Statements added here
525/// result in more configuration paths being added to the doxygen.
526/// @return instance of StaticInformation with the registered information
529{
531
532 static StaticInformation info;
533 static bool mapped = false;
534
535 if (mapped)
536 {
537 return info;
538 }
539
540 // Short circuit next call
541 mapped = true;
542
543 // The below statements register typical aggregation relationships
544 // in ns-3 programs, that otherwise aren't picked up automatically
545 // by the creation of the above node. To manually list other common
546 // aggregation relationships that you would like to see show up in
547 // the list of configuration paths in the doxygen, add additional
548 // statements below.
549 info.RecordAggregationInfo("ns3::Node", "ns3::TcpSocketFactory");
550 info.RecordAggregationInfo("ns3::Node", "ns3::UdpSocketFactory");
551 info.RecordAggregationInfo("ns3::Node", "ns3::PacketSocketFactory");
552 info.RecordAggregationInfo("ns3::Node", "ns3::MobilityModel");
553 info.RecordAggregationInfo("ns3::Node", "ns3::Ipv4L3Protocol");
554 info.RecordAggregationInfo("ns3::Node", "ns3::Ipv4NixVectorRouting");
555 info.RecordAggregationInfo("ns3::Node", "ns3::Icmpv4L4Protocol");
556 info.RecordAggregationInfo("ns3::Node", "ns3::ArpL3Protocol");
557 info.RecordAggregationInfo("ns3::Node", "ns3::Icmpv4L4Protocol");
558 info.RecordAggregationInfo("ns3::Node", "ns3::UdpL4Protocol");
559 info.RecordAggregationInfo("ns3::Node", "ns3::Ipv6L3Protocol");
560 info.RecordAggregationInfo("ns3::Node", "ns3::Icmpv6L4Protocol");
561 info.RecordAggregationInfo("ns3::Node", "ns3::TcpL4Protocol");
562 info.RecordAggregationInfo("ns3::Node", "ns3::RipNg");
563 info.RecordAggregationInfo("ns3::Node", "ns3::GlobalRouter");
564 info.RecordAggregationInfo("ns3::Node", "ns3::aodv::RoutingProtocol");
565 info.RecordAggregationInfo("ns3::Node", "ns3::dsdv::RoutingProtocol");
566 info.RecordAggregationInfo("ns3::Node", "ns3::dsr::DsrRouting");
567 info.RecordAggregationInfo("ns3::Node", "ns3::olsr::RoutingProtocol");
568 info.RecordAggregationInfo("ns3::Node", "ns3::energy::EnergyHarvesterContainer");
569 info.RecordAggregationInfo("ns3::Node", "ns3::energy::EnergySourceContainer");
570
571 // Create a channel object so that channels appear in the namespace
572 // paths that will be generated here.
573 Ptr<SimpleChannel> simpleChannel;
574 simpleChannel = CreateObject<SimpleChannel>();
575
576 for (uint32_t i = 0; i < Config::GetRootNamespaceObjectN(); ++i)
577 {
579 info.Gather(object->GetInstanceTypeId());
580 }
581
582 return info;
583
584} // GetTypicalAggregations()
585
586/// Map from TypeId name to tid
587typedef std::map<std::string, int32_t> NameMap;
588typedef NameMap::const_iterator NameMapIterator; ///< NameMap iterator
589
590/**
591 * Create a map from the class names to their index in the vector of
592 * TypeId's so that the names will end up in alphabetical order.
593 *
594 * @returns NameMap
595 */
598{
600
601 static NameMap nameMap;
602 static bool mapped = false;
603
604 if (mapped)
605 {
606 return nameMap;
607 }
608
609 // Short circuit next call
610 mapped = true;
611
612 // Get typical aggregation relationships.
614
615 // Registered types
616 for (uint32_t i = 0; i < TypeId::GetRegisteredN(); i++)
617 {
620 {
621 continue;
622 }
623
624 // Capitalize all of letters in the name so that it sorts
625 // correctly in the map.
626 std::string name = tid.GetName();
627 std::transform(name.begin(), name.end(), name.begin(), ::toupper);
628
629 // Save this name's index.
630 nameMap[name] = i;
631 }
632
633 // Type names without TypeIds
634 std::vector<std::string> noTids = info.GetNoTypeIds();
635 for (const auto& item : noTids)
636 {
637 nameMap[item] = -1;
638 }
639
640 return nameMap;
641} // GetNameMap()
642
643/// List of TypeIds for a group
644using GroupList_t = std::set<TypeId>;
645/// Collection of group names with associated TypeIds
646using GroupsList_t = std::map<std::string, GroupList_t>;
647
648/**
649 * Get a sorted list of TypeId groups
650 * @returns a map of group name and associated TypeIds
651 */
654{
655 static GroupsList_t groups;
656 static bool mapped = false;
657 if (mapped)
658 {
659 return groups;
660 }
661
662 NameMap nameMap = GetNameMap();
663 for (const auto& item : nameMap)
664 {
665 // Handle only real TypeIds
666 if (item.second < 0)
667 {
668 continue;
669 }
670 // Get the class's index out of the map;
671 TypeId tid = TypeId::GetRegistered(item.second);
672 auto group = tid.GetGroupName();
673
674 if (!group.empty())
675 {
676 groups[group].insert(tid);
677 }
678 }
679 return groups;
680
681} // GetGroupsList()
682
683/***************************************************************
684 * Docs for a single TypeId
685 ***************************************************************/
686
687/**
688 * Print the support level for an Attribute or TraceSource
689 * @param os the output stream
690 * @param supportLevel the SupportLevel
691 * @param supportMsg optional support message
692 */
693void
695{
696 os << " " << listLineStart << "Support level: ";
698
699 if (!supportMsg.empty())
700 {
701 os << ": " << supportMsg;
702 }
703 os << listLineStop << std::endl;
704} // PrintSupportLevel
705
706/**
707 * Print config paths
708 * @param os the output stream
709 * @param tid the type ID
710 */
711void
712PrintConfigPaths(std::ostream& os, const TypeId tid)
713{
714 NS_LOG_FUNCTION(tid);
715 std::vector<std::string> paths = GetTypicalAggregations().Get(tid);
716
717 // Config --------------
718 if (paths.empty())
719 {
720 os << "Introspection did not find any typical Config paths." << breakBoth << std::endl;
721 }
722 else
723 {
724 os << headingStart << "Config Paths" << headingStop << std::endl;
725 os << std::endl;
726 os << tid.GetName() << " is accessible through the following paths"
727 << " with Config::Set and Config::Connect:" << std::endl;
728 os << listStart << std::endl;
729 for (const auto& path : paths)
730 {
731 os << listLineStart << "\"" << path << "\"" << listLineStop << breakTextOnly
732 << std::endl;
733 }
734 os << listStop << std::endl;
735 }
736} // PrintConfigPaths()
737
738/**
739 * Print direct Attributes for this TypeId.
740 *
741 * Only attributes defined directly by this TypeId will be printed.
742 *
743 * @param [in,out] os The output stream.
744 * @param [in] tid The TypeId to print.
745 */
746void
747PrintAttributesTid(std::ostream& os, const TypeId tid)
748{
749 NS_LOG_FUNCTION(tid);
750
751 auto index = SortedAttributeInfo(tid);
752
753 os << listStart << std::endl;
754 for (const auto& [name, info] : index)
755 {
756 os << listLineStart << boldStart << name << boldStop << ": " << info.help << std::endl;
757 os << indentHtmlOnly << listStart << std::endl;
758 os << " " << listLineStart << "Set with class: " << reference
759 << info.checker->GetValueTypeName() << listLineStop << std::endl;
760
761 std::string underType;
762 if (info.checker->HasUnderlyingTypeInformation())
763 {
764 os << " " << listLineStart << "Underlying type: ";
765
766 std::string valType = info.checker->GetValueTypeName();
767 underType = info.checker->GetUnderlyingTypeInformation();
768 bool handled = false;
769 if ((valType != "ns3::EnumValue") && (underType != "std::string"))
770 {
771 // Indirect cases to handle
772 if (valType == "ns3::PointerValue")
773 {
774 const auto ptrChecker =
775 dynamic_cast<const PointerChecker*>(PeekPointer(info.checker));
776 if (ptrChecker != nullptr)
777 {
778 os << reference << "ns3::Ptr"
779 << "< " << reference << ptrChecker->GetPointeeTypeId().GetName() << ">";
780 handled = true;
781 }
782 }
783 else if (valType == "ns3::ObjectPtrContainerValue")
784 {
785 const auto ptrChecker =
786 dynamic_cast<const ObjectPtrContainerChecker*>(PeekPointer(info.checker));
787 if (ptrChecker != nullptr)
788 {
789 os << reference << "ns3::Ptr"
790 << "< " << reference << ptrChecker->GetItemTypeId().GetName() << ">";
791 handled = true;
792 }
793 }
794
795 // Helper to match first part of string
796 auto match = [&uType = std::as_const(underType)](const std::string& s) {
797 return uType.rfind(s, 0) == 0; // only checks position 0
798 };
799
800 if (match("bool") || match("double") || match("int8_t") || match("uint8_t") ||
801 match("int16_t") || match("uint16_t") || match("int32_t") ||
802 match("uint32_t") || match("int64_t") || match("uint64_t"))
803 {
804 os << underType;
805 handled = true;
806 }
807 }
808 if (!handled)
809 {
810 os << codeWord << underType;
811 }
812 os << listLineStop << std::endl;
813 }
814 if (info.flags & TypeId::ATTR_CONSTRUCT && info.accessor->HasSetter())
815 {
816 std::string value = info.initialValue->SerializeToString(info.checker);
817 if (underType == "std::string" && value.empty())
818 {
819 value = "\"\"";
820 }
821 os << " " << listLineStart << "Initial value: " << value << listLineStop
822 << std::endl;
823 }
824 bool moreFlags{false};
825 os << " " << listLineStart << "Flags: ";
826
827 auto myInfo = info; // See GitLab #1142
828 auto flagWrite = [&os, &moreFlags, myInfo](TypeId::AttributeFlag flag,
829 bool hasFunc,
830 std::string msg) -> void {
831 if (myInfo.flags & flag && hasFunc)
832 {
833 os << (outputText && moreFlags ? ", " : "") << flagSpanStart << msg << flagSpanStop;
834 moreFlags = true;
835 }
836 };
837 flagWrite(TypeId::ATTR_CONSTRUCT, info.accessor->HasSetter(), "construct");
838 flagWrite(TypeId::ATTR_SET, info.accessor->HasSetter(), "write");
839 flagWrite(TypeId::ATTR_GET, info.accessor->HasGetter(), "read");
840 os << listLineStop << std::endl;
841
842 PrintSupportLevel(os, info.supportLevel, info.supportMsg);
843
844 os << indentHtmlOnly << listStop << std::endl;
845 }
846 os << listStop << std::endl;
847} // PrintAttributesTid()
848
849/**
850 * Print the Attributes block for tid,
851 * including Attributes declared in base classes.
852 *
853 * All Attributes of this TypeId will be printed,
854 * including those defined in parent classes.
855 *
856 * @param [in,out] os The output stream.
857 * @param [in] tid The TypeId to print.
858 */
859void
860PrintAttributes(std::ostream& os, const TypeId tid)
861{
862 NS_LOG_FUNCTION(tid);
863 if (tid.GetAttributeN() == 0)
864 {
865 os << "No Attributes are defined for this type." << breakBoth << std::endl;
866 }
867 else
868 {
869 os << headingStart << "Attributes" << headingStop << std::endl;
870 PrintAttributesTid(os, tid);
871 }
872
873 // Attributes from base classes
874 TypeId tmp = tid.GetParent();
875 while (tmp.GetParent() != tmp)
876 {
877 if (tmp.GetAttributeN() != 0)
878 {
879 os << headingStart << "Attributes defined in parent class " << tmp.GetName()
880 << headingStop << std::endl;
881 PrintAttributesTid(os, tmp);
882 }
883 tmp = tmp.GetParent();
884
885 } // Attributes
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 } // for class documentation
1038
1039} // PrintTypeIdBlocks()
1040
1041/***************************************************************
1042 * Lists of All things
1043 ***************************************************************/
1044
1045/**
1046 * Print the list of all TypeIds
1047 *
1048 * @param [in,out] os The output stream.
1049 */
1050void
1051PrintAllTypeIds(std::ostream& os)
1052{
1054 os << commentStart << page << "TypeIdList All ns3::TypeId's\n" << std::endl;
1055 os << "This is a list of all" << reference << "ns3::TypeId's.\n"
1056 << "For more information see the" << reference << "ns3::TypeId "
1057 << "section of this API documentation and the" << referenceNo << "TypeId section "
1058 << "in the Configuration and " << referenceNo << "Attributes chapter of the Manual.\n"
1059 << std::endl;
1060
1061 os << listStart << std::endl;
1062
1063 NameMap nameMap = GetNameMap();
1064 // Iterate over the map, which will print the class names in
1065 // alphabetical order.
1066 for (const auto& item : nameMap)
1067 {
1068 // Handle only real TypeIds
1069 if (item.second < 0)
1070 {
1071 continue;
1072 }
1073 // Get the class's index out of the map;
1074 TypeId tid = TypeId::GetRegistered(item.second);
1075
1076 os << indentHtmlOnly << listLineStart << boldStart << tid.GetName() << boldStop
1077 << listLineStop << std::endl;
1078 }
1079 os << listStop << std::endl;
1080 os << commentStop << std::endl;
1081
1082} // PrintAllTypeIds()
1083
1084/**
1085 * Print the list of all Attributes.
1086 *
1087 * @param [in,out] os The output stream.
1088 *
1089 * @todo Print this sorted by class (the current version)
1090 * as well as by Attribute name.
1091 */
1092void
1093PrintAllAttributes(std::ostream& os)
1094{
1096 os << commentStart << page << "AttributeList All Attributes\n" << std::endl;
1097 os << "This is a list of all" << reference << "attributes classes. "
1098 << "For more information see the" << reference << "attributes "
1099 << "section of this API documentation and the Attributes sections "
1100 << "in the Tutorial and Manual.\n"
1101 << std::endl;
1102
1103 NameMap nameMap = GetNameMap();
1104 // Iterate over the map, which will print the class names in
1105 // alphabetical order.
1106 for (const auto& item : nameMap)
1107 {
1108 // Handle only real TypeIds
1109 if (item.second < 0)
1110 {
1111 continue;
1112 }
1113 // Get the class's index out of the map;
1114 TypeId tid = TypeId::GetRegistered(item.second);
1115
1116 if (tid.GetAttributeN() == 0)
1117 {
1118 continue;
1119 }
1120
1121 auto index = SortedAttributeInfo(tid);
1122
1123 os << boldStart << tid.GetName() << boldStop << breakHtmlOnly << std::endl;
1124 os << listStart << std::endl;
1125 for (const auto& [name, info] : index)
1126 {
1127 os << listLineStart << boldStart << name << boldStop << ": " << info.help
1128 << listLineStop << std::endl;
1129 }
1130 os << listStop << std::endl;
1131 }
1132 os << commentStop << std::endl;
1133
1134} // PrintAllAttributes()
1135
1136/**
1137 * Print the list of all global variables.
1138 *
1139 * @param [in,out] os The output stream.
1140 */
1141void
1142PrintAllGlobals(std::ostream& os)
1143{
1145 os << commentStart << page << "GlobalValueList All GlobalValues\n" << std::endl;
1146 os << "This is a list of all" << reference << "ns3::GlobalValue instances.\n"
1147 << "See ns3::GlobalValue for how to set these." << std::endl;
1148
1149 os << listStart << std::endl;
1150 for (auto i = GlobalValue::Begin(); i != GlobalValue::End(); ++i)
1151 {
1152 StringValue val;
1153 (*i)->GetValue(val);
1154 os << indentHtmlOnly << listLineStart << boldStart << hrefStart << (*i)->GetName()
1155 << hrefMid << "GlobalValue" << (*i)->GetName() << hrefStop << boldStop << ": "
1156 << (*i)->GetHelp() << ". Default value: " << val.Get() << "." << listLineStop
1157 << std::endl;
1158 }
1159 os << listStop << std::endl;
1160 os << commentStop << std::endl;
1161
1162} // PrintAllGlobals()
1163
1164/**
1165 * Print the list of all groups
1166 *
1167 * @param [in,out] os The output stream.
1168 */
1169void
1170PrintAllGroups(std::ostream& os)
1171{
1173 os << commentStart << page << "GroupsList All Object Groups\n" << std::endl;
1174 os << "This is a list of all Object Groups.\n"
1175 << "Objects are added to groups by " << hrefStart << "ns3::TypeId::SetGroupName()" << hrefMid
1176 << "ns3::TypeId::SetGroupName" << hrefStop << "\n"
1177 << std::endl;
1178
1179 auto groups = GetGroupsList();
1180
1181 for (const auto& g : groups)
1182 {
1183 os << boldStart << g.first << boldStop << breakHtmlOnly << std::endl;
1184
1185 os << listStart << std::endl;
1186 for (const auto& tid : g.second)
1187 {
1188 os << indentHtmlOnly << listLineStart << hrefStart << tid.GetName() << hrefMid
1189 << tid.GetName() << hrefStop << listLineStop << std::endl;
1190 }
1191 os << listStop << std::endl;
1192 }
1193 os << commentStop << std::endl;
1194}
1195
1196/**
1197 * Print the list of all LogComponents.
1198 *
1199 * @param [in,out] os The output stream.
1200 */
1201void
1202PrintAllLogComponents(std::ostream& os)
1203{
1205 os << commentStart << page << "LogComponentList All LogComponents\n" << std::endl;
1206 os << "This is a list of all" << reference << "ns3::LogComponent instances.\n" << std::endl;
1207
1208 /**
1209 * @todo Switch to a border-less table, so the file links align
1210 * See https://www.doxygen.nl/manual/htmlcmds.html
1211 */
1213 // Find longest log name
1214 std::size_t widthL = std::string("Log Component").size();
1215 std::size_t widthR = std::string("file").size();
1216 for (const auto& it : (*logs))
1217 {
1218 widthL = std::max(widthL, it.first.size());
1219 std::string file = it.second->File();
1220 // Strip leading "../" related to depth in build directory
1221 // since doxygen only sees the path starting with "src/", etc.
1222 while (file.find("../") == 0)
1223 {
1224 file = file.substr(3);
1225 }
1226 widthR = std::max(widthR, file.size());
1227 }
1228 const std::string tLeft("| ");
1229 const std::string tMid(" | ");
1230 const std::string tRight(" |");
1231
1232 // Header line has to be padded to same length as separator line
1233 os << tLeft << std::setw(widthL) << std::left << "Log Component" << tMid << std::setw(widthR)
1234 << std::left << "File" << tRight << std::endl;
1235 os << tLeft << ":" << std::string(widthL - 1, '-') << tMid << ":"
1236 << std::string(widthR - 1, '-') << tRight << std::endl;
1237
1238 for (const auto& it : (*logs))
1239 {
1240 std::string file = it.second->File();
1241 // Strip leading "../" related to depth in build directory
1242 // since doxygen only sees the path starting with "src/", etc.
1243 while (file.find("../") == 0)
1244 {
1245 file = file.substr(3);
1246 }
1247
1248 os << tLeft << std::setw(widthL) << std::left << it.first << tMid << std::setw(widthR)
1249 << file << tRight << std::endl;
1250 }
1251 os << std::right << std::endl;
1252 os << commentStop << std::endl;
1253} // PrintAllLogComponents()
1254
1255/**
1256 * Print the list of all Trace sources.
1257 *
1258 * @param [in,out] os The output stream.
1259 *
1260 * @todo Print this sorted by class (the current version)
1261 * as well as by TraceSource name.
1262 */
1263void
1264PrintAllTraceSources(std::ostream& os)
1265{
1267 os << commentStart << page << "TraceSourceList All TraceSources\n" << std::endl;
1268 os << "This is a list of all" << reference << "tracing sources. "
1269 << "For more information see the " << reference << "tracing "
1270 << "section of this API documentation and the Tracing sections "
1271 << "in the Tutorial and Manual.\n"
1272 << std::endl;
1273
1274 NameMap nameMap = GetNameMap();
1275
1276 // Iterate over the map, which will print the class names in
1277 // alphabetical order.
1278 for (const auto& item : nameMap)
1279 {
1280 // Handle only real TypeIds
1281 if (item.second < 0)
1282 {
1283 continue;
1284 }
1285 // Get the class's index out of the map;
1286 TypeId tid = TypeId::GetRegistered(item.second);
1287
1288 if (tid.GetTraceSourceN() == 0)
1289 {
1290 continue;
1291 }
1292
1293 auto index = SortedTraceSourceInfo(tid);
1294
1295 os << boldStart << tid.GetName() << boldStop << breakHtmlOnly << std::endl;
1296
1297 os << listStart << std::endl;
1298 for (const auto& [name, info] : index)
1299 {
1300 os << listLineStart << boldStart << name << boldStop << ": " << info.help
1301 << listLineStop << std::endl;
1302 }
1303 os << listStop << std::endl;
1304 }
1305 os << commentStop << std::endl;
1306
1307} // PrintAllTraceSources()
1308
1309/***************************************************************
1310 * Docs for Attribute classes
1311 ***************************************************************/
1312
1313/**
1314 * Print the section definition for an AttributeValue.
1315 *
1316 * In doxygen form this will print a comment block with
1317 * @verbatim
1318 * @ingroup attributes
1319 * @defgroup attribute_<name>Value <name>Value
1320 * @endverbatim
1321 *
1322 * @param [in,out] os The output stream.
1323 * @param [in] name The base name of the resulting AttributeValue type.
1324 * @param [in] seeBase Print a "see also" pointing to the base class.
1325 */
1326void
1327PrintAttributeValueSection(std::ostream& os, const std::string& name, const bool seeBase = true)
1328{
1330 std::string section = "attribute_" + name;
1331
1332 // \ingroup attributes
1333 // \defgroup attribute_<name>Value <name> Attribute
1334 os << commentStart << sectionStart << "attributes\n"
1335 << subSectionStart << "attribute_" << name << " " << name << " Attribute\n"
1336 << "AttributeValue implementation for " << name << "\n";
1337 if (seeBase)
1338 {
1339 os << seeAlso << "ns3::" << name << "\n";
1340 }
1341 os << commentStop;
1342
1343} // PrintAttributeValueSection()
1344
1345/**
1346 * Print the AttributeValue documentation for a class.
1347 *
1348 * This will print documentation for the \pname{AttributeValue} class and methods.
1349 *
1350 * @param [in,out] os The output stream.
1351 * @param [in] name The token to use in defining the accessor name.
1352 * @param [in] type The underlying type name.
1353 * @param [in] header The header file which contains this declaration.
1354 */
1355void
1357 const std::string& name,
1358 const std::string& type,
1359 const std::string& header)
1360{
1361 NS_LOG_FUNCTION(name << type << header);
1362 std::string sectAttr = sectionStart + "attribute_" + name;
1363
1364 // \ingroup attribute_<name>Value
1365 // \class ns3::<name>Value "header"
1366 std::string valClass = name + "Value";
1367 std::string qualClass = " ns3::" + valClass;
1368
1369 os << commentStart << sectAttr << std::endl;
1370 os << classStart << qualClass << " \"" << header << "\"" << std::endl;
1371 os << "AttributeValue implementation for " << name << "." << std::endl;
1372 os << seeAlso << "AttributeValue" << std::endl;
1373 os << commentStop;
1374
1375 // Ctor: <name>Value::<name>Value
1376 os << commentStart << functionStart << qualClass << "::" << valClass;
1377 // Constructors
1378 os << "(const " << type << " & value)\n"
1379 << "Constructor.\n"
1380 << argument << "[in] value The " << name << " value to use.\n";
1381 os << commentStop;
1382
1383 // <name>Value::Get() const
1384 os << commentStart << functionStart << type << qualClass << "::Get() const\n"
1385 << returns << "The " << name << " value.\n"
1386 << commentStop;
1387
1388 // <name>Value::GetAccessor(T & value) const
1389 os << commentStart << functionStart << "bool" << qualClass << "::GetAccessor(T & value) const\n"
1390 << "Access the " << name << " value as type " << codeWord << "T.\n"
1391 << templateArgument << "T " << templArgExplicit << "The type to cast to.\n"
1392 << argument << "[out] value The " << name << " value, as type " << codeWord << "T.\n"
1393 << returns << "true.\n"
1394 << commentStop;
1395
1396 // <name>Value::Set(const name & value)
1397 if (type != "Callback") // Yuck
1398 {
1399 os << commentStart << functionStart << "void" << qualClass << "::Set(const " << type
1400 << " & value)\n"
1401 << "Set the value.\n"
1402 << argument << "[in] value The value to adopt.\n"
1403 << commentStop;
1404 }
1405
1406 // <name>Value::m_value
1407 os << commentStart << variable << type << qualClass << "::m_value\n"
1408 << "The stored " << name << " instance.\n"
1409 << commentStop << std::endl;
1410
1411} // PrintAttributeValueWithName()
1412
1413/**
1414 * Print the AttributeValue MakeAccessor documentation for a class.
1415 *
1416 * This will print documentation for the \pname{Make<name>Accessor} functions.
1417 *
1418 * @param [in,out] os The output stream.
1419 * @param [in] name The token to use in defining the accessor name.
1420 */
1421void
1422PrintMakeAccessors(std::ostream& os, const std::string& name)
1423{
1425 std::string sectAttr = sectionStart + "attribute_" + name + "\n";
1426 std::string make = "ns3::Make" + name + "Accessor ";
1427
1428 // \ingroup attribute_<name>Value
1429 // Make<name>Accessor(T1 a1)
1430 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeAccessor> "
1431 << make << "(T1 a1)\n"
1432 << copyDoc << "ns3::MakeAccessorHelper(T1)\n"
1433 << seeAlso << "AttributeAccessor\n"
1434 << commentStop;
1435
1436 // \ingroup attribute_<name>Value
1437 // Make<name>Accessor(T1 a1)
1438 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeAccessor> "
1439 << make << "(T1 a1, T2 a2)\n"
1440 << copyDoc << "ns3::MakeAccessorHelper(T1,T2)\n"
1441 << seeAlso << "AttributeAccessor\n"
1442 << commentStop;
1443} // PrintMakeAccessors()
1444
1445/**
1446 * Print the AttributeValue MakeChecker documentation for a class.
1447 *
1448 * This will print documentation for the \pname{Make<name>Checker} function.
1449 *
1450 * @param [in,out] os The output stream.
1451 * @param [in] name The token to use in defining the accessor name.
1452 * @param [in] header The header file which contains this declaration.
1453 */
1454void
1455PrintMakeChecker(std::ostream& os, const std::string& name, const std::string& header)
1456{
1457 NS_LOG_FUNCTION(name << header);
1458 std::string sectAttr = sectionStart + "attribute_" + name + "\n";
1459 std::string make = "ns3::Make" + name + "Checker ";
1460
1461 // \ingroup attribute_<name>Value
1462 // class <name>Checker
1463 os << commentStart << sectAttr << std::endl;
1464 os << classStart << " ns3::" << name << "Checker"
1465 << " \"" << header << "\"" << std::endl;
1466 os << "AttributeChecker implementation for " << name << "Value." << std::endl;
1467 os << seeAlso << "AttributeChecker" << std::endl;
1468 os << commentStop;
1469
1470 // \ingroup attribute_<name>Value
1471 // Make<name>Checker()
1472 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeChecker> "
1473 << make << "()\n"
1474 << returns << "The AttributeChecker.\n"
1475 << seeAlso << "AttributeChecker\n"
1476 << commentStop;
1477} // PrintMakeChecker()
1478
1479/**Descriptor for an AttributeValue. */
1481{
1482 const std::string m_name; //!< The base name of the resulting AttributeValue type.
1483 const std::string m_type; //!< The name of the underlying type.
1484 const bool m_seeBase; //!< Print a "see also" pointing to the base class.
1485 const std::string m_header; //!< The header file name.
1486};
1487
1488/**
1489 * Print documentation corresponding to use of the
1490 * ATTRIBUTE_HELPER_HEADER macro or
1491 * ATTRIBUTE_VALUE_DEFINE_WITH_NAME macro.
1492 *
1493 * @param [in,out] os The output stream.
1494 * @param [in] attr The AttributeDescriptor.
1495 */
1496void
1497PrintAttributeHelper(std::ostream& os, const AttributeDescriptor& attr)
1498{
1499 NS_LOG_FUNCTION(attr.m_name << attr.m_type << attr.m_seeBase << attr.m_header);
1501 PrintAttributeValueWithName(os, attr.m_name, attr.m_type, attr.m_header);
1502 PrintMakeAccessors(os, attr.m_name);
1503 PrintMakeChecker(os, attr.m_name, attr.m_header);
1504} // PrintAttributeHelper()
1505
1506/**
1507 * Print documentation for Attribute implementations.
1508 * @param os The stream to print on.
1509 */
1510void
1512{
1514
1515 // clang-format off
1516 const AttributeDescriptor attributes [] =
1517 {
1518 // Name Type see Base header-file
1519 // Users of ATTRIBUTE_HELPER_HEADER
1520 //
1521 { "Address", "Address", true, "address.h" },
1522 { "Box", "Box", true, "box.h" },
1523 { "DataRate", "DataRate", true, "data-rate.h" },
1524 { "Length", "Length", true, "length.h" },
1525 { "Ipv4Address", "Ipv4Address", true, "ipv4-address.h" },
1526 { "Ipv4Mask", "Ipv4Mask", true, "ipv4-address.h" },
1527 { "Ipv6Address", "Ipv6Address", true, "ipv6-address.h" },
1528 { "Ipv6Prefix", "Ipv6Prefix", true, "ipv6-address.h" },
1529 { "Mac16Address", "Mac16Address", true, "mac16-address.h" },
1530 { "Mac48Address", "Mac48Address", true, "mac48-address.h" },
1531 { "Mac64Address", "Mac64Address", true, "mac64-address.h" },
1532 { "ObjectFactory", "ObjectFactory", true, "object-factory.h" },
1533 { "Priomap", "Priomap", true, "prio-queue-disc.h" },
1534 { "QueueSize", "QueueSize", true, "queue-size.h" },
1535 { "Rectangle", "Rectangle", true, "rectangle.h" },
1536 { "Ssid", "Ssid", true, "ssid.h" },
1537 { "TypeId", "TypeId", true, "type-id.h" },
1538 { "UanModesList", "UanModesList", true, "uan-tx-mode.h" },
1539 { "ValueClassTest", "ValueClassTest", false, "attribute-test-suite.cc" /* core/test/ */ },
1540 { "Vector2D", "Vector2D", true, "vector.h" },
1541 { "Vector3D", "Vector3D", true, "vector.h" },
1542 { "Waypoint", "Waypoint", true, "waypoint.h" },
1543 { "WifiMode", "WifiMode", true, "wifi-mode.h" },
1544
1545 // All three (Value, Access and Checkers) defined, but custom
1546 { "Boolean", "bool", false, "boolean.h" },
1547 { "Callback", "CallbackBase", true, "callback.h" },
1548 { "Double", "double", false, "double.h" },
1549 { "Enum", "T", false, "enum.h" },
1550 { "Integer", "int64_t", false, "integer.h" },
1551 { "String", "std::string", false, "string.h" },
1552 { "Time", "Time", true, "nstime.h" },
1553 { "Uinteger", "uint64_t", false, "uinteger.h" },
1554 { "", "", false, "last placeholder" }
1555 };
1556 // clang-format on
1557
1558 int i = 0;
1559 while (!attributes[i].m_name.empty())
1560 {
1561 PrintAttributeHelper(os, attributes[i]);
1562 ++i;
1563 }
1564
1565 PrintAttributeValueSection(os, "ObjectVector", false);
1566 PrintMakeAccessors(os, "ObjectVector");
1567 PrintMakeChecker(os, "ObjectVector", "object-vector.h");
1568
1569 PrintAttributeValueSection(os, "ObjectMap", false);
1570 PrintMakeAccessors(os, "ObjectMap");
1571 PrintMakeChecker(os, "ObjectMap", "object-map.h");
1572
1573} // PrintAttributeImplementations()
1574
1575/***************************************************************
1576 * Main
1577 ***************************************************************/
1578
1579int
1580main(int argc, char* argv[])
1581{
1583
1584 std::string typeId;
1585
1586 CommandLine cmd(__FILE__);
1587 cmd.Usage("Generate documentation for all ns-3 registered types, "
1588 "trace sources, attributes and global variables.");
1589 cmd.AddValue("output-text", "format output as plain text", outputText);
1590 cmd.AddValue("TypeId", "Print docs for just the given TypeId", typeId);
1591 cmd.Parse(argc, argv);
1592
1593 if (!typeId.empty())
1594 {
1595 outputText = true;
1596 SetMarkup();
1597
1598 TypeId tid;
1599
1600 bool validTypeId = TypeId::LookupByNameFailSafe(typeId, &tid);
1601 if (!validTypeId)
1602 {
1603 auto fqTypeId = "ns3::" + typeId;
1604 validTypeId = TypeId::LookupByNameFailSafe(fqTypeId, &tid);
1605 if (validTypeId)
1606 {
1607 std::cout << "\nFound fully qualified name " << fqTypeId << "\n\n";
1608 }
1609 }
1610 if (validTypeId)
1611 {
1612 PrintTypeIdBlock(std::cout, tid);
1613 return 0;
1614 }
1615 else
1616 {
1617 std::cerr << "Invalid TypeId name: " << typeId << "\n" << std::endl;
1618 std::cerr << cmd;
1619 exit(1);
1620 }
1621 }
1622
1623 SetMarkup();
1624
1625 // Create a Node, to force linking and instantiation of our TypeIds
1626 NodeContainer c;
1627 c.Create(1);
1628
1629 std::cout << std::endl;
1630 std::cout << commentStart << file << "\n"
1631 << sectionStart << "utils\n"
1632 << "Doxygen docs generated from the TypeId database.\n"
1633 << note << "This file is automatically generated by " << codeWord
1634 << "print-introspected-doxygen.cc. Do not edit this file! "
1635 << "Edit that file instead.\n"
1636 << commentStop << std::endl;
1637
1638 PrintTypeIdBlocks(std::cout);
1639
1640 PrintAllTypeIds(std::cout);
1641 PrintAllAttributes(std::cout);
1642 PrintAllGlobals(std::cout);
1643 PrintAllGroups(std::cout);
1644 PrintAllLogComponents(std::cout);
1645 PrintAllTraceSources(std::cout);
1647
1648 return 0;
1649}
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:1019
std::size_t GetRootNamespaceObjectN()
Definition config.cc:1012
#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