blob: ef7faa7c5a0dac2eb746a6579ef3659ee6584d41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef __DOCTREE_HH__
#define __DOCTREE_HH__
#include "lout/misc.hh"
class DoctreeNode {
public:
DoctreeNode *parent;
int num; // unique ascending id
int element;
lout::misc::SimpleVector<char*> *klass;
const char *pseudo;
const char *id;
DoctreeNode () {
parent = NULL;
klass = NULL;
pseudo = NULL;
id = NULL;
element = 0;
};
};
/**
* \brief HTML document tree interface.
*
* The Doctree class defines the interface to the parsed HTML document tree
* as it is used for CSS selector matching.
* Currently the Doctree can be represented as stack, however to support
* CSS adjacent siblings or for future JavaScript support it may have to
* be extended to a real tree.
*/
class Doctree {
private:
DoctreeNode *topNode;
int num;
public:
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
|