Doxygen
Loading...
Searching...
No Matches
QhpSectionTree Class Reference
Collaboration diagram for QhpSectionTree:

Classes

struct  Node

Public Member Functions

void addSection (const DString &title, const DString &ref)
void incLevel ()
void decLevel ()
void writeToc (TextStream &t) const

Private Member Functions

void traverse (const Node &root, TextStream &t, int indent) const

Private Attributes

Node m_root
Nodem_current = &m_root

Detailed Description

Definition at line 49 of file qhp.cpp.

Member Function Documentation

◆ addSection()

void QhpSectionTree::addSection ( const DString & title,
const DString & ref )
inline

Definition at line 127 of file qhp.cpp.

128 {
129 m_current->children.push_back(std::make_unique<Node>(m_current,title,ref));
130 }
Node * m_current
Definition qhp.cpp:70
std::vector< std::unique_ptr< Node > > children
Definition qhp.cpp:66

References QhpSectionTree::Node::children, and m_current.

◆ decLevel()

void QhpSectionTree::decLevel ( )
inline

Definition at line 137 of file qhp.cpp.

138 {
139 ASSERT(m_current->parent!=nullptr);
140 if (m_current->parent)
141 {
143 }
144 }
#define ASSERT(x)
Definition message.h:142

References ASSERT, m_current, and QhpSectionTree::Node::parent.

◆ incLevel()

void QhpSectionTree::incLevel ( )
inline

Definition at line 131 of file qhp.cpp.

132 {
133 auto newNode = new Node(m_current);
134 m_current->children.push_back(std::unique_ptr<Node>(newNode));
135 m_current = newNode;
136 }

References QhpSectionTree::Node::children, and m_current.

◆ traverse()

void QhpSectionTree::traverse ( const Node & root,
TextStream & t,
int indent ) const
inlineprivate

Definition at line 72 of file qhp.cpp.

73 {
74 /* Input: Output:
75 * =================================================
76 * Section1 <section title=".." ref="..">
77 * Dir1
78 * Section2 <section title=".." ref="..">
79 * Dir2
80 * Section3 <section title=".." ref=".."/>
81 * </section>
82 * </section>
83 * Section4 <section title=".." ref="..>
84 * Dir3
85 * Dir4
86 * Section5 <section title=.." ref=.."/>
87 * </section>
88 * Section6 <section title=".." ref=".."/>
89 */
90 size_t numChildren = root.children.size();
91 size_t i=0;
92 while (i<numChildren)
93 {
94 if (root.children[i]->type==Node::Type::Section)
95 {
96 i++;
97 if (i<numChildren && root.children[i]->type==Node::Type::Dir)
98 {
99 // we have a dir node
100 writeIndent(t,indent);
101 t << "<section title=\"" << convertToXML(root.children[i-1]->title) << "\""
102 << " ref=\"" << convertToXML(root.children[i-1]->ref) << "\">\n";
103 while (i<numChildren && root.children[i]->type==Node::Type::Dir)
104 {
105 traverse(*root.children[i].get(),t,indent+1);
106 i++;
107 }
108 writeIndent(t,indent);
109 t << "</section>\n";
110 }
111 else // we have a leaf section node
112 {
113 writeIndent(t,indent);
114 t << "<section title=\"" << convertToXML(root.children[i-1]->title) << "\""
115 << " ref=\"" << convertToXML(root.children[i-1]->ref) << "\"/>\n";
116 }
117 }
118 else // dir without preceding section (no extra indent)
119 {
120 traverse(*root.children[i].get(),t,indent);
121 i++;
122 }
123 }
124 }
void traverse(const Node &root, TextStream &t, int indent) const
Definition qhp.cpp:72
static void writeIndent(TextStream &t, int indent)
Definition qhp.cpp:41
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3232

References QhpSectionTree::Node::children, convertToXML(), QhpSectionTree::Node::Dir, QhpSectionTree::Node::Section, traverse(), and writeIndent().

Referenced by traverse(), and writeToc().

◆ writeToc()

void QhpSectionTree::writeToc ( TextStream & t) const
inline

Definition at line 145 of file qhp.cpp.

146 {
147 writeIndent(t,2);
148 t << "<toc>\n";
149 traverse(m_root,t,3);
150 writeIndent(t,2);
151 t << "</toc>\n";
152 }
Node m_root
Definition qhp.cpp:69

References m_root, traverse(), and writeIndent().

Member Data Documentation

◆ m_current

Node* QhpSectionTree::m_current = &m_root
private

Definition at line 70 of file qhp.cpp.

Referenced by addSection(), decLevel(), and incLevel().

◆ m_root

Node QhpSectionTree::m_root
private

Definition at line 69 of file qhp.cpp.

Referenced by writeToc().


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