1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QABSTRACTXMLNODEMODEL_H
43 #define QABSTRACTXMLNODEMODEL_H
45 #include <QtXmlPatterns/QXmlName>
46 #include <QtCore/QSharedData>
47 #include <QtCore/QScopedPointer>
53 /* This file contains the classes QXmlNodeModelIndex, QAbstractXmlNodeModel,
54 * QXmlItem and QPatternist::NodeIndexStorage. */
56 class QAbstractXmlNodeModel;
57 class QAbstractXmlNodeModelPrivate;
58 class QAbstractXmlReceiver;
59 class QSourceLocation;
62 class QXmlNodeModelIndex;
63 template<typename T> class QAbstractXmlForwardIterator;
64 template<typename T> class QVector;
66 /* The members in the namespace QPatternist are internal, not part of the public API, and
67 * unsupported. Using them leads to undefined behavior. */
73 class XsdValidatedXmlNodeModel;
74 template<typename TResult, typename TSource, typename TMapper, typename Context> class ItemMappingIterator;
75 template<typename TResult, typename TSource, typename TMapper> class SequenceMappingIterator;
76 typedef QExplicitlySharedDataPointer<ItemType> ItemTypePtr;
77 typedef QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<Item> > ItemIteratorPtr;
78 typedef QVector<QXmlName> QXmlNameVector;
80 class NodeIndexStorage
86 \note Changing merely the order of these two members, ptr and data,
87 is a binary incompatible change on Mac Power PC.
91 void *ptr; // Do not use ptr directy, use pointer() instead.
96 /* Constructing to qptrdiff means we avoid the warning "cast to pointer
97 * from integer of different size."
99 return (void *)qptrdiff(data);
103 const QAbstractXmlNodeModel *model;
105 /* Implementation is in qabstractxmlnodemodel.cpp. */
106 inline bool operator!=(const NodeIndexStorage &other) const;
117 class Q_XMLPATTERNS_EXPORT QXmlNodeModelIndex
126 inline QXmlNodeModelIndex()
131 inline QXmlNodeModelIndex(const QXmlNodeModelIndex &other) : m_storage(other.m_storage)
135 bool operator==(const QXmlNodeModelIndex &other) const;
136 bool operator!=(const QXmlNodeModelIndex &other) const;
138 typedef QAbstractXmlForwardIterator<QXmlNodeModelIndex> Iterator;
139 typedef QList<QXmlNodeModelIndex> List;
148 ProcessingInstruction = 32,
161 AxisChild = 1 | ForwardAxis,
162 AxisDescendant = 2 | ForwardAxis,
163 AxisAttribute = 4 | ForwardAxis,
164 AxisSelf = 8 | ForwardAxis,
165 AxisDescendantOrSelf = 16 | ForwardAxis,
166 AxisFollowingSibling = 32 | ForwardAxis,
167 AxisNamespace = 64 | ForwardAxis,
168 AxisFollowing = 128 | ReverseAxis,
169 AxisParent = 256 | ReverseAxis,
170 AxisAncestor = 512 | ReverseAxis,
171 AxisPrecedingSibling = 1024 | ReverseAxis,
172 AxisPreceding = 2048 | ReverseAxis,
173 AxisAncestorOrSelf = 4096 | ReverseAxis,
174 /* Note that we cannot clash with the values of ForwardAxis and
176 AxisChildOrTop = 32768 | ForwardAxis,
177 AxisAttributeOrTop = 65536 | ForwardAxis
180 inline qint64 data() const
182 return m_storage.data;
185 inline void *internalPointer() const
187 return m_storage.pointer();
190 inline const QAbstractXmlNodeModel *model() const
192 return m_storage.model;
195 inline qint64 additionalData() const
197 return m_storage.additionalData;
200 inline bool isNull() const
202 return !m_storage.model;
205 /* The members below are internal, not part of the public API, and
206 * unsupported. Using them leads to undefined behavior. */
208 inline QXmlName name() const;
209 inline QXmlNodeModelIndex root() const;
210 inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > iterate(const Axis axis) const;
211 inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QPatternist::Item> > sequencedTypedValue() const;
212 inline QUrl documentUri() const;
213 inline QUrl baseUri() const;
214 inline NodeKind kind() const;
215 inline bool isDeepEqual(const QXmlNodeModelIndex &other) const;
216 inline DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const;
217 inline void sendNamespaces(QAbstractXmlReceiver *const receiver) const;
218 inline QVector<QXmlName> namespaceBindings() const;
219 inline QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const;
220 inline QString stringValue() const;
221 inline QPatternist::ItemTypePtr type() const;
222 inline bool is(const QXmlNodeModelIndex &other) const;
230 static inline QXmlNodeModelIndex create(const qint64 d,
231 const QAbstractXmlNodeModel *const nm)
233 QXmlNodeModelIndex n;
234 n.m_storage.data = d;
235 n.m_storage.model = nm;
236 n.m_storage.additionalData = 0;
240 static inline QXmlNodeModelIndex create(const qint64 data,
241 const QAbstractXmlNodeModel *const nm,
242 const qint64 addData)
244 QXmlNodeModelIndex n;
245 n.m_storage.data = data;
246 n.m_storage.model = nm;
247 n.m_storage.additionalData = addData;
251 inline QXmlNodeModelIndex(const QPatternist::NodeIndexStorage &storage) : m_storage(storage)
255 friend class QAbstractXmlNodeModel;
256 friend class QPatternist::Item;
257 friend class QXmlItem;
258 inline operator int() const; // Disable
260 QPatternist::NodeIndexStorage m_storage;
263 Q_XMLPATTERNS_EXPORT uint qHash(const QXmlNodeModelIndex &index);
265 inline bool qIsForwardIteratorEnd(const QXmlNodeModelIndex &item)
267 return item.isNull();
270 class Q_XMLPATTERNS_EXPORT QAbstractXmlNodeModel : public QSharedData
281 typedef QExplicitlySharedDataPointer<QAbstractXmlNodeModel> Ptr;
282 typedef QList<Ptr> List;
284 QAbstractXmlNodeModel();
285 virtual ~QAbstractXmlNodeModel();
287 virtual QUrl baseUri(const QXmlNodeModelIndex &ni) const = 0;
288 virtual QUrl documentUri(const QXmlNodeModelIndex &ni) const = 0;
289 virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const = 0;
290 virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &ni1,
291 const QXmlNodeModelIndex &ni2) const = 0;
292 virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const = 0;
293 virtual QXmlName name(const QXmlNodeModelIndex &ni) const = 0;
294 virtual QString stringValue(const QXmlNodeModelIndex &n) const = 0;
295 virtual QVariant typedValue(const QXmlNodeModelIndex &n) const = 0;
297 /* The members below are internal, not part of the public API, and
298 * unsupported. Using them leads to undefined behavior. */
299 virtual QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const;
300 virtual QPatternist::ItemIteratorPtr sequencedTypedValue(const QXmlNodeModelIndex &ni) const;
301 virtual QPatternist::ItemTypePtr type(const QXmlNodeModelIndex &ni) const;
302 virtual QXmlName::NamespaceCode namespaceForPrefix(const QXmlNodeModelIndex &ni,
303 const QXmlName::PrefixCode prefix) const;
304 virtual bool isDeepEqual(const QXmlNodeModelIndex &ni1,
305 const QXmlNodeModelIndex &ni2) const;
306 virtual void sendNamespaces(const QXmlNodeModelIndex &n,
307 QAbstractXmlReceiver *const receiver) const;
308 virtual QVector<QXmlName> namespaceBindings(const QXmlNodeModelIndex &n) const = 0;
311 virtual QXmlNodeModelIndex elementById(const QXmlName &NCName) const = 0;
312 virtual QVector<QXmlNodeModelIndex> nodesByIdref(const QXmlName &NCName) const = 0;
316 InheritNamespaces = 0x1,
317 PreserveNamespaces = 0x2
320 typedef QFlags<NodeCopySetting> NodeCopySettings;
321 virtual void copyNodeTo(const QXmlNodeModelIndex &node,
322 QAbstractXmlReceiver *const receiver,
323 const NodeCopySettings &) const;
325 QSourceLocation sourceLocation(const QXmlNodeModelIndex &index) const;
329 virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const = 0;
330 virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const = 0;
332 QAbstractXmlNodeModel(QAbstractXmlNodeModelPrivate *d);
334 inline QXmlNodeModelIndex createIndex(qint64 data) const
336 return QXmlNodeModelIndex::create(data, this);
339 inline QXmlNodeModelIndex createIndex(void * pointer,
340 qint64 additionalData = 0) const
342 return QXmlNodeModelIndex::create(qptrdiff(pointer), this, additionalData);
345 inline QXmlNodeModelIndex createIndex(qint64 data,
346 qint64 additionalData) const
348 return QXmlNodeModelIndex::create(data, this, additionalData);
351 QScopedPointer<QAbstractXmlNodeModelPrivate> d_ptr;
353 friend class QPatternist::ItemMappingIterator<QXmlNodeModelIndex, QXmlNodeModelIndex, const QAbstractXmlNodeModel *, QExplicitlySharedDataPointer<QPatternist::DynamicContext> >;
354 friend class QPatternist::SequenceMappingIterator<QXmlNodeModelIndex, QXmlNodeModelIndex, const QAbstractXmlNodeModel *>;
355 friend class QPatternist::XsdValidatedXmlNodeModel;
357 inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > mapToSequence(const QXmlNodeModelIndex &ni,
358 const QExplicitlySharedDataPointer<QPatternist::DynamicContext> &) const;
360 static inline bool isIgnorableInDeepEqual(const QXmlNodeModelIndex &n);
361 Q_DISABLE_COPY(QAbstractXmlNodeModel)
364 Q_DECLARE_TYPEINFO(QXmlNodeModelIndex, Q_MOVABLE_TYPE);
366 template<typename T> class QAbstractXmlForwardIterator;
368 class QXmlItemPrivate;
370 namespace QPatternist
373 class VariableLoader;
374 class IteratorBridge;
375 class ToQXmlItemMapper;
379 class Q_XMLPATTERNS_EXPORT QXmlItem
382 typedef QAbstractXmlForwardIterator<QXmlItem> Iterator;
385 QXmlItem(const QXmlItem &other);
386 QXmlItem(const QXmlNodeModelIndex &node);
387 QXmlItem(const QVariant &atomicValue);
389 QXmlItem &operator=(const QXmlItem &other);
393 bool isAtomicValue() const;
395 QVariant toAtomicValue() const;
396 QXmlNodeModelIndex toNodeModelIndex() const;
399 friend class QPatternist::IteratorBridge;
400 friend class QPatternist::VariableLoader;
401 friend class QPatternist::ToQXmlItemMapper;
402 friend class QPatternist::ToItemMapper;
403 friend class QPatternist::Item;
405 inline bool internalIsAtomicValue() const;
407 inline QXmlItem(const QPatternist::Item &i);
411 QPatternist::NodeIndexStorage m_node;
413 /* These two sits at the position of NodeIndexStorage::data.
414 * NodeIndexStorage::{additionalData,model} are free. */
415 const QPatternist::AtomicValue *m_atomicValue;
416 QXmlItemPrivate * m_ptr; /* Not currently used. */
420 inline bool qIsForwardIteratorEnd(const QXmlItem &item)
422 return item.isNull();
425 Q_DECLARE_TYPEINFO(QXmlItem, Q_MOVABLE_TYPE);
429 Q_DECLARE_METATYPE(QXmlItem) /* This macro must appear after QT_END_NAMESPACE. */