1 | /*
|
---|
2 | * The Apache Software License, Version 1.1
|
---|
3 | *
|
---|
4 | * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
|
---|
5 | * reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * 1. Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | *
|
---|
14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
15 | * notice, this list of conditions and the following disclaimer in
|
---|
16 | * the documentation and/or other materials provided with the
|
---|
17 | * distribution.
|
---|
18 | *
|
---|
19 | * 3. The end-user documentation included with the redistribution,
|
---|
20 | * if any, must include the following acknowledgment:
|
---|
21 | * "This product includes software developed by the
|
---|
22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
25 | *
|
---|
26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
27 | * not be used to endorse or promote products derived from this
|
---|
28 | * software without prior written permission. For written
|
---|
29 | * permission, please contact apache\@apache.org.
|
---|
30 | *
|
---|
31 | * 5. Products derived from this software may not be called "Apache",
|
---|
32 | * nor may "Apache" appear in their name, without prior written
|
---|
33 | * permission of the Apache Software Foundation.
|
---|
34 | *
|
---|
35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
46 | * SUCH DAMAGE.
|
---|
47 | * ====================================================================
|
---|
48 | *
|
---|
49 | * This software consists of voluntary contributions made by many
|
---|
50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
51 | * originally based on software copyright (c) 1999, International
|
---|
52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
53 | * on the Apache Software Foundation, please see
|
---|
54 | * <http://www.apache.org/>.
|
---|
55 | */
|
---|
56 |
|
---|
57 | /*
|
---|
58 | * $Id: DOM_TreeWalker.hpp,v 1.3 2002/11/04 15:04:44 tng Exp $
|
---|
59 | */
|
---|
60 |
|
---|
61 | #ifndef DOM_TreeWalker_HEADER_GUARD_
|
---|
62 | #define DOM_TreeWalker_HEADER_GUARD_
|
---|
63 |
|
---|
64 | #include "DOM_Node.hpp"
|
---|
65 | #include "DOM_NodeFilter.hpp"
|
---|
66 |
|
---|
67 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
68 |
|
---|
69 |
|
---|
70 | class TreeWalkerImpl;
|
---|
71 |
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * <code>DOM_TreeWalker</code> objects are used to navigate a document tree or
|
---|
75 | * subtree using the view of the document defined by its <code>whatToShow</code>
|
---|
76 | * flags and any filters that are defined for the <code>DOM_TreeWalker</code>. Any
|
---|
77 | * function which performs navigation using a <code>DOM_TreeWalker</code> will
|
---|
78 | * automatically support any view defined by a <code>DOM_TreeWalker</code>.
|
---|
79 | *
|
---|
80 | * Omitting nodes from the logical view of a subtree can result in a structure that is
|
---|
81 | * substantially different from the same subtree in the complete, unfiltered document. Nodes
|
---|
82 | * that are siblings in the DOM_TreeWalker view may be children of different, widely separated
|
---|
83 | * nodes in the original view. For instance, consider a Filter that skips all nodes except for
|
---|
84 | * Text nodes and the root node of a document. In the logical view that results, all text
|
---|
85 | * nodes will be siblings and appear as direct children of the root node, no matter how
|
---|
86 | * deeply nested the structure of the original document.
|
---|
87 | *
|
---|
88 | */
|
---|
89 | class CDOM_EXPORT DOM_TreeWalker {
|
---|
90 | public:
|
---|
91 | /** @name Constructors and assignment operator */
|
---|
92 | //@{
|
---|
93 | /**
|
---|
94 | * Default constructor.
|
---|
95 | */
|
---|
96 | DOM_TreeWalker();
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Copy constructor.
|
---|
100 | *
|
---|
101 | * @param other The object to be copied.
|
---|
102 | */
|
---|
103 | DOM_TreeWalker(const DOM_TreeWalker &other);
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Assignment operator.
|
---|
107 | *
|
---|
108 | * @param other The object to be copied.
|
---|
109 | */
|
---|
110 | DOM_TreeWalker & operator = (const DOM_TreeWalker &other);
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Assignment operator. This overloaded variant is provided for
|
---|
114 | * the sole purpose of setting a DOM_NodeIterator to null.
|
---|
115 | *
|
---|
116 | * @param val Only a value of 0, or null, is allowed.
|
---|
117 | */
|
---|
118 | DOM_TreeWalker & operator = (const DOM_NullPtr *val);
|
---|
119 | //@}
|
---|
120 |
|
---|
121 | /** @name Destructor. */
|
---|
122 | //@{
|
---|
123 | /**
|
---|
124 | * Destructor for DOM_TreeWalker.
|
---|
125 | */
|
---|
126 | ~DOM_TreeWalker();
|
---|
127 | //@}
|
---|
128 |
|
---|
129 | /** @name Equality and Inequality operators. */
|
---|
130 | //@{
|
---|
131 | /**
|
---|
132 | * The equality operator.
|
---|
133 | *
|
---|
134 | * @param other The object reference with which <code>this</code> object is compared
|
---|
135 | * @returns True if both <code>DOM_TreeWalker</code>s refer to the same
|
---|
136 | * actual node, or are both null; return false otherwise.
|
---|
137 | */
|
---|
138 | bool operator == (const DOM_TreeWalker & other)const;
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Compare with a pointer. Intended only to allow a convenient
|
---|
142 | * comparison with null.
|
---|
143 | */
|
---|
144 | bool operator == (const DOM_NullPtr *other) const;
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * The inequality operator. See operator ==.
|
---|
148 | */
|
---|
149 | bool operator != (const DOM_TreeWalker & other) const;
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Compare with a pointer. Intended only to allow a convenient
|
---|
153 | * comparison with null.
|
---|
154 | *
|
---|
155 | */
|
---|
156 | bool operator != (const DOM_NullPtr * other) const;
|
---|
157 | //@}
|
---|
158 |
|
---|
159 | /** @name Get functions. */
|
---|
160 | //@{
|
---|
161 | /**
|
---|
162 | * The <code>root</code> node of the <code>TreeWalker</code>, as specified
|
---|
163 | * when it was created.
|
---|
164 | */
|
---|
165 | DOM_Node getRoot();
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Return which node types are presented via the DOM_TreeWalker.
|
---|
169 | * These constants are defined in the DOM_NodeFilter interface.
|
---|
170 | *
|
---|
171 | */
|
---|
172 | unsigned long getWhatToShow();
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Return The filter used to screen nodes.
|
---|
176 | *
|
---|
177 | */
|
---|
178 | DOM_NodeFilter* getFilter();
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Return the expandEntityReferences flag.
|
---|
182 | * The value of this flag determines whether the children of entity reference
|
---|
183 | * nodes are visible to the DOM_TreeWalker. If false, they will be skipped over.
|
---|
184 | *
|
---|
185 | */
|
---|
186 | bool getExpandEntityReferences();
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Return the node at which the DOM_TreeWalker is currently positioned.
|
---|
190 | *
|
---|
191 | */
|
---|
192 | DOM_Node getCurrentNode();
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Moves to and returns the closest visible ancestor node of the current node.
|
---|
196 | * If the search for parentNode attempts to step upward from the DOM_TreeWalker's root
|
---|
197 | * node, or if it fails to find a visible ancestor node, this method retains the
|
---|
198 | * current position and returns null.
|
---|
199 | *
|
---|
200 | */
|
---|
201 | DOM_Node parentNode();
|
---|
202 |
|
---|
203 | /**
|
---|
204 | * Moves the <code>DOM_TreeWalker</code> to the first child of the current node,
|
---|
205 | * and returns the new node. If the current node has no children, returns
|
---|
206 | * <code>null</code>, and retains the current node.
|
---|
207 | *
|
---|
208 | */
|
---|
209 | DOM_Node firstChild();
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Moves the <code>DOM_TreeWalker</code> to the last child of the current node, and
|
---|
213 | * returns the new node. If the current node has no children, returns
|
---|
214 | * <code>null</code>, and retains the current node.
|
---|
215 | *
|
---|
216 | */
|
---|
217 | DOM_Node lastChild();
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Moves the <code>DOM_TreeWalker</code> to the previous sibling of the current
|
---|
221 | * node, and returns the new node. If the current node has no previous sibling,
|
---|
222 | * returns <code>null</code>, and retains the current node.
|
---|
223 | *
|
---|
224 | */
|
---|
225 | DOM_Node previousSibling();
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Moves the <code>DOM_TreeWalker</code> to the next sibling of the current node,
|
---|
229 | * and returns the new node. If the current node has no next sibling, returns
|
---|
230 | * <code>null</code>, and retains the current node.
|
---|
231 | *
|
---|
232 | */
|
---|
233 | DOM_Node nextSibling();
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Moves the <code>DOM_TreeWalker</code> to the previous visible node in document
|
---|
237 | * order relative to the current node, and returns the new node. If the current
|
---|
238 | * node has no previous node,
|
---|
239 | * or if the search for previousNode attempts to step upward from the DOM_TreeWalker's
|
---|
240 | * root node, returns <code>null</code>, and retains the current node.
|
---|
241 | *
|
---|
242 | */
|
---|
243 | DOM_Node previousNode();
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Moves the <code>DOM_TreeWalker</code> to the next visible node in document order
|
---|
247 | * relative to the current node, and returns the new node. If the current node has
|
---|
248 | * no next node,
|
---|
249 | * or if the search for nextNode attempts to step upward from the DOM_TreeWalker's
|
---|
250 | * root node, returns <code>null</code>, and retains the current node.
|
---|
251 | *
|
---|
252 | */
|
---|
253 | DOM_Node nextNode();
|
---|
254 | //@}
|
---|
255 |
|
---|
256 | /** @name Set functions. */
|
---|
257 | //@{
|
---|
258 | /**
|
---|
259 | * Set the node at which the DOM_TreeWalker is currently positioned.
|
---|
260 | *
|
---|
261 | */
|
---|
262 | void setCurrentNode(DOM_Node currentNode);
|
---|
263 | //@}
|
---|
264 |
|
---|
265 |
|
---|
266 | protected:
|
---|
267 | DOM_TreeWalker(TreeWalkerImpl* impl);
|
---|
268 |
|
---|
269 | friend class DOM_Document;
|
---|
270 |
|
---|
271 | private:
|
---|
272 | TreeWalkerImpl* fImpl;
|
---|
273 | };
|
---|
274 |
|
---|
275 | XERCES_CPP_NAMESPACE_END
|
---|
276 |
|
---|
277 | #endif
|
---|