Code

add proper unix socket includes
[inkscape.git] / src / dom / xpathtoken.cpp
1 /**\r
2  * Phoebe DOM Implementation.\r
3  *\r
4  * This is a C++ approximation of the W3C DOM model, which follows\r
5  * fairly closely the specifications in the various .idl files, copies of\r
6  * which are provided for reference.  Most important is this one:\r
7  *\r
8  * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html\r
9  *\r
10  * Authors:\r
11  *   Bob Jamison\r
12  *\r
13  * Copyright (C) 2005 Bob Jamison\r
14  *\r
15  *  This library is free software; you can redistribute it and/or\r
16  *  modify it under the terms of the GNU Lesser General Public\r
17  *  License as published by the Free Software Foundation; either\r
18  *  version 2.1 of the License, or (at your option) any later version.\r
19  *\r
20  *  This library is distributed in the hope that it will be useful,\r
21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
23  *  Lesser General Public License for more details.\r
24  *\r
25  *  You should have received a copy of the GNU Lesser General Public\r
26  *  License along with this library; if not, write to the Free Software\r
27  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
28  */\r
29 \r
30 \r
31 #include "xpathtoken.h"\r
32 #include <stdio.h>\r
33 \r
34 \r
35 \r
36 namespace org\r
37 {\r
38 namespace w3c\r
39 {\r
40 namespace dom\r
41 {\r
42 namespace xpath\r
43 {\r
44 \r
45 \r
46 //########################################################################\r
47 //# X P A T H    S T A C K    I T E M\r
48 //########################################################################\r
49 \r
50 /**\r
51  *\r
52  */\r
53 StackItem::StackItem()\r
54 {\r
55     ival = 0L;\r
56     dval = 0.0;\r
57 }\r
58 \r
59 \r
60 /**\r
61  *\r
62  */\r
63 StackItem::StackItem(const StackItem &other)\r
64 {\r
65     sval = other.sval;\r
66     ival = other.ival;\r
67     dval = other.dval;\r
68 }\r
69 \r
70 \r
71 /**\r
72  *\r
73  */\r
74 StackItem::~StackItem()\r
75 {\r
76 }\r
77 \r
78 \r
79 //########################################################################\r
80 //# X P A T H    S T A C K\r
81 //########################################################################\r
82 \r
83 /**\r
84  *\r
85  */\r
86 Stack::Stack()\r
87 {\r
88     size = 0;\r
89 }\r
90 \r
91 \r
92 /**\r
93  *\r
94  */\r
95 Stack::Stack(const Stack &other)\r
96 {\r
97     size = other.size;\r
98     for (int i=0 ; i<size ; i++)\r
99         items[i] = other.items[i];\r
100 }\r
101 \r
102 \r
103 /**\r
104  *\r
105  */\r
106 Stack::~Stack()\r
107 {\r
108 }\r
109 \r
110 /**\r
111  *\r
112  */\r
113 void Stack::push(StackItem &item)\r
114 {\r
115     if (size>=STACK_SIZE)\r
116         {\r
117         return;\r
118         }\r
119     items[size++] = item;\r
120 }\r
121 \r
122 /**\r
123  *\r
124  */\r
125 StackItem Stack::pop()\r
126 {\r
127     if (size<1)\r
128         {\r
129         StackItem item;\r
130         return item;\r
131         }\r
132     return items[--size];\r
133 }\r
134 \r
135 \r
136 \r
137 //########################################################################\r
138 //# T O K E N    L I S T\r
139 //########################################################################\r
140 \r
141 /**\r
142  *\r
143  */\r
144 TokenList::TokenList()\r
145 {\r
146 }\r
147 \r
148 \r
149 /**\r
150  *\r
151  */\r
152 TokenList::~TokenList()\r
153 {\r
154     clear();\r
155 }\r
156 \r
157 /**\r
158  *\r
159  */\r
160 void TokenList::clear()\r
161 {\r
162     std::vector<Token *>::iterator iter;\r
163     for (iter = tokens.begin() ; iter!= tokens.end() ; iter++)\r
164         {\r
165         delete (*iter);\r
166         }\r
167     tokens.clear();\r
168 }\r
169 \r
170 /**\r
171  *\r
172  */\r
173 void TokenList::add(Token *tok)\r
174 {\r
175     tokens.push_back(tok);\r
176 }\r
177 \r
178 /**\r
179  *  This method "executes" a list of Tokens in the context of a DOM root\r
180  *  Node, returning a list of Nodes that match the xpath expression.\r
181  */\r
182 NodeList TokenList::execute(const Node *root)\r
183 {\r
184     NodeList list;\r
185 \r
186     if (!root)\r
187         return list;\r
188 \r
189     Stack stack;\r
190     //### Execute the token list\r
191     std::vector<Token *>::iterator iter;\r
192     for (iter = tokens.begin() ; iter != tokens.end() ; iter++)\r
193         {\r
194         Token *tok = *iter;\r
195         tok->execute(stack, list);\r
196         }\r
197 \r
198     return list;\r
199 }\r
200 \r
201 \r
202 /**\r
203  *\r
204  */\r
205 void TokenList::dump()\r
206 {\r
207     std::vector<Token *>::iterator iter;\r
208     printf("############# TOKENS\n");\r
209     for (iter = tokens.begin() ; iter != tokens.end() ; iter++)\r
210         {\r
211         Token *tok = *iter;\r
212         tok->dump();\r
213         }\r
214 }\r
215 \r
216 \r
217 \r
218 \r
219 \r
220 } // namespace xpath\r
221 } // namespace dom\r
222 } // namespace w3c\r
223 } // namespace org\r
224 //########################################################################\r
225 //# E N D    O F    F I L E\r
226 //########################################################################\r
227 \r
228 \r
229 \r