1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QABSTRACTXMLNODEMODEL_H
|
---|
43 | #define QABSTRACTXMLNODEMODEL_H
|
---|
44 |
|
---|
45 | #include <QtXmlPatterns/QXmlName>
|
---|
46 | #include <QtCore/QSharedData>
|
---|
47 |
|
---|
48 | QT_BEGIN_HEADER
|
---|
49 | QT_BEGIN_NAMESPACE
|
---|
50 |
|
---|
51 | QT_MODULE(XmlPatterns)
|
---|
52 |
|
---|
53 | /* This file contains the classes QXmlNodeModelIndex, QAbstractXmlNodeModel,
|
---|
54 | * QXmlItem and QPatternist::NodeIndexStorage. */
|
---|
55 |
|
---|
56 | class QAbstractXmlNodeModel;
|
---|
57 | class QAbstractXmlNodeModelPrivate;
|
---|
58 | class QAbstractXmlReceiver;
|
---|
59 | class QUrl;
|
---|
60 | class QXmlName;
|
---|
61 | class QXmlNodeModelIndex;
|
---|
62 | template<typename T> class QAbstractXmlForwardIterator;
|
---|
63 | template<typename T> class QVector;
|
---|
64 |
|
---|
65 | /* The members in the namespace QPatternist are internal, not part of the public API, and
|
---|
66 | * unsupported. Using them leads to undefined behavior. */
|
---|
67 | namespace QPatternist
|
---|
68 | {
|
---|
69 | class DynamicContext;
|
---|
70 | class Item;
|
---|
71 | class ItemType;
|
---|
72 | template<typename TResult, typename TSource, typename TMapper, typename Context> class ItemMappingIterator;
|
---|
73 | template<typename TResult, typename TSource, typename TMapper> class SequenceMappingIterator;
|
---|
74 | typedef QExplicitlySharedDataPointer<ItemType> ItemTypePtr;
|
---|
75 | typedef QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<Item> > ItemIteratorPtr;
|
---|
76 | typedef QVector<QXmlName> QXmlNameVector;
|
---|
77 |
|
---|
78 | class NodeIndexStorage
|
---|
79 | {
|
---|
80 | public:
|
---|
81 | typedef qint64 Data;
|
---|
82 |
|
---|
83 | /*!
|
---|
84 | \note Changing merely the order of these two members, ptr and data,
|
---|
85 | is a binary incompatible change on Mac Power PC.
|
---|
86 | */
|
---|
87 | union
|
---|
88 | {
|
---|
89 | void *ptr; // Do not use ptr directy, use pointer() instead.
|
---|
90 | Data data;
|
---|
91 | };
|
---|
92 | void *pointer() const
|
---|
93 | {
|
---|
94 | /* Constructing to qptrdiff means we avoid the warning "cast to pointer
|
---|
95 | * from integer of different size."
|
---|
96 | */
|
---|
97 | return (void *)qptrdiff(data);
|
---|
98 | }
|
---|
99 |
|
---|
100 | Data additionalData;
|
---|
101 | const QAbstractXmlNodeModel *model;
|
---|
102 |
|
---|
103 | /* Implementation is in qabstractxmlnodemodel.cpp. */
|
---|
104 | inline bool operator!=(const NodeIndexStorage &other) const;
|
---|
105 | };
|
---|
106 | }
|
---|
107 |
|
---|
108 | class Q_XMLPATTERNS_EXPORT QXmlNodeModelIndex
|
---|
109 | {
|
---|
110 | enum Constants
|
---|
111 | {
|
---|
112 | ForwardAxis = 8192,
|
---|
113 | ReverseAxis = 16384
|
---|
114 | };
|
---|
115 |
|
---|
116 | public:
|
---|
117 | inline QXmlNodeModelIndex()
|
---|
118 | {
|
---|
119 | reset();
|
---|
120 | }
|
---|
121 |
|
---|
122 | inline QXmlNodeModelIndex(const QXmlNodeModelIndex &other) : m_storage(other.m_storage)
|
---|
123 | {
|
---|
124 | }
|
---|
125 |
|
---|
126 | bool operator==(const QXmlNodeModelIndex &other) const;
|
---|
127 | bool operator!=(const QXmlNodeModelIndex &other) const;
|
---|
128 |
|
---|
129 | typedef QAbstractXmlForwardIterator<QXmlNodeModelIndex> Iterator;
|
---|
130 | typedef QList<QXmlNodeModelIndex> List;
|
---|
131 |
|
---|
132 | enum NodeKind
|
---|
133 | {
|
---|
134 | Attribute = 1,
|
---|
135 | Comment = 2,
|
---|
136 | Document = 4,
|
---|
137 | Element = 8,
|
---|
138 | Namespace = 16,
|
---|
139 | ProcessingInstruction = 32,
|
---|
140 | Text = 64
|
---|
141 | };
|
---|
142 |
|
---|
143 | enum DocumentOrder
|
---|
144 | {
|
---|
145 | Precedes = -1,
|
---|
146 | Is = 0,
|
---|
147 | Follows = 1
|
---|
148 | };
|
---|
149 |
|
---|
150 | enum Axis
|
---|
151 | {
|
---|
152 | AxisChild = 1 | ForwardAxis,
|
---|
153 | AxisDescendant = 2 | ForwardAxis,
|
---|
154 | AxisAttribute = 4 | ForwardAxis,
|
---|
155 | AxisSelf = 8 | ForwardAxis,
|
---|
156 | AxisDescendantOrSelf = 16 | ForwardAxis,
|
---|
157 | AxisFollowingSibling = 32 | ForwardAxis,
|
---|
158 | AxisNamespace = 64 | ForwardAxis,
|
---|
159 | AxisFollowing = 128 | ReverseAxis,
|
---|
160 | AxisParent = 256 | ReverseAxis,
|
---|
161 | AxisAncestor = 512 | ReverseAxis,
|
---|
162 | AxisPrecedingSibling = 1024 | ReverseAxis,
|
---|
163 | AxisPreceding = 2048 | ReverseAxis,
|
---|
164 | AxisAncestorOrSelf = 4096 | ReverseAxis,
|
---|
165 | /* Note that we cannot clash with the values of ForwardAxis and
|
---|
166 | * ReverseAxis. */
|
---|
167 | AxisChildOrTop = 32768 | ForwardAxis,
|
---|
168 | AxisAttributeOrTop = 65536 | ForwardAxis
|
---|
169 | };
|
---|
170 |
|
---|
171 | inline qint64 data() const
|
---|
172 | {
|
---|
173 | return m_storage.data;
|
---|
174 | }
|
---|
175 |
|
---|
176 | inline void *internalPointer() const
|
---|
177 | {
|
---|
178 | return m_storage.pointer();
|
---|
179 | }
|
---|
180 |
|
---|
181 | inline const QAbstractXmlNodeModel *model() const
|
---|
182 | {
|
---|
183 | return m_storage.model;
|
---|
184 | }
|
---|
185 |
|
---|
186 | inline qint64 additionalData() const
|
---|
187 | {
|
---|
188 | return m_storage.additionalData;
|
---|
189 | }
|
---|
190 |
|
---|
191 | inline bool isNull() const
|
---|
192 | {
|
---|
193 | return !m_storage.model;
|
---|
194 | }
|
---|
195 |
|
---|
196 | /* The members below are internal, not part of the public API, and
|
---|
197 | * unsupported. Using them leads to undefined behavior. */
|
---|
198 |
|
---|
199 | inline QXmlName name() const;
|
---|
200 | inline QXmlNodeModelIndex root() const;
|
---|
201 | inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > iterate(const Axis axis) const;
|
---|
202 | inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QPatternist::Item> > sequencedTypedValue() const;
|
---|
203 | inline QUrl documentUri() const;
|
---|
204 | inline QUrl baseUri() const;
|
---|
205 | inline NodeKind kind() const;
|
---|
206 | inline bool isDeepEqual(const QXmlNodeModelIndex &other) const;
|
---|
207 | inline DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const;
|
---|
208 | inline void sendNamespaces(QAbstractXmlReceiver *const receiver) const;
|
---|
209 | inline QVector<QXmlName> namespaceBindings() const;
|
---|
210 | inline QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const;
|
---|
211 | inline QString stringValue() const;
|
---|
212 | inline QPatternist::ItemTypePtr type() const;
|
---|
213 | inline bool is(const QXmlNodeModelIndex &other) const;
|
---|
214 |
|
---|
215 | inline void reset()
|
---|
216 | {
|
---|
217 | m_storage.data = 0;
|
---|
218 | m_storage.additionalData = 0;
|
---|
219 | m_storage.model = 0;
|
---|
220 | }
|
---|
221 |
|
---|
222 | private:
|
---|
223 | static inline QXmlNodeModelIndex create(const qint64 d,
|
---|
224 | const QAbstractXmlNodeModel *const nm)
|
---|
225 | {
|
---|
226 | QXmlNodeModelIndex n;
|
---|
227 | n.m_storage.data = d;
|
---|
228 | n.m_storage.model = nm;
|
---|
229 | n.m_storage.additionalData = 0;
|
---|
230 | return n;
|
---|
231 | }
|
---|
232 |
|
---|
233 | static inline QXmlNodeModelIndex create(const qint64 data,
|
---|
234 | const QAbstractXmlNodeModel *const nm,
|
---|
235 | const qint64 addData)
|
---|
236 | {
|
---|
237 | QXmlNodeModelIndex n;
|
---|
238 | n.m_storage.data = data;
|
---|
239 | n.m_storage.model = nm;
|
---|
240 | n.m_storage.additionalData = addData;
|
---|
241 | return n;
|
---|
242 | }
|
---|
243 |
|
---|
244 | inline QXmlNodeModelIndex(const QPatternist::NodeIndexStorage &storage) : m_storage(storage)
|
---|
245 | {
|
---|
246 | }
|
---|
247 |
|
---|
248 | friend class QAbstractXmlNodeModel;
|
---|
249 | friend class QPatternist::Item;
|
---|
250 | friend class QXmlItem;
|
---|
251 | inline operator int() const; // Disable
|
---|
252 |
|
---|
253 | QPatternist::NodeIndexStorage m_storage;
|
---|
254 | };
|
---|
255 |
|
---|
256 | Q_XMLPATTERNS_EXPORT uint qHash(const QXmlNodeModelIndex &index);
|
---|
257 |
|
---|
258 | inline bool qIsForwardIteratorEnd(const QXmlNodeModelIndex &item)
|
---|
259 | {
|
---|
260 | return item.isNull();
|
---|
261 | }
|
---|
262 |
|
---|
263 | class Q_XMLPATTERNS_EXPORT QAbstractXmlNodeModel : public QSharedData
|
---|
264 | {
|
---|
265 | public:
|
---|
266 | enum SimpleAxis
|
---|
267 | {
|
---|
268 | Parent,
|
---|
269 | FirstChild,
|
---|
270 | PreviousSibling,
|
---|
271 | NextSibling
|
---|
272 | };
|
---|
273 |
|
---|
274 | typedef QExplicitlySharedDataPointer<QAbstractXmlNodeModel> Ptr;
|
---|
275 | typedef QList<Ptr> List;
|
---|
276 |
|
---|
277 | QAbstractXmlNodeModel();
|
---|
278 | virtual ~QAbstractXmlNodeModel();
|
---|
279 |
|
---|
280 | virtual QUrl baseUri(const QXmlNodeModelIndex &ni) const = 0;
|
---|
281 | virtual QUrl documentUri(const QXmlNodeModelIndex &ni) const = 0;
|
---|
282 | virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const = 0;
|
---|
283 | virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &ni1,
|
---|
284 | const QXmlNodeModelIndex &ni2) const = 0;
|
---|
285 | virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const = 0;
|
---|
286 | virtual QXmlName name(const QXmlNodeModelIndex &ni) const = 0;
|
---|
287 | virtual QString stringValue(const QXmlNodeModelIndex &n) const = 0;
|
---|
288 | virtual QVariant typedValue(const QXmlNodeModelIndex &n) const = 0;
|
---|
289 |
|
---|
290 | /* The members below are internal, not part of the public API, and
|
---|
291 | * unsupported. Using them leads to undefined behavior. */
|
---|
292 | virtual QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const;
|
---|
293 | virtual QPatternist::ItemIteratorPtr sequencedTypedValue(const QXmlNodeModelIndex &ni) const;
|
---|
294 | virtual QPatternist::ItemTypePtr type(const QXmlNodeModelIndex &ni) const;
|
---|
295 | virtual QXmlName::NamespaceCode namespaceForPrefix(const QXmlNodeModelIndex &ni,
|
---|
296 | const QXmlName::PrefixCode prefix) const;
|
---|
297 | virtual bool isDeepEqual(const QXmlNodeModelIndex &ni1,
|
---|
298 | const QXmlNodeModelIndex &ni2) const;
|
---|
299 | virtual void sendNamespaces(const QXmlNodeModelIndex &n,
|
---|
300 | QAbstractXmlReceiver *const receiver) const;
|
---|
301 | virtual QVector<QXmlName> namespaceBindings(const QXmlNodeModelIndex &n) const = 0;
|
---|
302 |
|
---|
303 |
|
---|
304 | virtual QXmlNodeModelIndex elementById(const QXmlName &NCName) const = 0;
|
---|
305 | virtual QVector<QXmlNodeModelIndex> nodesByIdref(const QXmlName &NCName) const = 0;
|
---|
306 |
|
---|
307 | enum NodeCopySetting
|
---|
308 | {
|
---|
309 | InheritNamespaces = 0x1,
|
---|
310 | PreserveNamespaces = 0x2
|
---|
311 | };
|
---|
312 |
|
---|
313 | typedef QFlags<NodeCopySetting> NodeCopySettings;
|
---|
314 | virtual void copyNodeTo(const QXmlNodeModelIndex &node,
|
---|
315 | QAbstractXmlReceiver *const receiver,
|
---|
316 | const NodeCopySettings &) const;
|
---|
317 |
|
---|
318 | protected:
|
---|
319 |
|
---|
320 | virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const = 0;
|
---|
321 | virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const = 0;
|
---|
322 |
|
---|
323 | QAbstractXmlNodeModel(QAbstractXmlNodeModelPrivate *d);
|
---|
324 |
|
---|
325 | inline QXmlNodeModelIndex createIndex(qint64 data) const
|
---|
326 | {
|
---|
327 | return QXmlNodeModelIndex::create(data, this);
|
---|
328 | }
|
---|
329 |
|
---|
330 | inline QXmlNodeModelIndex createIndex(void * pointer,
|
---|
331 | qint64 additionalData = 0) const
|
---|
332 | {
|
---|
333 | return QXmlNodeModelIndex::create(qptrdiff(pointer), this, additionalData);
|
---|
334 | }
|
---|
335 |
|
---|
336 | inline QXmlNodeModelIndex createIndex(qint64 data,
|
---|
337 | qint64 additionalData) const
|
---|
338 | {
|
---|
339 | return QXmlNodeModelIndex::create(data, this, additionalData);
|
---|
340 | }
|
---|
341 |
|
---|
342 | QAbstractXmlNodeModelPrivate *d_ptr;
|
---|
343 | private:
|
---|
344 | friend class QPatternist::ItemMappingIterator<QXmlNodeModelIndex, QXmlNodeModelIndex, const QAbstractXmlNodeModel *, QExplicitlySharedDataPointer<QPatternist::DynamicContext> >;
|
---|
345 | friend class QPatternist::SequenceMappingIterator<QXmlNodeModelIndex, QXmlNodeModelIndex, const QAbstractXmlNodeModel *>;
|
---|
346 |
|
---|
347 | inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > mapToSequence(const QXmlNodeModelIndex &ni,
|
---|
348 | const QExplicitlySharedDataPointer<QPatternist::DynamicContext> &) const;
|
---|
349 |
|
---|
350 | static inline bool isIgnorableInDeepEqual(const QXmlNodeModelIndex &n);
|
---|
351 | Q_DISABLE_COPY(QAbstractXmlNodeModel)
|
---|
352 | };
|
---|
353 |
|
---|
354 | Q_DECLARE_TYPEINFO(QXmlNodeModelIndex, Q_MOVABLE_TYPE);
|
---|
355 |
|
---|
356 | template<typename T> class QAbstractXmlForwardIterator;
|
---|
357 | class QVariant;
|
---|
358 | class QXmlItemPrivate;
|
---|
359 |
|
---|
360 | namespace QPatternist
|
---|
361 | {
|
---|
362 | class AtomicValue;
|
---|
363 | class VariableLoader;
|
---|
364 | class IteratorBridge;
|
---|
365 | class ToQXmlItemMapper;
|
---|
366 | class ToItemMapper;
|
---|
367 | }
|
---|
368 |
|
---|
369 | class Q_XMLPATTERNS_EXPORT QXmlItem
|
---|
370 | {
|
---|
371 | public:
|
---|
372 | typedef QAbstractXmlForwardIterator<QXmlItem> Iterator;
|
---|
373 |
|
---|
374 | QXmlItem();
|
---|
375 | QXmlItem(const QXmlItem &other);
|
---|
376 | QXmlItem(const QXmlNodeModelIndex &node);
|
---|
377 | QXmlItem(const QVariant &atomicValue);
|
---|
378 | ~QXmlItem();
|
---|
379 | QXmlItem &operator=(const QXmlItem &other);
|
---|
380 |
|
---|
381 | bool isNull() const;
|
---|
382 | bool isNode() const;
|
---|
383 | bool isAtomicValue() const;
|
---|
384 |
|
---|
385 | QVariant toAtomicValue() const;
|
---|
386 | QXmlNodeModelIndex toNodeModelIndex() const;
|
---|
387 |
|
---|
388 | private:
|
---|
389 | friend class QPatternist::IteratorBridge;
|
---|
390 | friend class QPatternist::VariableLoader;
|
---|
391 | friend class QPatternist::ToQXmlItemMapper;
|
---|
392 | friend class QPatternist::ToItemMapper;
|
---|
393 | friend class QPatternist::Item;
|
---|
394 |
|
---|
395 | inline bool internalIsAtomicValue() const;
|
---|
396 |
|
---|
397 | inline QXmlItem(const QPatternist::Item &i);
|
---|
398 |
|
---|
399 | union
|
---|
400 | {
|
---|
401 | QPatternist::NodeIndexStorage m_node;
|
---|
402 |
|
---|
403 | /* These two sits at the position of NodeIndexStorage::data.
|
---|
404 | * NodeIndexStorage::{additionalData,model} are free. */
|
---|
405 | const QPatternist::AtomicValue *m_atomicValue;
|
---|
406 | QXmlItemPrivate * m_ptr; /* Not currently used. */
|
---|
407 | };
|
---|
408 | };
|
---|
409 |
|
---|
410 | inline bool qIsForwardIteratorEnd(const QXmlItem &item)
|
---|
411 | {
|
---|
412 | return item.isNull();
|
---|
413 | }
|
---|
414 |
|
---|
415 | Q_DECLARE_TYPEINFO(QXmlItem, Q_MOVABLE_TYPE);
|
---|
416 |
|
---|
417 | QT_END_NAMESPACE
|
---|
418 |
|
---|
419 | Q_DECLARE_METATYPE(QXmlItem) /* This macro must appear after QT_END_NAMESPACE. */
|
---|
420 |
|
---|
421 | QT_END_HEADER
|
---|
422 |
|
---|
423 | #endif
|
---|