source: trunk/src/xmlpatterns/api/qabstractxmlnodemodel.h@ 1036

Last change on this file since 1036 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 14.5 KB
RevLine 
[2]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[561]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
[2]6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
[561]24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
[2]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**
[561]36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
[2]38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QABSTRACTXMLNODEMODEL_H
43#define QABSTRACTXMLNODEMODEL_H
44
45#include <QtXmlPatterns/QXmlName>
46#include <QtCore/QSharedData>
[561]47#include <QtCore/QScopedPointer>
[2]48
49QT_BEGIN_HEADER
50QT_BEGIN_NAMESPACE
51
52QT_MODULE(XmlPatterns)
53
54/* This file contains the classes QXmlNodeModelIndex, QAbstractXmlNodeModel,
55 * QXmlItem and QPatternist::NodeIndexStorage. */
56
57class QAbstractXmlNodeModel;
58class QAbstractXmlNodeModelPrivate;
59class QAbstractXmlReceiver;
[561]60class QSourceLocation;
[2]61class QUrl;
62class QXmlName;
63class QXmlNodeModelIndex;
64template<typename T> class QAbstractXmlForwardIterator;
65template<typename T> class QVector;
66
67/* The members in the namespace QPatternist are internal, not part of the public API, and
68 * unsupported. Using them leads to undefined behavior. */
69namespace QPatternist
70{
71 class DynamicContext;
72 class Item;
73 class ItemType;
[561]74 class XsdValidatedXmlNodeModel;
[2]75 template<typename TResult, typename TSource, typename TMapper, typename Context> class ItemMappingIterator;
76 template<typename TResult, typename TSource, typename TMapper> class SequenceMappingIterator;
77 typedef QExplicitlySharedDataPointer<ItemType> ItemTypePtr;
78 typedef QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<Item> > ItemIteratorPtr;
79 typedef QVector<QXmlName> QXmlNameVector;
80
81 class NodeIndexStorage
82 {
83 public:
84 typedef qint64 Data;
85
86 /*!
87 \note Changing merely the order of these two members, ptr and data,
88 is a binary incompatible change on Mac Power PC.
89 */
90 union
91 {
92 void *ptr; // Do not use ptr directy, use pointer() instead.
93 Data data;
94 };
95 void *pointer() const
96 {
97 /* Constructing to qptrdiff means we avoid the warning "cast to pointer
98 * from integer of different size."
99 */
100 return (void *)qptrdiff(data);
101 }
102
103 Data additionalData;
104 const QAbstractXmlNodeModel *model;
105
106 /* Implementation is in qabstractxmlnodemodel.cpp. */
107 inline bool operator!=(const NodeIndexStorage &other) const;
108 };
109}
110
111class Q_XMLPATTERNS_EXPORT QXmlNodeModelIndex
112{
113 enum Constants
114 {
115 ForwardAxis = 8192,
116 ReverseAxis = 16384
117 };
118
119public:
120 inline QXmlNodeModelIndex()
121 {
122 reset();
123 }
124
125 inline QXmlNodeModelIndex(const QXmlNodeModelIndex &other) : m_storage(other.m_storage)
126 {
127 }
128
129 bool operator==(const QXmlNodeModelIndex &other) const;
130 bool operator!=(const QXmlNodeModelIndex &other) const;
131
132 typedef QAbstractXmlForwardIterator<QXmlNodeModelIndex> Iterator;
133 typedef QList<QXmlNodeModelIndex> List;
134
135 enum NodeKind
136 {
137 Attribute = 1,
138 Comment = 2,
139 Document = 4,
140 Element = 8,
141 Namespace = 16,
142 ProcessingInstruction = 32,
143 Text = 64
144 };
145
146 enum DocumentOrder
147 {
148 Precedes = -1,
149 Is = 0,
150 Follows = 1
151 };
152
153 enum Axis
154 {
155 AxisChild = 1 | ForwardAxis,
156 AxisDescendant = 2 | ForwardAxis,
157 AxisAttribute = 4 | ForwardAxis,
158 AxisSelf = 8 | ForwardAxis,
159 AxisDescendantOrSelf = 16 | ForwardAxis,
160 AxisFollowingSibling = 32 | ForwardAxis,
161 AxisNamespace = 64 | ForwardAxis,
162 AxisFollowing = 128 | ReverseAxis,
163 AxisParent = 256 | ReverseAxis,
164 AxisAncestor = 512 | ReverseAxis,
165 AxisPrecedingSibling = 1024 | ReverseAxis,
166 AxisPreceding = 2048 | ReverseAxis,
167 AxisAncestorOrSelf = 4096 | ReverseAxis,
168 /* Note that we cannot clash with the values of ForwardAxis and
169 * ReverseAxis. */
170 AxisChildOrTop = 32768 | ForwardAxis,
171 AxisAttributeOrTop = 65536 | ForwardAxis
172 };
173
174 inline qint64 data() const
175 {
176 return m_storage.data;
177 }
178
179 inline void *internalPointer() const
180 {
181 return m_storage.pointer();
182 }
183
184 inline const QAbstractXmlNodeModel *model() const
185 {
186 return m_storage.model;
187 }
188
189 inline qint64 additionalData() const
190 {
191 return m_storage.additionalData;
192 }
193
194 inline bool isNull() const
195 {
196 return !m_storage.model;
197 }
198
199 /* The members below are internal, not part of the public API, and
200 * unsupported. Using them leads to undefined behavior. */
201
202 inline QXmlName name() const;
203 inline QXmlNodeModelIndex root() const;
204 inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > iterate(const Axis axis) const;
205 inline QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QPatternist::Item> > sequencedTypedValue() const;
206 inline QUrl documentUri() const;
207 inline QUrl baseUri() const;
208 inline NodeKind kind() const;
209 inline bool isDeepEqual(const QXmlNodeModelIndex &other) const;
210 inline DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const;
211 inline void sendNamespaces(QAbstractXmlReceiver *const receiver) const;
212 inline QVector<QXmlName> namespaceBindings() const;
213 inline QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const;
214 inline QString stringValue() const;
215 inline QPatternist::ItemTypePtr type() const;
216 inline bool is(const QXmlNodeModelIndex &other) const;
217
218 inline void reset()
219 {
220 m_storage.data = 0;
221 m_storage.additionalData = 0;
222 m_storage.model = 0;
223 }
224
225private:
226 static inline QXmlNodeModelIndex create(const qint64 d,
227 const QAbstractXmlNodeModel *const nm)
228 {
229 QXmlNodeModelIndex n;
230 n.m_storage.data = d;
231 n.m_storage.model = nm;
232 n.m_storage.additionalData = 0;
233 return n;
234 }
235
236 static inline QXmlNodeModelIndex create(const qint64 data,
237 const QAbstractXmlNodeModel *const nm,
238 const qint64 addData)
239 {
240 QXmlNodeModelIndex n;
241 n.m_storage.data = data;
242 n.m_storage.model = nm;
243 n.m_storage.additionalData = addData;
244 return n;
245 }
246
247 inline QXmlNodeModelIndex(const QPatternist::NodeIndexStorage &storage) : m_storage(storage)
248 {
249 }
250
251 friend class QAbstractXmlNodeModel;
252 friend class QPatternist::Item;
253 friend class QXmlItem;
254 inline operator int() const; // Disable
255
256 QPatternist::NodeIndexStorage m_storage;
257};
258
259Q_XMLPATTERNS_EXPORT uint qHash(const QXmlNodeModelIndex &index);
260
261inline bool qIsForwardIteratorEnd(const QXmlNodeModelIndex &item)
262{
263 return item.isNull();
264}