Doxygen
Loading...
Searching...
No Matches
DocSection Class Referencefinal

Node representing a normal section. More...

#include <src/docnode.h>

Inheritance diagram for DocSection:
Collaboration diagram for DocSection:

Public Member Functions

 DocSection (DocParser *parser, DocNodeVariant *parent, int level, const DString &id)
int level () const
const DocNodeVariant * title () const
DString anchor () const
DString id () const
DString file () const
Token parse ()
Public Member Functions inherited from DocCompoundNode
 DocCompoundNode (DocParser *parser, DocNodeVariant *parent)
DocNodeList & children ()
const DocNodeList & children () const
Public Member Functions inherited from DocNode
 DocNode (DocParser *parser, DocNodeVariant *parent)
 ~DocNode ()=default
DocNodeVariant * parent ()
const DocNodeVariant * parent () const
DocNodeVariant * thisVariant ()
const DocNodeVariant * thisVariant () const
void setThisVariant (DocNodeVariant *thisVariant)
DocParser * parser ()
const DocParser * parser () const
void setParent (DocNodeVariant *parent)
bool isPreformatted () const

Private Attributes

int m_level = 0
DString m_id
std::unique_ptr< DocNodeVariant > m_title
DString m_anchor
DString m_file

Additional Inherited Members

Protected Types inherited from DocNode
enum  RefType {
  Unknown , Anchor , Section , Table ,
  Requirement
}
Protected Member Functions inherited from DocNode
void setInsidePreformatted (bool p)

Detailed Description

Node representing a normal section.

Definition at line 922 of file docnode.h.

Constructor & Destructor Documentation

◆ DocSection()

DocSection::DocSection ( DocParser * parser,
DocNodeVariant * parent,
int level,
const DString & id )
inline

Definition at line 925 of file docnode.h.

925 :
DocCompoundNode(DocParser *parser, DocNodeVariant *parent)
Definition docnode.h:141
DocParser * parser()
Definition docnode.h:97
DocNodeVariant * parent()
Definition docnode.h:89
int level() const
Definition docnode.h:927
DString m_id
Definition docnode.h:936
int m_level
Definition docnode.h:935

References DocCompoundNode::DocCompoundNode(), id(), level(), m_id, m_level, DocNode::parent(), and DocNode::parser().

Referenced by parse().

Member Function Documentation

◆ anchor()

DString DocSection::anchor ( ) const
inline

◆ file()

DString DocSection::file ( ) const
inline

◆ id()

DString DocSection::id ( ) const
inline

Definition at line 930 of file docnode.h.

930{ return m_id; }

References m_id.

Referenced by DocSection().

◆ level()

◆ parse()

Token DocSection::parse ( )

Definition at line 6084 of file docnode.cpp.

