Doctree owns its root node correctly now.

This commit is contained in:
2025-04-20 01:42:39 -04:00
parent 0dc0938c7f
commit f702ca398d

View File

@ -45,19 +45,16 @@ class DoctreeNode {
class Doctree {
private:
DoctreeNode *topNode;
DoctreeNode *rootNode;
std::unique_ptr< DoctreeNode > rootNode= std::make_unique< DoctreeNode >();
int num;
public:
Doctree () {
rootNode = new DoctreeNode;
topNode = rootNode;
topNode = rootNode.get();
num = 0;
};
~Doctree () {
delete rootNode;
};
~Doctree ()= default;
DoctreeNode *push () {
DoctreeNode *dn = new DoctreeNode ();
@ -70,19 +67,19 @@ class Doctree {
};
void pop () {
assert (topNode != rootNode); // never pop the root node
assert (topNode != rootNode.get()); // never pop the root node
topNode = topNode->parent;
};
inline DoctreeNode *top () {
if (topNode != rootNode)
if (topNode != rootNode.get())
return topNode;
else
return NULL;
};
inline DoctreeNode *parent (const DoctreeNode *node) {
if (node->parent != rootNode)
if (node->parent != rootNode.get())
return node->parent;
else
return NULL;