1 #ifndef __TRAVERSAL_H__
2 #define __TRAVERSAL_H__
4 /**
5 * Phoebe DOM Implementation.
6 *
7 * This is a C++ approximation of the W3C DOM model, which follows
8 * fairly closely the specifications in the various .idl files, copies of
9 * which are provided for reference. Most important is this one:
10 *
11 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
12 *
13 * Authors:
14 * Bob Jamison
15 *
16 * Copyright (C) 2005 Bob Jamison
17 *
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
22 *
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with this library; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 */
34 #include "dom.h"
37 namespace org
38 {
39 namespace w3c
40 {
41 namespace dom
42 {
43 namespace traversal
44 {
47 //Local aliases
48 typedef dom::Node Node;
54 /*#########################################################################
55 ## NodeFilter
56 #########################################################################*/
57 /**
58 *
59 */
60 class NodeFilter
61 {
62 public:
64 // Constants returned by acceptNode
65 typedef enum
66 {
67 FILTER_ACCEPT = 1,
68 FILTER_REJECT = 2,
69 FILTER_SKIP = 3
70 } AcceptNodeReturn;
74 // Constants for whatToShow
75 typedef enum
76 {
77 SHOW_ALL = 0xFFFFFFFF,
78 SHOW_ELEMENT = 0x00000001,
79 SHOW_ATTRIBUTE = 0x00000002,
80 SHOW_TEXT = 0x00000004,
81 SHOW_CDATA_SECTION = 0x00000008,
82 SHOW_ENTITY_REFERENCE = 0x00000010,
83 SHOW_ENTITY = 0x00000020,
84 SHOW_PROCESSING_INSTRUCTION = 0x00000040,
85 SHOW_COMMENT = 0x00000080,
86 SHOW_DOCUMENT = 0x00000100,
87 SHOW_DOCUMENT_TYPE = 0x00000200,
88 SHOW_DOCUMENT_FRAGMENT = 0x00000400,
89 SHOW_NOTATION = 0x00000800
90 } WhatToShowReturn;
92 /**
93 *
94 */
95 virtual short acceptNode(const Node *n)
96 {
97 return 0;
98 }
102 //##################
103 //# Non-API methods
104 //##################
106 /**
107 *
108 */
109 NodeFilter()
110 {}
112 /**
113 *
114 */
115 NodeFilter(const NodeFilter &other)
116 {
117 }
119 /**
120 *
121 */
122 virtual ~NodeFilter() {}
125 };
127 /*#########################################################################
128 ## NodeIterator
129 #########################################################################*/
130 /**
131 *
132 */
133 class NodeIterator
134 {
135 public:
137 /**
138 *
139 */
140 virtual Node *getRoot()
141 {
142 return NULL;
143 }
145 /**
146 *
147 */
148 virtual unsigned long getWhatToShow()
149 { return whatToShow; }
151 /**
152 *
153 */
154 virtual NodeFilter getFilter()
155 { return filter; }
157 /**
158 *
159 */
160 virtual bool getExpandEntityReferences()
161 { return expandEntityReferences; }
163 /**
164 *
165 */
166 virtual Node *nextNode() throw(dom::DOMException)
167 {
168 return NULL;
169 }
171 /**
172 *
173 */
174 virtual Node *previousNode() throw(dom::DOMException)
175 {
176 return NULL;
177 }
179 /**
180 *
181 */
182 virtual void detach()
183 {
184 }
187 //##################
188 //# Non-API methods
189 //##################
191 /**
192 *
193 */
194 NodeIterator() {}
196 /**
197 *
198 */
199 NodeIterator(const NodeIterator &other)
200 {
201 whatToShow = other.whatToShow;
202 filter = other.filter;
203 expandEntityReferences = other.expandEntityReferences;
204 }
206 /**
207 *
208 */
209 virtual ~NodeIterator() {}
211 protected:
213 unsigned long whatToShow;
214 NodeFilter filter;
215 bool expandEntityReferences;
218 };
222 /*#########################################################################
223 ## TreeWalker
224 #########################################################################*/
226 /**
227 *
228 */
229 class TreeWalker
230 {
231 public:
234 /**
235 *
236 */
237 virtual Node *getRoot()
238 {
239 return NULL;
240 }
242 /**
243 *
244 */
245 virtual unsigned long getWhatToShow()
246 { return whatToShow; }
248 /**
249 *
250 */
251 virtual NodeFilter getFilter()
252 { return filter; }
254 /**
255 *
256 */
257 virtual bool getExpandEntityReferences()
258 { return expandEntityReferences; }
260 /**
261 *
262 */
263 virtual Node *getCurrentNode()
264 { return currentNode; }
266 /**
267 *
268 */
269 virtual void setCurrentNode(const Node *val) throw(dom::DOMException)
270 { currentNode = (Node *)val; }
272 /**
273 *
274 */
275 virtual Node *parentNode()
276 {
277 return NULL;
278 }
280 /**
281 *
282 */
283 virtual Node *firstChild()
284 {
285 return NULL;
286 }
288 /**
289 *
290 */
291 virtual Node *lastChild()
292 {
293 return NULL;
294 }
296 /**
297 *
298 */
299 virtual Node *previousSibling()
300 {
301 return NULL;
302 }
304 /**
305 *
306 */
307 virtual Node *nextSibling()
308 {
309 return NULL;
310 }
312 /**
313 *
314 */
315 virtual Node *previousNode()
316 {
317 return NULL;
318 }
320 /**
321 *
322 */
323 virtual Node *nextNode()
324 {
325 return NULL;
326 }
330 //##################
331 //# Non-API methods
332 //##################
334 /**
335 *
336 */
337 TreeWalker() {}
339 /**
340 *
341 */
342 TreeWalker(const TreeWalker &other)
343 {
344 whatToShow = other.whatToShow;
345 filter = other.filter;
346 expandEntityReferences = other.expandEntityReferences;
347 currentNode = other.currentNode;
348 }
350 /**
351 *
352 */
353 virtual ~TreeWalker() {}
356 protected:
358 unsigned long whatToShow;
359 NodeFilter filter;
360 bool expandEntityReferences;
361 Node *currentNode;
363 };
368 /*#########################################################################
369 ## DocumentTraversal
370 #########################################################################*/
372 /**
373 *
374 */
375 class DocumentTraversal
376 {
377 public:
379 /**
380 *
381 */
382 virtual NodeIterator createNodeIterator(const Node *root,
383 unsigned long whatToShow,
384 const NodeFilter *filter,
385 bool entityReferenceExpansion)
386 throw (dom::DOMException)
387 {
388 NodeIterator ret;
389 return ret;
390 }
392 /**
393 *
394 */
395 virtual TreeWalker createTreeWalker(const Node *root,
396 unsigned long whatToShow,
397 const NodeFilter *filter,
398 bool entityReferenceExpansion)
399 throw (dom::DOMException)
400 {
401 TreeWalker ret;
402 return ret;
403 }
406 //##################
407 //# Non-API methods
408 //##################
410 /**
411 *
412 */
413 DocumentTraversal() {}
415 /**
416 *
417 */
418 DocumentTraversal(const DocumentTraversal &other)
419 {}
421 /**
422 *
423 */
424 virtual ~DocumentTraversal() {}
426 };
433 } //namespace traversal
434 } //namespace dom
435 } //namespace w3c
436 } //namespace org
438 #endif /* __TRAVERSAL_H__ */
441 /*#########################################################################
442 ## E N D O F F I L E
443 #########################################################################*/