1 | #ifndef DOMXPathResult_HEADER_GUARD_ |
---|
2 | #define DOMXPathResult_HEADER_GUARD_ |
---|
3 | |
---|
4 | /* |
---|
5 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
6 | * contributor license agreements. See the NOTICE file distributed with |
---|
7 | * this work for additional information regarding copyright ownership. |
---|
8 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
9 | * (the "License"); you may not use this file except in compliance with |
---|
10 | * the License. You may obtain a copy of the License at |
---|
11 | * |
---|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
13 | * |
---|
14 | * Unless required by applicable law or agreed to in writing, software |
---|
15 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
17 | * See the License for the specific language governing permissions and |
---|
18 | * limitations under the License. |
---|
19 | */ |
---|
20 | |
---|
21 | #include <xercesc/util/XercesDefs.hpp> |
---|
22 | |
---|
23 | XERCES_CPP_NAMESPACE_BEGIN |
---|
24 | |
---|
25 | class DOMXPathNSResolver; |
---|
26 | class DOMXPathExpression; |
---|
27 | class DOMNode; |
---|
28 | |
---|
29 | /** |
---|
30 | * The <code>DOMXPathResult</code> interface represents the result of the |
---|
31 | * evaluation of an XPath 1.0 expression within the context of a particular |
---|
32 | * node. Since evaluation of an XPath expression can result in various result |
---|
33 | * types, this object makes it possible to discover and manipulate the type |
---|
34 | * and value of the result. |
---|
35 | * @since DOM Level 3 |
---|
36 | */ |
---|
37 | class CDOM_EXPORT DOMXPathResult |
---|
38 | { |
---|
39 | |
---|
40 | protected: |
---|
41 | // ----------------------------------------------------------------------- |
---|
42 | // Hidden constructors |
---|
43 | // ----------------------------------------------------------------------- |
---|
44 | /** @name Hidden constructors */ |
---|
45 | //@{ |
---|
46 | DOMXPathResult() {}; |
---|
47 | //@} |
---|
48 | |
---|
49 | private: |
---|
50 | // ----------------------------------------------------------------------- |
---|
51 | // Unimplemented constructors and operators |
---|
52 | // ----------------------------------------------------------------------- |
---|
53 | /** @name Unimplemented constructors and operators */ |
---|
54 | //@{ |
---|
55 | DOMXPathResult(const DOMXPathResult &); |
---|
56 | DOMXPathResult& operator = (const DOMXPathResult&); |
---|
57 | //@} |
---|
58 | |
---|
59 | public: |
---|
60 | // ----------------------------------------------------------------------- |
---|
61 | // All constructors are hidden, just the destructor is available |
---|
62 | // ----------------------------------------------------------------------- |
---|
63 | /** @name Destructor */ |
---|
64 | //@{ |
---|
65 | /** |
---|
66 | * Destructor |
---|
67 | * |
---|
68 | */ |
---|
69 | virtual ~DOMXPathResult() {}; |
---|
70 | //@} |
---|
71 | |
---|
72 | // ----------------------------------------------------------------------- |
---|
73 | // Class Types |
---|
74 | // ----------------------------------------------------------------------- |
---|
75 | /** @name Public Contants */ |
---|
76 | //@{ |
---|
77 | /** |
---|
78 | * <p>ANY_TYPE |
---|
79 | * <br>This code does not represent a specific type. An evaluation of an XPath |
---|
80 | * expression will never produce this type. If this type is requested, then |
---|
81 | * the evaluation returns whatever type naturally results from evaluation |
---|
82 | * of the expression. |
---|
83 | * If the natural result is a node set when ANY_TYPE was requested, then |
---|
84 | * UNORDERED_NODE_ITERATOR_TYPE is always the resulting type. Any other |
---|
85 | * representation of a node set must be explicitly requested. |
---|
86 | * <p>ANY_UNORDERED_NODE_TYPE |
---|
87 | * <br>The result is a node set as defined by [XPath 1.0] and will be accessed |
---|
88 | * as a single node, which may be nullif the node set is empty. Document |
---|
89 | * modification does not invalidate the node, but may mean that the result |
---|
90 | * node no longer corresponds to the current document. This is a convenience |
---|
91 | * that permits optimization since the implementation can stop once any node |
---|
92 | * in the resulting set has been found. |
---|
93 | * If there is more than one node in the actual result, the single node |
---|
94 | * returned might not be the first in document order. |
---|
95 | * <p>BOOLEAN_TYPE |
---|
96 | * <br>The result is a boolean as defined by [XPath 1.0]. Document modification |
---|
97 | * does not invalidate the boolean, but may mean that reevaluation would not |
---|
98 | * yield the same boolean. |
---|
99 | * <p>FIRST_ORDERED_NODE_TYPE |
---|
100 | * <br>The result is a node set as defined by [XPath 1.0] and will be accessed |
---|
101 | * as a single node, which may be null if the node set is empty. Document |
---|
102 | * modification does not invalidate the node, but may mean that the result |
---|
103 | * node no longer corresponds to the current document. This is a convenience |
---|
104 | * that permits optimization since the implementation can stop once the first |
---|
105 | * node in document order of the resulting set has been found. |
---|
106 | * If there are more than one node in the actual result, the single node |
---|
107 | * returned will be the first in document order. |
---|
108 | * <p>NUMBER_TYPE |
---|
109 | * <br>The result is a number as defined by [XPath 1.0]. Document modification does |
---|
110 | * not invalidate the number, but may mean that reevaluation would not yield the |
---|
111 | * same number. |
---|
112 | * <p>ORDERED_NODE_ITERATOR_TYPE |
---|
113 | * <br>The result is a node set as defined by [XPath 1.0] that will be accessed |
---|
114 | * iteratively, which will produce document-ordered nodes. Document modification |
---|
115 | * invalidates the iteration. |
---|
116 | * <p>ORDERED_NODE_SNAPSHOT_TYPE |
---|
117 | * <br>The result is a node set as defined by [XPath 1.0] that will be accessed as a |
---|
118 | * snapshot list of nodes that will be in original document order. Document |
---|
119 | * modification does not invalidate the snapshot but may mean that reevaluation would |
---|
120 | * not yield the same snapshot and nodes in the snapshot may have been altered, moved, |
---|
121 | * or removed from the document. |
---|
122 | * <p>STRING_TYPE |
---|
123 | * <br>The result is a string as defined by [XPath 1.0]. Document modification does not |
---|
124 | * invalidate the string, but may mean that the string no longer corresponds to the |
---|
125 | * current document. |
---|
126 | * <p>UNORDERED_NODE_ITERATOR_TYPE |
---|
127 | * <br>The result is a node set as defined by [XPath 1.0] that will be accessed iteratively, |
---|
128 | * which may not produce nodes in a particular order. Document modification invalidates the iteration. |
---|
129 | * This is the default type returned if the result is a node set and ANY_TYPE is requested. |
---|
130 | * <p>UNORDERED_NODE_SNAPSHOT_TYPE |
---|
131 | * <br>The result is a node set as defined by [XPath 1.0] that will be accessed as a |
---|
132 | * snapshot list of nodes that may not be in a particular order. Document modification |
---|
133 | * does not invalidate the snapshot but may mean that reevaluation would not yield the same |
---|
134 | * snapshot and nodes in the snapshot may have been altered, moved, or removed from the document. |
---|
135 | */ |
---|
136 | enum resultType { |
---|
137 | ANY_TYPE = 0, |
---|
138 | NUMBER_TYPE = 1, |
---|
139 | STRING_TYPE = 2, |
---|
140 | BOOLEAN_TYPE = 3, |
---|
141 | UNORDERED_NODE_ITERATOR_TYPE = 4, |
---|
142 | ORDERED_NODE_ITERATOR_TYPE = 5, |
---|
143 | UNORDERED_NODE_SNAPSHOT_TYPE = 6, |
---|
144 | ORDERED_NODE_SNAPSHOT_TYPE = 7, |
---|
145 | ANY_UNORDERED_NODE_TYPE = 8, |
---|
146 | FIRST_ORDERED_NODE_TYPE = 9 |
---|
147 | }; |
---|
148 | //@} |
---|
149 | |
---|
150 | |
---|
151 | // ----------------------------------------------------------------------- |
---|
152 | // Virtual DOMDocument interface |
---|
153 | // ----------------------------------------------------------------------- |
---|
154 | /** @name Functions introduced in DOM Level 3 */ |
---|
155 | //@{ |
---|
156 | |
---|
157 | |
---|
158 | /** |
---|
159 | * Returns the boolean value of this result |
---|
160 | * @return booleanValue of type boolean, readonly |
---|
161 | * The value of this boolean result. |
---|
162 | * @exception XPathException |
---|
163 | * TYPE_ERR: raised if resultType is not BOOLEAN_TYPE. |
---|
164 | */ |
---|
165 | virtual bool getBooleanValue() const = 0; |
---|
166 | |
---|
167 | /** |
---|
168 | * Returns the state of the iterator |
---|
169 | * @return invalidIteratorState |
---|
170 | * Signifies that the iterator has become invalid. True if resultType is |
---|
171 | * UNORDERED_NODE_ITERATOR_TYPE or ORDERED_NODE_ITERATOR_TYPE and the |
---|
172 | * document has been modified since this result was returned. |
---|
173 | * @exception XPathException |
---|
174 | * TYPE_ERR: raised if resultType is not NUMBER_TYPE. |
---|
175 | */ |
---|
176 | virtual bool getInvalidIteratorState() const = 0; |
---|
177 | |
---|
178 | /** |
---|
179 | * Returns the number value of this result |
---|
180 | * @return numberValue |
---|
181 | * The value of this number result. If the native double type of the DOM |
---|
182 | * binding does not directly support the exact IEEE 754 result of the XPath |
---|
183 | * expression, then it is up to the definition of the binding to specify how |
---|
184 | * the XPath number is converted to the native binding number. |
---|
185 | * @exception XPathException |
---|
186 | * TYPE_ERR: raised if resultType is not NUMBER_TYPE. |
---|
187 | */ |
---|
188 | virtual double getNumberValue() const = 0; |
---|
189 | |
---|
190 | /** |
---|
191 | * Returns the result type of this result |
---|
192 | * @return resultType |
---|
193 | * A code representing the type of this result, as defined by the type constants. |
---|
194 | * @exception XPathException |
---|
195 | * TYPE_ERR: raised if resultType is not ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE. |
---|
196 | */ |
---|
197 | virtual short getResultType() const = 0; |
---|
198 | |
---|
199 | /** |
---|
200 | * Returns the single node value of this result |
---|
201 | * @return singleNodeValue |
---|
202 | * The value of this single node result, which may be null. |
---|
203 | * @exception XPathException |
---|
204 | * TYPE_ERR: raised if resultType is not ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE. |
---|
205 | */ |
---|
206 | virtual DOMNode *getSingleNodeValue() const = 0; |
---|
207 | |
---|
208 | /** |
---|
209 | * Returns the snapshot length |
---|
210 | * @return snapshotLength |
---|
211 | * The number of nodes in the result snapshot. Valid values for snapshotItem indices |
---|
212 | * are 0 to snapshotLength-1 inclusive. |
---|
213 | * @exception XPathException |
---|
214 | * TYPE_ERR: raised if resultType is not UNORDERED_NODE_SNAPSHOT_TYPE or |
---|
215 | * ORDERED_NODE_SNAPSHOT_TYPE. |
---|
216 | */ |
---|
217 | virtual unsigned long getSnapshotLength() const = 0; |
---|
218 | |
---|
219 | /** |
---|
220 | * Returns the string value of this result |
---|
221 | * @return stringValue |
---|
222 | * The value of this string result. |
---|
223 | * @exception XPathException |
---|
224 | * TYPE_ERR: raised if resultType is not STRING_TYPE. |
---|
225 | */ |
---|
226 | virtual const XMLCh* getStringValue() const = 0; |
---|
227 | |
---|
228 | /** |
---|
229 | * Iterates and returns the next node from the node set or nullif there are no more nodes. |
---|
230 | * @return the next node. |
---|
231 | * @exception XPathException |
---|
232 | * TYPE_ERR: raised if resultType is not UNORDERED_NODE_ITERATOR_TYPE or ORDERED_NODE_ITERATOR_TYPE. |
---|
233 | * @exception DOMException |
---|
234 | * INVALID_STATE_ERR: The document has been mutated since the result was returned. |
---|
235 | */ |
---|
236 | virtual DOMNode* iterateNext() const = 0; |
---|
237 | |
---|
238 | /** |
---|
239 | * Returns the indexth item in the snapshot collection. If index is greater than or |
---|
240 | * equal to the number of nodes in the list, this method returns null. Unlike the |
---|
241 | * iterator result, the snapshot does not become invalid, but may not correspond |
---|
242 | * to the current document if it is mutated. |
---|
243 | * @param index of type unsigned long - Index into the snapshot collection. |
---|
244 | * @return The node at the indexth position in the NodeList, or null if that is not a valid index. |
---|
245 | * @exception XPathException |
---|
246 | * TYPE_ERR: raised if resultType is not UNORDERED_NODE_SNAPSHOT_TYPE or ORDERED_NODE_SNAPSHOT_TYPE. |
---|
247 | */ |
---|
248 | virtual DOMNode* snapshotItem(unsigned long index) const = 0; |
---|
249 | |
---|
250 | //@} |
---|
251 | }; |
---|
252 | |
---|
253 | XERCES_CPP_NAMESPACE_END |
---|
254 | |
---|
255 | #endif |
---|