6085{
6086 AUTO_TRACE("start {} level={}", parser()->context.token->sectionId, m_level);
6087 Token retval = Token::make_RetVal_OK();
6088 auto ns = AutoNodeStack(parser(),thisVariant());
6089
6090 if (!m_id.empty())
6091 {
6092 const SectionInfo *sec = SectionManager::instance().find(m_id);
6093 if (sec)
6094 {
6095 m_file = sec->fileName();
6096 m_anchor = sec->label();
6097 DString titleStr = sec->title();
6098 if (titleStr.empty()) titleStr = sec->label();
6100 DocTitle *title = &std::get<DocTitle>(*m_title);
6101 title->parseFromString(thisVariant(),titleStr);
6102 }
6103 }
6104
6105 // first parse any number of paragraphs
6106 bool isFirst=true;
6107 DocPara *lastPar=nullptr;
6108 do
6109 {
6110 children().append<DocPara>(parser(),thisVariant());
6111 DocPara *par = children().get_last<DocPara>();
6112 if (isFirst) { par->markFirst(); isFirst=false; }
6113 retval=par->parse();
6114 if (!par->empty())
6115 {
6116 if (lastPar) lastPar->markLast(false);
6117 lastPar = par;
6118 }
6119 else
6120 {
6121 children().pop_back();
6122 }
6123 if (retval.is(TokenRetval::TK_LISTITEM))
6124 {
6125 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"Invalid list item found");
6126 }
6127 if (retval.is(TokenRetval::RetVal_Internal))
6128 {
6129 children().append<DocInternal>(parser(),thisVariant());
6130 retval = children().get_last<DocInternal>()->parse(m_level+1);
6131 if (retval.is(TokenRetval::RetVal_EndInternal))
6132 {
6133 retval = Token::make_RetVal_OK();
6134 }
6135 }
6136 } while (!retval.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF, TokenRetval::RetVal_Section, TokenRetval::RetVal_Subsection,
6137 TokenRetval::RetVal_Subsubsection, TokenRetval::RetVal_Paragraph, TokenRetval::RetVal_SubParagraph,
6138 TokenRetval::RetVal_SubSubParagraph, TokenRetval::RetVal_EndInternal)
6139 );
6140
6141 if (lastPar) lastPar->markLast();
6142
6143 while (true)
6144 {
6145 if (retval.is(TokenRetval::RetVal_Subsection) && m_level<=1)
6146 {
6147 // then parse any number of nested sections
6148 while (retval.is(TokenRetval::RetVal_Subsection)) // more sections follow
6149 {
6151 2,
6153 retval = children().get_last<DocSection>()->parse();
6154 }
6155 break;
6156 }
6157 else if (retval.is(TokenRetval::RetVal_Subsubsection) && m_level<=2)
6158 {
6159 if ((m_level <= 1) &&
6160 !AnchorGenerator::instance().isGenerated(parser()->context.token->sectionId.str()))
6161 {
6162 warn_doc_error(parser()->context.fileName,
6163 parser()->tokenizer.getLineNr(),
6164 "Unexpected subsubsection command found inside {}!",
6166 }
6167 // then parse any number of nested sections
6168 while (retval.is(TokenRetval::RetVal_Subsubsection)) // more sections follow
6169 {
6171 3,
6173 retval = children().get_last<DocSection>()->parse();
6174 }
6175 if (!(m_level < 2 && retval.is(TokenRetval::RetVal_Subsection))) break;
6176 }
6177 else if (retval.is(TokenRetval::RetVal_Paragraph) && m_level<=3)
6178 {
6179 if ((m_level <= 2) &&
6180 !AnchorGenerator::instance().isGenerated(parser()->context.token->sectionId.str()))
6181 {
6182 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),
6183 "Unexpected paragraph command found inside {}!",
6185 }
6186 // then parse any number of nested sections
6187 while (retval.is(TokenRetval::RetVal_Paragraph)) // more sections follow
6188 {
6190 4,
6192 retval = children().get_last<DocSection>()->parse();
6193 }
6194 if (!(m_level<3 && (retval.is_any_of(TokenRetval::RetVal_Subsection,TokenRetval::RetVal_Subsubsection)))) break;
6195 }
6196 else if (retval.is(TokenRetval::RetVal_SubParagraph) && m_level<=4)
6197 {
6198 if ((m_level <= 3) &&
6199 !AnchorGenerator::instance().isGenerated(parser()->context.token->sectionId.str()))
6200 {
6201 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),
6202 "Unexpected subparagraph command found inside {}!",
6204 }
6205 // then parse any number of nested sections
6206 while (retval.is(TokenRetval::RetVal_SubParagraph)) // more sections follow
6207 {
6209 5,
6211 retval = children().get_last<DocSection>()->parse();
6212 }
6213 if (!(m_level<4 && (retval.is_any_of(TokenRetval::RetVal_Subsection,TokenRetval::RetVal_Subsubsection,TokenRetval::RetVal_Paragraph)))) break;
6214 }
6215 else if (retval.is(TokenRetval::RetVal_SubSubParagraph) && m_level<=5)
6216 {
6217 if ((m_level <= 4) &&
6218 !AnchorGenerator::instance().isGenerated(parser()->context.token->sectionId.str()))
6219 {
6220 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),
6221 "Unexpected subsubparagraph command found inside {}!",
6223 }
6224 // then parse any number of nested sections
6225 while (retval.is(TokenRetval::RetVal_SubSubParagraph)) // more sections follow
6226 {
6228 6,
6230 retval = children().get_last<DocSection>()->parse();
6231 }
6232 if (!(m_level<5 && (retval.is_any_of( TokenRetval::RetVal_Subsection, TokenRetval::RetVal_Subsubsection,
6233 TokenRetval::RetVal_Paragraph, TokenRetval::RetVal_SubParagraph)))) break;
6234 }
6235 else
6236 {
6237 break;
6238 }
6239 }
6240
6241 INTERNAL_ASSERT(retval.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF,
6242 TokenRetval::RetVal_Section, TokenRetval::RetVal_Subsection,
6243 TokenRetval::RetVal_Subsubsection, TokenRetval::RetVal_Paragraph,
6244 TokenRetval::RetVal_SubParagraph, TokenRetval::RetVal_SubSubParagraph,
6245 TokenRetval::RetVal_Internal, TokenRetval::RetVal_EndInternal)
6246 );
6247
6248 AUTO_TRACE_EXIT("retval={}", retval.to_string());
6249 return retval;
6250}
static AnchorGenerator & instance()
Returns the singleton instance.
Definition anchor.cpp:41
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
DocNodeList & children()
Definition docnode.h:143
DocNodeVariant * thisVariant()
Definition docnode.h:92
void append(Args &&... args)
Append a new DocNodeVariant to the list by constructing it with type T and parameters Args.
Definition docnode.h:1404
T * get_last()
Returns a pointer to the last element in the list if that element exists and holds a T,...
Definition docnode.h:1415
void markLast(bool v=true)
Definition docnode.h:1095
DocParserContext context
std::unique_ptr< DocNodeVariant > m_title
Definition docnode.h:937
DocSection(DocParser *parser, DocNodeVariant *parent, int level, const DString &id)
Definition docnode.h:925
Token parse()
Definition docnode.cpp:6084
const DocNodeVariant * title() const
Definition docnode.h:928
void parseFromString(DocNodeVariant *, const DString &title)
Definition docnode.cpp:3221
void pop_back()
removes the last element
Definition growvector.h:115
const T * find(const std::string &key) const
Definition linkedmap.h:47
DString fileName() const
Definition section.h:74
DString title() const
Definition section.h:70
DString label() const
Definition section.h:69
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
bool is(TokenRetval rv) const
TOKEN_SPECIFICATIONS RETVAL_SPECIFICATIONS const char * to_string() const
bool is_any_of(ARGS... args) const
DString sectionId
static const char * g_sectionLevelToName[]
Definition docnode.cpp:63
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define INTERNAL_ASSERT(x)
Definition docnode.cpp:58
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
std::unique_ptr< DocNodeVariant > createDocNode(Args &&...args)
Definition docnode.h:1500
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
TokenInfo * token
Definition docparser_p.h:94

