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.
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} // PrintAttributes()
886
887/**
888 * Print direct Trace sources for this TypeId.
889 *
890 * Only Trace sources defined directly by this TypeId will be printed.
891 *
892 * @param [in,out] os The output stream.
893 * @param [in] tid The TypeId to print.
894 */
895void
896PrintTraceSourcesTid(std::ostream& os, const TypeId tid)
897{
898 NS_LOG_FUNCTION(tid);
899
900 auto index = SortedTraceSourceInfo(tid);
901
902 os << listStart << std::endl;
903 for (const auto& [name, info] : index)
904 {
905 os << listLineStart << boldStart << name << boldStop << ": " << info.help << breakBoth;
906 os << indentHtmlOnly << listStart << std::endl;
907 os << " " << listLineStart;
908 if (!outputText)
909 {
910 // '%' prevents doxygen from linking to the Callback class...
911 os << " %";
912 }
913 os << "Callback signature: " << info.callback << std::endl;
914 os << listLineStop << std::endl;
915
916 PrintSupportLevel(os, info.supportLevel, info.supportMsg);
917 os << listStop << std::endl;
918 }
919 os << listStop << std::endl;
920} // PrintTraceSourcesTid()
921
922/**
923 * Print the Trace sources block for tid,
924 * including Trace sources declared in base classes.
925 *
926 * All Trace sources of this TypeId will be printed,
927 * including those defined in parent classes.
928 *
929 * @param [in,out] os The output stream.
930 * @param [in] tid The TypeId to print.
931 */
932void
933PrintTraceSources(std::ostream& os, const TypeId tid)
934{
935 NS_LOG_FUNCTION(tid);
936 if (tid.GetTraceSourceN() == 0)
937 {
938 os << "No TraceSources are defined for this type." << breakBoth << std::endl;
939 }
940 else
941 {
942 os << headingStart << "TraceSources" << headingStop << std::endl;
943 PrintTraceSourcesTid(os, tid);
944 }
945
946 // Trace sources from base classes
947 TypeId tmp = tid.GetParent();
948 while (tmp.GetParent() != tmp)
949 {
950 if (tmp.GetTraceSourceN() != 0)
951 {
952 os << headingStart << "TraceSources defined in parent class " << tmp.GetName()
953 << headingStop << std::endl;
954 PrintTraceSourcesTid(os, tmp);
955 }
956 tmp = tmp.GetParent();
957 }
958
959} // PrintTraceSources()
960
961/**
962 * Print the size of the type represented by this tid.
963 *
964 * @param [in,out] os The output stream.
965 * @param [in] tid The TypeId to print.
966 */
967void
968PrintSize(std::ostream& os, const TypeId tid)
969{
970 NS_LOG_FUNCTION(tid);
971 NS_ASSERT_MSG(CHAR_BIT != 0, "CHAR_BIT is zero");
972
973 std::size_t arch = (sizeof(void*) * CHAR_BIT);
974
975 os << boldStart << "Size" << boldStop << " of this type is " << tid.GetSize() << " bytes (on a "
976 << arch << "-bit architecture)." << std::endl;
977} // PrintSize()
978
979/**
980 * Print the doxy block for a single TypeId
981 *
982 * @param [in,out] os The output stream.
983 * @param [in] tid the TypeId
984 */
985void
986PrintTypeIdBlock(std::ostream& os, const TypeId tid)
987{
988 NS_LOG_FUNCTION(tid);
989
990 std::string name = tid.GetName();
991
992 os << commentStart << std::endl;
993
994 os << classStart << name << std::endl;
995 os << std::endl;
996
997 PrintConfigPaths(os, tid);
998 PrintAttributes(os, tid);
999 PrintTraceSources(os, tid);
1000
1001 if (!tid.GetGroupName().empty())
1002 {
1003 os << boldStart << "Group:" << boldStop << " " << tid.GetGroupName() << "\n" << std::endl;
1004 }
1005
1006 PrintSize(os, tid);
1007
1008 os << commentStop << std::endl;
1009
1010} // PrintTypeIdBlock()
1011
1012/**
1013 * Print the doxy block for each TypeId
1014 *
1015 * @param [in,out] os The output stream.
1016 */
1017void
1018PrintTypeIdBlocks(std::ostream& os)
1019{
1021
1022 NameMap nameMap = GetNameMap();
1023
1024 // Iterate over the map, which will print the class names in
1025 // alphabetical order.
1026 for (const auto& item : nameMap)
1027 {
1028 // Handle only real TypeIds
1029 if (item.second < 0)
1030 {
1031 continue;
1032 }
1033 // Get the class's index out of the map;
1034 TypeId tid = TypeId::GetRegistered(item.second);
1035 PrintTypeIdBlock(os, tid);
1036 }
1037} // PrintTypeIdBlocks()
1038
1039/***************************************************************
1040 * Lists of All things
1041 ***************************************************************/
1042
1043/**
1044 * Print the list of all TypeIds
1045 *
1046 * @param [in,out] os The output stream.
1047 */
1048void
1049PrintAllTypeIds(std::ostream& os)
1050{
1052 os << commentStart << page << "TypeIdList All ns3::TypeId's\n" << std::endl;
1053 os << "This is a list of all" << reference << "ns3::TypeId's.\n"
1054 << "For more information see the" << reference << "ns3::TypeId "
1055 << "section of this API documentation and the" << referenceNo << "TypeId section "
1056 << "in the Configuration and " << referenceNo << "Attributes chapter of the Manual.\n"
1057 << std::endl;
1058
1059 os << listStart << std::endl;
1060
1061 NameMap nameMap = GetNameMap();
1062 // Iterate over the map, which will print the class names in
1063 // alphabetical order.
1064 for (const auto& item : nameMap)
1065 {
1066 // Handle only real TypeIds
1067 if (item.second < 0)
1068 {
1069 continue;
1070 }
1071 // Get the class's index out of the map;
1072 TypeId tid = TypeId::GetRegistered(item.second);
1073
1074 os << indentHtmlOnly << listLineStart << boldStart << tid.GetName() << boldStop
1075 << listLineStop << std::endl;
1076 }
1077 os << listStop << std::endl;
1078 os << commentStop << std::endl;
1079
1080} // PrintAllTypeIds()
1081
1082/**
1083 * Print the list of all Attributes.
1084 *
1085 * @param [in,out] os The output stream.
1086 *
1087 * @todo Print this sorted by class (the current version)
1088 * as well as by Attribute name.
1089 */
1090void
1091PrintAllAttributes(std::ostream& os)
1092{
1094 os << commentStart << page << "AttributeList All Attributes\n" << std::endl;
1095 os << "This is a list of all" << reference << "attributes classes. "
1096 << "For more information see the" << reference << "attributes "
1097 << "section of this API documentation and the Attributes sections "
1098 << "in the Tutorial and Manual.\n"
1099 << std::endl;
1100
1101 NameMap nameMap = GetNameMap();
1102 // Iterate over the map, which will print the class names in
1103 // alphabetical order.
1104 for (const auto& item : nameMap)
1105 {
1106 // Handle only real TypeIds
1107 if (item.second < 0)
1108 {
1109 continue;
1110 }
1111 // Get the class's index out of the map;
1112 TypeId tid = TypeId::GetRegistered(item.second);
1113
1114 if (tid.GetAttributeN() == 0)
1115 {
1116 continue;
1117 }
1118
1119 auto index = SortedAttributeInfo(tid);
1120
1121 os << boldStart << tid.GetName() << boldStop << breakHtmlOnly << std::endl;
1122 os << listStart << std::endl;
1123 for (const auto& [name, info] : index)
1124 {
1125 os << listLineStart << boldStart << name << boldStop << ": " << info.help
1126 << listLineStop << std::endl;
1127 }
1128 os << listStop << std::endl;
1129 }
1130 os << commentStop << std::endl;
1131
1132} // PrintAllAttributes()
1133
1134/**
1135 * Print the list of all global variables.
1136 *
1137 * @param [in,out] os The output stream.
1138 */
1139void
1140PrintAllGlobals(std::ostream& os)
1141{
1143 os << commentStart << page << "GlobalValueList All GlobalValues\n" << std::endl;
1144 os << "This is a list of all" << reference << "ns3::GlobalValue instances.\n"
1145 << "See ns3::GlobalValue for how to set these." << std::endl;
1146
1147 os << listStart << std::endl;
1148 for (auto i = GlobalValue::Begin(); i != GlobalValue::End(); ++i)
1149 {
1150 StringValue val;
1151 (*i)->GetValue(val);
1152 os << indentHtmlOnly << listLineStart << boldStart << hrefStart << (*i)->GetName()
1153 << hrefMid << "GlobalValue" << (*i)->GetName() << hrefStop << boldStop << ": "
1154 << (*i)->GetHelp() << ". Default value: " << val.Get() << "." << listLineStop
1155 << std::endl;
1156 }
1157 os << listStop << std::endl;
1158 os << commentStop << std::endl;
1159
1160} // PrintAllGlobals()
1161
1162/**
1163 * Print the list of all groups
1164 *
1165 * @param [in,out] os The output stream.
1166 */
1167void
1168PrintAllGroups(std::ostream& os)
1169{
1171 os << commentStart << page << "GroupsList All Object Groups\n" << std::endl;
1172 os << "This is a list of all Object Groups.\n"
1173 << "Objects are added to groups by " << hrefStart << "ns3::TypeId::SetGroupName()" << hrefMid
1174 << "ns3::TypeId::SetGroupName" << hrefStop << "\n"
1175 << std::endl;
1176
1177 auto groups = GetGroupsList();
1178
1179 for (const auto& g : groups)
1180 {
1181 os << boldStart << g.first << boldStop << breakHtmlOnly << std::endl;
1182
1183 os << listStart << std::endl;
1184 for (const auto& tid : g.second)
1185 {
1186 os << indentHtmlOnly << listLineStart << hrefStart << tid.GetName() << hrefMid
1187 << tid.GetName() << hrefStop << listLineStop << std::endl;
1188 }
1189 os << listStop << std::endl;
1190 }
1191 os << commentStop << std::endl;
1192}
1193
1194/**
1195 * Print the list of all LogComponents.
1196 *
1197 * @param [in,out] os The output stream.
1198 */
1199void
1200PrintAllLogComponents(std::ostream& os)
1201{
1203 os << commentStart << page << "LogComponentList All LogComponents\n" << std::endl;
1204 os << "This is a list of all" << reference << "ns3::LogComponent instances.\n" << std::endl;
1205
1206 /**
1207 * @todo Switch to a border-less table, so the file links align
1208 * See https://www.doxygen.nl/manual/htmlcmds.html
1209 */
1211 // Find longest log name
1212 std::size_t widthL = std::string("Log Component").size();
1213 std::size_t widthR = std::string("file").size();
1214 for (const auto& it : (*logs))
1215 {
1216 widthL = std::max(widthL, it.first.size());
1217 std::string file = it.second->File();
1218 // Strip leading "../" related to depth in build directory
1219 // since doxygen only sees the path starting with "src/", etc.
1220 while (file.find("../") == 0)
1221 {
1222 file = file.substr(3);
1223 }
1224 widthR = std::max(widthR, file.size());
1225 }
1226 const std::string tLeft("| ");
1227 const std::string tMid(" | ");
1228 const std::string tRight(" |");
1229
1230 // Header line has to be padded to same length as separator line
1231 os << tLeft << std::setw(widthL) << std::left << "Log Component" << tMid << std::setw(widthR)
1232 << std::left << "File" << tRight << std::endl;
1233 os << tLeft << ":" << std::string(widthL - 1, '-') << tMid << ":"
1234 << std::string(widthR - 1, '-') << tRight << std::endl;
1235
1236 for (const auto& it : (*logs))
1237 {
1238 std::string file = it.second->File();
1239 // Strip leading "../" related to depth in build directory
1240 // since doxygen only sees the path starting with "src/", etc.
1241 while (file.find("../") == 0)
1242 {
1243 file = file.substr(3);
1244 }
1245
1246 os << tLeft << std::setw(widthL) << std::left << it.first << tMid << std::setw(widthR)
1247 << file << tRight << std::endl;
1248 }
1249 os << std::right << std::endl;
1250 os << commentStop << std::endl;
1251} // PrintAllLogComponents()
1252
1253/**
1254 * Print the list of all Trace sources.
1255 *
1256 * @param [in,out] os The output stream.
1257 *
1258 * @todo Print this sorted by class (the current version)
1259 * as well as by TraceSource name.
1260 */
1261void
1262PrintAllTraceSources(std::ostream& os)
1263{
1265 os << commentStart << page << "TraceSourceList All TraceSources\n" << std::endl;
1266 os << "This is a list of all" << reference << "tracing sources. "
1267 << "For more information see the " << reference << "tracing "
1268 << "section of this API documentation and the Tracing sections "
1269 << "in the Tutorial and Manual.\n"
1270 << std::endl;
1271
1272 NameMap nameMap = GetNameMap();
1273
1274 // Iterate over the map, which will print the class names in
1275 // alphabetical order.
1276 for (const auto& item : nameMap)
1277 {
1278 // Handle only real TypeIds
1279 if (item.second < 0)
1280 {
1281 continue;
1282 }
1283 // Get the class's index out of the map;
1284 TypeId tid = TypeId::GetRegistered(item.second);
1285
1286 if (tid.GetTraceSourceN() == 0)
1287 {
1288 continue;
1289 }
1290
1291 auto index = SortedTraceSourceInfo(tid);
1292
1293 os << boldStart << tid.GetName() << boldStop << breakHtmlOnly << std::endl;
1294
1295 os << listStart << std::endl;
1296 for (const auto& [name, info] : index)
1297 {
1298 os << listLineStart << boldStart << name << boldStop << ": " << info.help
1299 << listLineStop << std::endl;
1300 }
1301 os << listStop << std::endl;
1302 }
1303 os << commentStop << std::endl;
1304
1305} // PrintAllTraceSources()
1306
1307/***************************************************************
1308 * Docs for Attribute classes
1309 ***************************************************************/
1310
1311/**
1312 * Print the section definition for an AttributeValue.
1313 *
1314 * In doxygen form this will print a comment block with
1315 * @verbatim
1316 * @ingroup attributes
1317 * @defgroup attribute_<name>Value <name>Value
1318 * @endverbatim
1319 *
1320 * @param [in,out] os The output stream.
1321 * @param [in] name The base name of the resulting AttributeValue type.
1322 * @param [in] seeBase Print a "see also" pointing to the base class.
1323 */
1324void
1325PrintAttributeValueSection(std::ostream& os, const std::string& name, const bool seeBase = true)
1326{
1328 std::string section = "attribute_" + name;
1329
1330 // \ingroup attributes
1331 // \defgroup attribute_<name>Value <name> Attribute
1332 os << commentStart << sectionStart << "attributes\n"
1333 << subSectionStart << "attribute_" << name << " " << name << " Attribute\n"
1334 << "AttributeValue implementation for " << name << "\n";
1335 if (seeBase)
1336 {
1337 os << seeAlso << "ns3::" << name << "\n";
1338 }
1339 os << commentStop;
1340
1341} // PrintAttributeValueSection()
1342
1343/**
1344 * Print the AttributeValue documentation for a class.
1345 *
1346 * This will print documentation for the \pname{AttributeValue} class and methods.
1347 *
1348 * @param [in,out] os The output stream.
1349 * @param [in] name The token to use in defining the accessor name.
1350 * @param [in] type The underlying type name.
1351 * @param [in] header The header file which contains this declaration.
1352 */
1353void
1355 const std::string& name,
1356 const std::string& type,
1357 const std::string& header)
1358{
1359 NS_LOG_FUNCTION(name << type << header);
1360 std::string sectAttr = sectionStart + "attribute_" + name;
1361
1362 // \ingroup attribute_<name>Value
1363 // \class ns3::<name>Value "header"
1364 std::string valClass = name + "Value";
1365 std::string qualClass = " ns3::" + valClass;
1366
1367 os << commentStart << sectAttr << std::endl;
1368 os << classStart << qualClass << " \"" << header << "\"" << std::endl;
1369 os << "AttributeValue implementation for " << name << "." << std::endl;
1370 os << seeAlso << "AttributeValue" << std::endl;
1371 os << commentStop;
1372
1373 // Ctor: <name>Value::<name>Value
1374 os << commentStart << functionStart << qualClass << "::" << valClass;
1375 // Constructors
1376 os << "(const " << type << " & value)\n"
1377 << "Constructor.\n"
1378 << argument << "[in] value The " << name << " value to use.\n";
1379 os << commentStop;
1380
1381 // <name>Value::Get() const
1382 os << commentStart << functionStart << type << qualClass << "::Get() const\n"
1383 << returns << "The " << name << " value.\n"
1384 << commentStop;
1385
1386 // <name>Value::GetAccessor(T & value) const
1387 os << commentStart << functionStart << "bool" << qualClass << "::GetAccessor(T & value) const\n"
1388 << "Access the " << name << " value as type " << codeWord << "T.\n"
1389 << templateArgument << "T " << templArgExplicit << "The type to cast to.\n"
1390 << argument << "[out] value The " << name << " value, as type " << codeWord << "T.\n"
1391 << returns << "true.\n"
1392 << commentStop;
1393
1394 // <name>Value::Set(const name & value)
1395 if (type != "Callback") // Yuck
1396 {
1397 os << commentStart << functionStart << "void" << qualClass << "::Set(const " << type
1398 << " & value)\n"
1399 << "Set the value.\n"
1400 << argument << "[in] value The value to adopt.\n"
1401 << commentStop;
1402 }
1403
1404 // <name>Value::m_value
1405 os << commentStart << variable << type << qualClass << "::m_value\n"
1406 << "The stored " << name << " instance.\n"
1407 << commentStop << std::endl;
1408
1409} // PrintAttributeValueWithName()
1410
1411/**
1412 * Print the AttributeValue MakeAccessor documentation for a class.
1413 *
1414 * This will print documentation for the \pname{Make<name>Accessor} functions.
1415 *
1416 * @param [in,out] os The output stream.
1417 * @param [in] name The token to use in defining the accessor name.
1418 */
1419void
1420PrintMakeAccessors(std::ostream& os, const std::string& name)
1421{
1423 std::string sectAttr = sectionStart + "attribute_" + name + "\n";
1424 std::string make = "ns3::Make" + name + "Accessor ";
1425
1426 // \ingroup attribute_<name>Value
1427 // Make<name>Accessor(T1 a1)
1428 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeAccessor> "
1429 << make << "(T1 a1)\n"
1430 << copyDoc << "ns3::MakeAccessorHelper(T1)\n"
1431 << seeAlso << "AttributeAccessor\n"
1432 << commentStop;
1433
1434 // \ingroup attribute_<name>Value
1435 // Make<name>Accessor(T1 a1)
1436 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeAccessor> "
1437 << make << "(T1 a1, T2 a2)\n"
1438 << copyDoc << "ns3::MakeAccessorHelper(T1,T2)\n"
1439 << seeAlso << "AttributeAccessor\n"
1440 << commentStop;
1441} // PrintMakeAccessors()
1442
1443/**
1444 * Print the AttributeValue MakeChecker documentation for a class.
1445 *
1446 * This will print documentation for the \pname{Make<name>Checker} function.
1447 *
1448 * @param [in,out] os The output stream.
1449 * @param [in] name The token to use in defining the accessor name.
1450 * @param [in] header The header file which contains this declaration.
1451 */
1452void
1453PrintMakeChecker(std::ostream& os, const std::string& name, const std::string& header)
1454{
1455 NS_LOG_FUNCTION(name << header);
1456 std::string sectAttr = sectionStart + "attribute_" + name + "\n";
1457 std::string make = "ns3::Make" + name + "Checker ";
1458
1459 // \ingroup attribute_<name>Value
1460 // class <name>Checker
1461 os << commentStart << sectAttr << std::endl;
1462 os << classStart << " ns3::" << name << "Checker"
1463 << " \"" << header << "\"" << std::endl;
1464 os << "AttributeChecker implementation for " << name << "Value." << std::endl;
1465 os << seeAlso << "AttributeChecker" << std::endl;
1466 os << commentStop;
1467
1468 // \ingroup attribute_<name>Value
1469 // Make<name>Checker()
1470 os << commentStart << sectAttr << functionStart << "ns3::Ptr<const ns3::AttributeChecker> "
1471 << make << "()\n"
1472 << returns << "The AttributeChecker.\n"
1473 << seeAlso << "AttributeChecker\n"
1474 << commentStop;
1475} // PrintMakeChecker()
1476
1477/**Descriptor for an AttributeValue. */
1479{
1480 const std::string m_name; //!< The base name of the resulting AttributeValue type.
1481 const std::string m_type; //!< The name of the underlying type.
1482 const bool m_seeBase; //!< Print a "see also" pointing to the base class.
1483 const std::string m_header; //!< The header file name.
1484};
1485
1486/**
1487 * Print documentation corresponding to use of the
1488 * ATTRIBUTE_HELPER_HEADER macro or
1489 * ATTRIBUTE_VALUE_DEFINE_WITH_NAME macro.
1490 *
1491 * @param [in,out] os The output stream.
1492 * @param [in] attr The AttributeDescriptor.
1493 */
1494void
1495PrintAttributeHelper(std::ostream& os, const AttributeDescriptor& attr)
1496{
1497 NS_LOG_FUNCTION(attr.m_name << attr.m_type << attr.m_seeBase << attr.m_header);
1499 PrintAttributeValueWithName(os, attr.m_name, attr.m_type, attr.m_header);
1500 PrintMakeAccessors(os, attr.m_name);
1501 PrintMakeChecker(os, attr.m_name, attr.m_header);
1502} // PrintAttributeHelper()
1503
1504/**
1505 * Print documentation for Attribute implementations.
1506 * @param os The stream to print on.
1507 */
1508void
1510{
1512
1513 // clang-format off
1514 const AttributeDescriptor attributes [] =
1515 {
1516 // Name Type see Base header-file
1517 // Users of ATTRIBUTE_HELPER_HEADER
1518 //
1519 { "Address", "Address", true, "address.h" },
1520 { "Box", "Box", true, "box.h" },
1521 { "DataRate", "DataRate", true, "data-rate.h" },
1522 { "Length", "Length", true, "length.h" },
1523 { "Ipv4Address", "Ipv4Address", true, "ipv4-address.h" },
1524 { "Ipv4Mask", "Ipv4Mask", true, "ipv4-address.h" },
1525 { "Ipv6Address", "Ipv6Address", true, "ipv6-address.h" },
1526 { "Ipv6Prefix", "Ipv6Prefix", true, "ipv6-address.h" },
1527 { "Mac16Address", "Mac16Address", true, "mac16-address.h" },
1528 { "Mac48Address", "Mac48Address", true, "mac48-address.h" },
1529 { "Mac64Address", "Mac64Address", true, "mac64-address.h" },
1530 { "ObjectFactory", "ObjectFactory", true, "object-factory.h" },
1531 { "Priomap", "Priomap", true, "prio-queue-disc.h" },
1532 { "QueueSize", "QueueSize", true, "queue-size.h" },
1533 { "Rectangle", "Rectangle", true, "rectangle.h" },
1534 { "Ssid", "Ssid", true, "ssid.h" },
1535 { "TypeId", "TypeId", true, "type-id.h" },
1536 { "UanModesList", "UanModesList", true, "uan-tx-mode.h" },
1537 { "ValueClassTest", "ValueClassTest", false, "attribute-test-suite.cc" /* core/test/ */ },
1538 { "Vector2D", "Vector2D", true, "vector.h" },
1539 { "Vector3D", "Vector3D", true, "vector.h" },
1540 { "Waypoint", "Waypoint", true, "waypoint.h" },
1541 { "WifiMode", "WifiMode", true, "wifi-mode.h" },
1542
1543 // All three (Value, Access and Checkers) defined, but custom
1544 { "Boolean", "bool", false, "boolean.h" },
1545 { "Callback", "CallbackBase", true, "callback.h" },
1546 { "Double", "double", false, "double.h" },
1547 { "Enum", "T", false, "enum.h" },
1548 { "Integer", "int64_t", false, "integer.h" },
1549 { "String", "std::string", false, "string.h" },
1550 { "Time", "Time", true, "nstime.h" },
1551 { "Uinteger", "uint64_t", false, "uinteger.h" },
1552 { "", "", false, "last placeholder" }
1553 };
1554 // clang-format on
1555
1556 int i = 0;
1557 while (!attributes[i].m_name.empty())
1558 {
1559 PrintAttributeHelper(os, attributes[i]);
1560 ++i;
1561 }
1562
1563 PrintAttributeValueSection(os, "ObjectVector", false);
1564 PrintMakeAccessors(os, "ObjectVector");
1565 PrintMakeChecker(os, "ObjectVector", "object-vector.h");
1566
1567 PrintAttributeValueSection(os, "ObjectMap", false);
1568 PrintMakeAccessors(os, "ObjectMap");
1569 PrintMakeChecker(os, "ObjectMap", "object-map.h");
1570
1571} // PrintAttributeImplementations()
1572
1573/***************************************************************
1574 * Main
1575 ***************************************************************/
1576
1577int
1578main(int argc, char* argv[])
1579{
1581
1582 std::string typeId;
1583
1584 CommandLine cmd(__FILE__);
1585 cmd.Usage("Generate documentation for all ns-3 registered types, "
1586 "trace sources, attributes and global variables.");
1587 cmd.AddValue("output-text", "format output as plain text", outputText);
1588 cmd.AddValue("TypeId", "Print docs for just the given TypeId", typeId);
1589 cmd.Parse(argc, argv);
1590
1591 if (!typeId.empty())
1592 {
1593 outputText = true;
1594 SetMarkup();
1595
1596 TypeId tid;
1597
1598 bool validTypeId = TypeId::LookupByNameFailSafe(typeId, &tid);
1599 if (!validTypeId)
1600 {
1601 auto fqTypeId = "ns3::" + typeId;
1602 validTypeId = TypeId::LookupByNameFailSafe(fqTypeId, &tid);
1603 if (validTypeId)
1604 {
1605 std::cout << "\nFound fully qualified name " << fqTypeId << "\n\n";
1606 }
1607 }
1608 if (validTypeId)
1609 {
1610 PrintTypeIdBlock(std::cout, tid);
1611 return 0;
1612 }
1613 else
1614 {
1615 std::cerr << "Invalid TypeId name: " << typeId << "\n" << std::endl;
1616 std::cerr << cmd;
1617 exit(1);
1618 }
1619 }
1620
1621 SetMarkup();
1622
1623 // Create a Node, to force linking and instantiation of our TypeIds
1624 NodeContainer c;
1625 c.Create(1);
1626
1627 std::cout << std::endl;
1628 std::cout << commentStart << file << "\n"
1629 << sectionStart << "utils\n"
1630 << "Doxygen docs generated from the TypeId database.\n"
1631 << note << "This file is automatically generated by " << codeWord
1632 << "print-introspected-doxygen.cc. Do not edit this file! "
1633 << "Edit that file instead.\n"
1634 << commentStop << std::endl;
1635
1636 PrintTypeIdBlocks(std::cout);
1637
1638 PrintAllTypeIds(std::cout);
1639 PrintAllAttributes(std::cout);
1640 PrintAllGlobals(std::cout);
1641 PrintAllGroups(std::cout);
1642 PrintAllLogComponents(std::cout);
1643 PrintAllTraceSources(std::cout);
1645
1646 return 0;
1647}
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:396
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.
Definition ptr.h:67
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:448
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