Doctree owns its root node correctly now.
This commit is contained in:
@ -45,19 +45,16 @@ class DoctreeNode {
|
|||||||
class Doctree {
|
class Doctree {
|
||||||
private:
|
private:
|
||||||
DoctreeNode *topNode;
|
DoctreeNode *topNode;
|
||||||
DoctreeNode *rootNode;
|
std::unique_ptr< DoctreeNode > rootNode= std::make_unique< DoctreeNode >();
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Doctree () {
|
Doctree () {
|
||||||
rootNode = new DoctreeNode;
|
topNode = rootNode.get();
|
||||||
topNode = rootNode;
|
|
||||||
num = 0;
|
num = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
~Doctree () {
|
~Doctree ()= default;
|
||||||
delete rootNode;
|
|
||||||
};
|
|
||||||
|
|
||||||
DoctreeNode *push () {
|
DoctreeNode *push () {
|
||||||
DoctreeNode *dn = new DoctreeNode ();
|
DoctreeNode *dn = new DoctreeNode ();
|
||||||
@ -70,19 +67,19 @@ class Doctree {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void pop () {
|
void pop () {
|
||||||
assert (topNode != rootNode); // never pop the root node
|
assert (topNode != rootNode.get()); // never pop the root node
|
||||||
topNode = topNode->parent;
|
topNode = topNode->parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline DoctreeNode *top () {
|
inline DoctreeNode *top () {
|
||||||
if (topNode != rootNode)
|
if (topNode != rootNode.get())
|
||||||
return topNode;
|
return topNode;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline DoctreeNode *parent (const DoctreeNode *node) {
|
inline DoctreeNode *parent (const DoctreeNode *node) {
|
||||||
if (node->parent != rootNode)
|
if (node->parent != rootNode.get())
|
||||||
return node->parent;
|
return node->parent;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user