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 46 of file qhp.cpp.

Member Function Documentation

◆ addSection()

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

Definition at line 124 of file qhp.cpp.

125 {
126 m_current->children.push_back(std::make_unique<Node>(m_current,title,ref));
127 }
Node * m_current
Definition qhp.cpp:67
std::vector< std::unique_ptr< Node > > children
Definition qhp.cpp:63

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

◆ decLevel()

void QhpSectionTree::decLevel ( )
inline

Definition at line 134 of file qhp.cpp.

135 {
136 assert(m_current->parent!=nullptr);
137 if (m_current->parent)
138 {
140 }
141 }

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

◆ incLevel()

void QhpSectionTree::incLevel ( )
inline

Definition at line 128 of file qhp.cpp.

129 {
130 auto newNode = new Node(m_current);
131 m_current->children.push_back(std::unique_ptr<Node>(newNode));
132 m_current = newNode;
133 }

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

◆ traverse()

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

Definition at line 69 of file qhp.cpp.

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

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 142 of file qhp.cpp.

143 {
144 writeIndent(t,2);
145 t << "<toc>\n";
146 traverse(m_root,t,3);
147 writeIndent(t,2);
148 t << "</toc>\n";
149 }
Node m_root
Definition qhp.cpp:66

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

Member Data Documentation

◆ m_current

Node* QhpSectionTree::m_current = &m_root
private

Definition at line 67 of file qhp.cpp.

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

◆ m_root

Node QhpSectionTree::m_root
private

Definition at line 66 of file qhp.cpp.

Referenced by writeToc().


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