diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-01-07 16:23:05 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2010-01-07 16:23:05 +0100 |
commit | a153bb89aaa85933d9619b4ffbff98a90baa7324 (patch) | |
tree | 640ba92a8f6fc722d305f9c7fb47545164074a88 /src/doctree.hh | |
parent | c931cda3a9797da8ffd3ad24562a88837f5f4773 (diff) |
make Doctree a non-virtual class
Doctree now is a proper class with it's own implementation.
StyleEngine no longer needs to provide the Doctree interface itself.
This hopefully make the code easier to understand and should also be
a bit faster as no virtual methods are involved.
Diffstat (limited to 'src/doctree.hh')
-rw-r--r-- | src/doctree.hh | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/doctree.hh b/src/doctree.hh index 30762e44..ef7faa7c 100644 --- a/src/doctree.hh +++ b/src/doctree.hh @@ -5,12 +5,20 @@ class DoctreeNode { public: + DoctreeNode *parent; int num; // unique ascending id - int depth; int element; lout::misc::SimpleVector<char*> *klass; const char *pseudo; const char *id; + + DoctreeNode () { + parent = NULL; + klass = NULL; + pseudo = NULL; + id = NULL; + element = 0; + }; }; /** @@ -23,10 +31,42 @@ class DoctreeNode { * be extended to a real tree. */ class Doctree { + private: + DoctreeNode *topNode; + int num; + public: - virtual ~Doctree () {}; - virtual const DoctreeNode *top () = 0; - virtual const DoctreeNode *parent (const DoctreeNode *node) = 0; + Doctree () { + topNode = NULL; + num = 0; + }; + ~Doctree () { while (top ()) pop (); }; + DoctreeNode *push () { + DoctreeNode *dn = new DoctreeNode (); + dn->parent = topNode; + dn->num = num++; + topNode = dn; + return dn; + }; + void pop () { + DoctreeNode *dn = topNode; + if (dn) { + dFree ((void*) dn->id); + if (dn->klass) { + for (int i = 0; i < dn->klass->size (); i++) + dFree (dn->klass->get(i)); + delete dn->klass; + } + topNode = dn->parent; + delete dn; + } + }; + inline DoctreeNode *top () { + return topNode; + }; + inline DoctreeNode *parent (const DoctreeNode *node) { + return node->parent; + }; }; #endif |