comparison src/doctree.hh @ 1494:9225a90ad7dd

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.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 07 Jan 2010 16:23:05 +0100
parents e9729d5a1416
children
comparison
equal deleted inserted replaced
1493:a26f03ea99a8 1494:9225a90ad7dd
3 3
4 #include "lout/misc.hh" 4 #include "lout/misc.hh"
5 5
6 class DoctreeNode { 6 class DoctreeNode {
7 public: 7 public:
8 DoctreeNode *parent;
8 int num; // unique ascending id 9 int num; // unique ascending id
9 int depth;
10 int element; 10 int element;
11 lout::misc::SimpleVector<char*> *klass; 11 lout::misc::SimpleVector<char*> *klass;
12 const char *pseudo; 12 const char *pseudo;
13 const char *id; 13 const char *id;
14
15 DoctreeNode () {
16 parent = NULL;
17 klass = NULL;
18 pseudo = NULL;
19 id = NULL;
20 element = 0;
21 };
14 }; 22 };
15 23
16 /** 24 /**
17 * \brief HTML document tree interface. 25 * \brief HTML document tree interface.
18 * 26 *
21 * Currently the Doctree can be represented as stack, however to support 29 * Currently the Doctree can be represented as stack, however to support
22 * CSS adjacent siblings or for future JavaScript support it may have to 30 * CSS adjacent siblings or for future JavaScript support it may have to
23 * be extended to a real tree. 31 * be extended to a real tree.
24 */ 32 */
25 class Doctree { 33 class Doctree {
34 private:
35 DoctreeNode *topNode;
36 int num;
37
26 public: 38 public:
27 virtual ~Doctree () {}; 39 Doctree () {
28 virtual const DoctreeNode *top () = 0; 40 topNode = NULL;
29 virtual const DoctreeNode *parent (const DoctreeNode *node) = 0; 41 num = 0;
42 };
43 ~Doctree () { while (top ()) pop (); };
44 DoctreeNode *push () {
45 DoctreeNode *dn = new DoctreeNode ();
46 dn->parent = topNode;
47 dn->num = num++;
48 topNode = dn;
49 return dn;
50 };
51 void pop () {
52 DoctreeNode *dn = topNode;
53 if (dn) {
54 dFree ((void*) dn->id);
55 if (dn->klass) {
56 for (int i = 0; i < dn->klass->size (); i++)
57 dFree (dn->klass->get(i));
58 delete dn->klass;
59 }
60 topNode = dn->parent;
61 delete dn;
62 }
63 };
64 inline DoctreeNode *top () {
65 return topNode;
66 };
67 inline DoctreeNode *parent (const DoctreeNode *node) {
68 return node->parent;
69 };
30 }; 70 };
31 71
32 #endif 72 #endif