17
17
#include < mrdox/Support/Error.hpp>
18
18
#include < memory>
19
19
#include < string>
20
+ #include < type_traits>
20
21
#include < utility>
21
22
#include < vector>
22
23
@@ -38,14 +39,15 @@ using List = std::vector<std::unique_ptr<T>>;
38
39
enum class Kind
39
40
{
40
41
text = 1 , // needed by bitstream
41
- styled,
42
- paragraph,
43
- brief,
44
42
admonition,
43
+ brief,
45
44
code,
45
+ heading,
46
+ paragraph,
46
47
param,
48
+ returns,
49
+ styled,
47
50
tparam,
48
- returns
49
51
};
50
52
51
53
/* * A text style.
@@ -209,6 +211,31 @@ struct Block : Node
209
211
}
210
212
};
211
213
214
+ /* * A manually specified section heading.
215
+ */
216
+ struct Heading : Block
217
+ {
218
+ static constexpr Kind static_kind = Kind::heading;
219
+
220
+ String string;
221
+
222
+ Heading (
223
+ String string_ = String())
224
+ : Block(Kind::heading)
225
+ , string(std::move(string_))
226
+ {
227
+ }
228
+
229
+ bool operator ==(const Heading&)
230
+ const noexcept = default ;
231
+
232
+ bool equals (const Node& other) const noexcept override
233
+ {
234
+ return kind == other.kind &&
235
+ *this == static_cast <const Heading&>(other);
236
+ }
237
+ };
238
+
212
239
/* * A sequence of text nodes.
213
240
*/
214
241
struct Paragraph : Block
@@ -383,8 +410,68 @@ struct Returns : Paragraph
383
410
}
384
411
};
385
412
413
+ // ------------------------------------------------
414
+
415
+ template <class F , class ... Args>
416
+ constexpr
417
+ auto
418
+ visit (
419
+ Node const & node,
420
+ F&& f, Args&&... args)
421
+ {
422
+ switch (node.kind )
423
+ {
424
+ case Kind::admonition:
425
+ return f (static_cast <Admonition const &>(node),
426
+ std::forward<Args>(args)...);
427
+ case Kind::brief:
428
+ return f (static_cast <Brief const &>(node),
429
+ std::forward<Args>(args)...);
430
+ case Kind::code:
431
+ return f (static_cast <Code const &>(node),
432
+ std::forward<Args>(args)...);
433
+ case Kind::heading:
434
+ return f (static_cast <Heading const &>(node),
435
+ std::forward<Args>(args)...);
436
+ case Kind::paragraph:
437
+ return f (static_cast <Paragraph const &>(node),
438
+ std::forward<Args>(args)...);
439
+ case Kind::param:
440
+ return f (static_cast <Param const &>(node),
441
+ std::forward<Args>(args)...);
442
+ case Kind::returns:
443
+ return f (static_cast <Returns const &>(node),
444
+ std::forward<Args>(args)...);
445
+ case Kind::styled:
446
+ return f (static_cast <StyledText const &>(node),
447
+ std::forward<Args>(args)...);
448
+ case Kind::text:
449
+ return f (static_cast <Text const &>(node),
450
+ std::forward<Args>(args)...);
451
+ case Kind::tparam:
452
+ return f (static_cast <TParam const &>(node),
453
+ std::forward<Args>(args)...);
454
+ default :
455
+ MRDOX_UNREACHABLE ();
456
+ }
457
+ }
458
+
459
+ template <class F , class T , class ... Args>
460
+ requires std::derived_from<T, Node>
461
+ void traverse (
462
+ std::vector<std::unique_ptr<T>> const & list,
463
+ F&& f, Args&&... args)
464
+ {
465
+ for (auto const & node : list)
466
+ visit (*node,
467
+ std::forward<F>(f),
468
+ std::forward<Args>(args)...);
469
+ }
470
+
386
471
} // doc
387
472
473
+ // ------------------------------------------------
474
+
388
475
/* * A processed Doxygen-style comment attached to a declaration.
389
476
*/
390
477
struct MRDOX_VISIBLE
0 commit comments