annotate src/doctree.hh @ 2102:e1973d1962c5

rm comment warning about (left|right)-tab
author corvid <corvid@lavabit.com>
date Tue, 21 Jun 2011 00:15:55 +0000
parents 9225a90ad7dd
children
rev   line source
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
1 #ifndef __DOCTREE_HH__
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
2 #define __DOCTREE_HH__
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
3
1214
e9729d5a1416 support multiple classes per doctree node
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1049
diff changeset
4 #include "lout/misc.hh"
e9729d5a1416 support multiple classes per doctree node
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1049
diff changeset
5
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
6 class DoctreeNode {
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
7 public:
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
8 DoctreeNode *parent;
763
df8153796f48 initial implementation of a CSS selector matching optimization
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 562
diff changeset
9 int num; // unique ascending id
562
145b8a4d65b3 tag -> element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 558
diff changeset
10 int element;
1214
e9729d5a1416 support multiple classes per doctree node
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1049
diff changeset
11 lout::misc::SimpleVector<char*> *klass;
558
be6295157b10 adjust pseudo class handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 536
diff changeset
12 const char *pseudo;
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
13 const char *id;
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
14
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
15 DoctreeNode () {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
16 parent = NULL;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
17 klass = NULL;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
18 pseudo = NULL;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
19 id = NULL;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
20 element = 0;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
21 };
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
22 };
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
23
1049
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
24 /**
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
25 * \brief HTML document tree interface.
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
26 *
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
27 * The Doctree class defines the interface to the parsed HTML document tree
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
28 * as it is used for CSS selector matching.
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
29 * Currently the Doctree can be represented as stack, however to support
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
30 * CSS adjacent siblings or for future JavaScript support it may have to
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
31 * be extended to a real tree.
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 763
diff changeset
32 */
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
33 class Doctree {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
34 private:
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
35 DoctreeNode *topNode;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
36 int num;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
37
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
38 public:
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
39 Doctree () {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
40 topNode = NULL;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
41 num = 0;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
42 };
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
43 ~Doctree () { while (top ()) pop (); };
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
44 DoctreeNode *push () {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
45 DoctreeNode *dn = new DoctreeNode ();
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
46 dn->parent = topNode;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
47 dn->num = num++;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
48 topNode = dn;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
49 return dn;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
50 };
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
51 void pop () {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
52 DoctreeNode *dn = topNode;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
53 if (dn) {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
54 dFree ((void*) dn->id);
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
55 if (dn->klass) {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
56 for (int i = 0; i < dn->klass->size (); i++)
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
57 dFree (dn->klass->get(i));
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
58 delete dn->klass;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
59 }
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
60 topNode = dn->parent;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
61 delete dn;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
62 }
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
63 };
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
64 inline DoctreeNode *top () {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
65 return topNode;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
66 };
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
67 inline DoctreeNode *parent (const DoctreeNode *node) {
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
68 return node->parent;
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
69 };
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
70 };
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
71
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
72 #endif