References DocNodeList::append(), AUTO_TRACE, AUTO_TRACE_EXIT, DocCompoundNode::children(), DocParser::context, createDocNode(), DocSection(), DString::empty(), SectionInfo::fileName(), LinkedMap< T, Hash, KeyEqual, Map >::find(), g_sectionLevelToName, DocNodeList::get_last(), AnchorGenerator::instance(), SectionManager::instance(), INTERNAL_ASSERT, Token::is(), Token::is_any_of(), SectionInfo::label(), m_anchor, m_file, m_id, m_level, m_title, DocPara::markLast(), parse(), DocTitle::parseFromString(), DocNode::parser(), GrowVector< T >::pop_back(), TokenInfo::sectionId, DocNode::thisVariant(), title(), SectionInfo::title(), Token::to_string(), DocParserContext::token, and warn_doc_error.

Referenced by parse().

◆ title()

Member Data Documentation

◆ m_anchor

DString DocSection::m_anchor
private

Definition at line 938 of file docnode.h.

Referenced by anchor(), and parse().

◆ m_file

DString DocSection::m_file
private

Definition at line 939 of file docnode.h.

Referenced by file(), and parse().

◆ m_id

DString DocSection::m_id
private

Definition at line 936 of file docnode.h.

Referenced by DocSection(), id(), and parse().

◆ m_level

int DocSection::m_level = 0
private

Definition at line 935 of file docnode.h.

Referenced by DocSection(), level(), and parse().

◆ m_title

std::unique_ptr<DocNodeVariant> DocSection::m_title
private

Definition at line 937 of file docnode.h.

Referenced by parse(), and title().


The documentation for this class was generated from the following files: