@@ -33,11 +33,15 @@ struct Node;
33
33
using String = std::string;
34
34
35
35
template <typename T>
36
- requires std::derived_from<T, doc::Node>
36
+ requires std::derived_from<T, doc::Node>
37
37
using List = std::vector<std::unique_ptr<T>>;
38
38
39
39
enum class Kind
40
40
{
41
+ // VFALCO Don't forget to update
42
+ // Node::isText() and Node::isBlock()
43
+ // when changing this enum!
44
+
41
45
text = 1 , // needed by bitstream
42
46
admonition,
43
47
brief,
@@ -88,16 +92,20 @@ enum class ParamDirection : int
88
92
89
93
/* * This is a variant-like list element.
90
94
*/
91
- struct Node
95
+ struct MRDOX_DECL
96
+ Node
92
97
{
93
98
Kind kind;
94
99
100
+ virtual ~Node () = default ;
101
+
95
102
explicit Node (Kind kind_) noexcept
96
103
: kind(kind_)
97
104
{
98
105
}
99
106
100
- virtual ~Node () = default ;
107
+ bool isBlock () const noexcept ;
108
+ bool isText () const noexcept ;
101
109
102
110
bool operator ==(const Node&)const noexcept = default ;
103
111
virtual bool equals (const Node& other) const noexcept
@@ -209,7 +217,8 @@ struct Link : Text
209
217
210
218
The top level is a list of blocks.
211
219
*/
212
- struct Block : Node
220
+ struct MRDOX_DECL
221
+ Block : Node
213
222
{
214
223
List<Text> children;
215
224
@@ -230,12 +239,20 @@ struct Block : Node
230
239
});
231
240
}
232
241
233
- bool equals (const Node& other) const noexcept override
242
+ bool equals (Node const & other) const noexcept override
234
243
{
235
244
return kind == other.kind &&
236
245
*this == static_cast <const Block&>(other);
237
246
}
238
247
248
+ template <std::derived_from<Text> T>
249
+ void emplace_back (T&& text)
250
+ {
251
+ emplace_back (std::make_unique<T>(std::move (text)));
252
+ }
253
+
254
+ void append (List<Node>&& blocks);
255
+
239
256
protected:
240
257
explicit
241
258
Block (
@@ -245,6 +262,9 @@ struct Block : Node
245
262
, children(std::move(children_))
246
263
{
247
264
}
265
+
266
+ private:
267
+ void emplace_back (std::unique_ptr<Text> text);
248
268
};
249
269
250
270
/* * A manually specified section heading.
@@ -321,13 +341,13 @@ struct Brief : Paragraph
321
341
*/
322
342
struct Admonition : Paragraph
323
343
{
324
- Admonish style ;
344
+ Admonish admonish ;
325
345
326
346
explicit
327
347
Admonition (
328
- Admonish style_ = Admonish::none) noexcept
348
+ Admonish admonish_ = Admonish::none) noexcept
329
349
: Paragraph(Kind::admonition)
330
- , style(style_ )
350
+ , admonish(admonish_ )
331
351
{
332
352
}
333
353
@@ -559,9 +579,9 @@ void traverse(
559
579
560
580
struct Overview
561
581
{
562
- Paragraph const * brief;
582
+ Paragraph const * brief = nullptr ;
563
583
std::vector<Block const *> blocks;
564
- Returns const * returns;
584
+ Returns const * returns = nullptr ;
565
585
std::vector<Param const *> params;
566
586
std::vector<TParam const *> tparams;
567
587
};
@@ -572,35 +592,30 @@ struct Overview
572
592
573
593
/* * A processed Doxygen-style comment attached to a declaration.
574
594
*/
575
- struct MRDOX_VISIBLE
595
+ class MRDOX_DECL
576
596
Javadoc
577
597
{
578
- MRDOX_DECL
598
+ public:
579
599
Javadoc () noexcept ;
580
600
581
601
/* * Constructor
582
602
*/
583
- MRDOX_DECL
584
603
explicit
585
604
Javadoc (
586
605
doc::List<doc::Block> blocks);
587
606
588
607
/* * Return true if this is empty
589
608
*/
590
- MRDOX_DECL
591
609
bool
592
- empty () const noexcept ;
610
+ empty () const noexcept
611
+ {
612
+ return blocks_.empty ();
613
+ }
593
614
594
615
/* * Return the brief, or nullptr if there is none.
595
-
596
- This function should only be called
597
- after postProcess() has been invoked.
598
616
*/
599
617
doc::Paragraph const *
600
- getBrief () const noexcept
601
- {
602
- return brief_.get ();
603
- }
618
+ brief () const noexcept ;
604
619
605
620
/* * Return the list of top level blocks.
606
621
*/
@@ -610,30 +625,6 @@ struct MRDOX_VISIBLE
610
625
return blocks_;
611
626
}
612
627
613
- /* * Return the element describing the return type.
614
- */
615
- doc::Returns const *
616
- getReturns () const noexcept
617
- {
618
- return returns_.get ();
619
- }
620
-
621
- /* * Return the list of top level blocks.
622
- */
623
- doc::List<doc::Param> const &
624
- getParams () const noexcept
625
- {
626
- return params_;
627
- }
628
-
629
- /* * Return the list of top level blocks.
630
- */
631
- doc::List<doc::TParam> const &
632
- getTParams () const noexcept
633
- {
634
- return tparams_;
635
- }
636
-
637
628
// VFALCO This is unfortunately necessary for
638
629
// the deserialization from bitcode...
639
630
doc::List<doc::Block>&
@@ -651,34 +642,10 @@ struct MRDOX_VISIBLE
651
642
output format.
652
643
*/
653
644
/* * @{ */
654
- MRDOX_DECL bool operator ==(Javadoc const &) const noexcept ;
655
- MRDOX_DECL bool operator !=(Javadoc const &) const noexcept ;
645
+ bool operator ==(Javadoc const &) const noexcept ;
646
+ bool operator !=(Javadoc const &) const noexcept ;
656
647
/* @} */
657
648
658
- /* * Apply post-processing to the final object.
659
-
660
- The implementation calls this function once,
661
- after all doc comments have been merged
662
- and attached, to calculate the brief as
663
- follows:
664
-
665
- @li Sets the brief to the first paragraph
666
- in which a "brief" command exists, or
667
-
668
- @li Sets the first paragraph as the brief if
669
- no "brief" is found.
670
-
671
- @li Otherwise, the brief is set to a
672
- null pointer to indicate absence.
673
-
674
- Furthermore, the Params and TParams are
675
- spliced out of the top level list of
676
- blocks into their own lists.
677
- */
678
- MRDOX_DECL
679
- void
680
- postProcess ();
681
-
682
649
/* * Return an overview of the javadoc.
683
650
684
651
The Javadoc is stored as a list of blocks,
@@ -692,54 +659,35 @@ struct MRDOX_VISIBLE
692
659
the returend overview is invalidated if the
693
660
javadoc object is destroyed.
694
661
*/
695
- MRDOX_DECL doc::Overview makeOverview () const ;
662
+ doc::Overview makeOverview () const ;
696
663
697
664
// --------------------------------------------
698
665
699
- /* * These are used to bottleneck all insertions.
700
- */
701
- /* * @{ */
702
- template <class T , class U >
703
- static
704
- void
705
- append (doc::List<T>& list, doc::List<U>&& other) noexcept
706
- {
707
- list.reserve (list.size () + other.size ());
708
- for (auto & p : other)
709
- list.emplace_back (static_cast <T*>(p.release ()));
710
- other.clear ();
711
- }
666
+ /* * Attempt to append a block.
712
667
713
- template <class T , class Child >
714
- static
715
- void
716
- append (
717
- doc::List<T>& list,
718
- std::unique_ptr<Child>&& child)
719
- {
720
- list.emplace_back (
721
- std::move (child));
722
- }
668
+ @return An empty string on success, otherwise
669
+ a string indicating the reason for the failure.
723
670
724
- template <class Parent , class Child >
725
- static
726
- void
727
- append (
728
- Parent& parent,
729
- std::unique_ptr<Child>&& child)
671
+ @param block The block to append.
672
+ */
673
+ template <std::derived_from<doc::Block> T>
674
+ std::string
675
+ emplace_back (T&& block)
730
676
{
731
- append (parent.children ,
732
- std::move (child));
677
+ return emplace_back (std::make_unique<T>(std::move (block)));
733
678
}
734
679
735
- // --------------------------------------------
680
+ /* * Append blocks from another javadoc to this.
681
+ */
682
+ void append (Javadoc&& other);
683
+
684
+ void append (doc::List<doc::Node>&& blocks);
736
685
737
686
private:
738
- std::unique_ptr<doc::Paragraph> brief_;
739
- std::unique_ptr<doc::Returns> returns_;
687
+ std::string emplace_back (std::unique_ptr<doc::Block>);
688
+
689
+ doc::Paragraph const * brief_ = nullptr ;
740
690
doc::List<doc::Block> blocks_;
741
- doc::List<doc::Param> params_;
742
- doc::List<doc::TParam> tparams_;
743
691
};
744
692
745
693
} // mrdox
0 commit comments