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 | //
|
---|
43 | // W A R N I N G
|
---|
44 | // -------------
|
---|
45 | //
|
---|
46 | // This file is not part of the Qt API. It exists purely as an
|
---|
47 | // implementation detail. This header file may change from version to
|
---|
48 | // version without notice, or even be removed.
|
---|
49 | //
|
---|
50 | // We mean it.
|
---|
51 |
|
---|
52 | #ifndef QABSTRACTXMLFORWARDITERATOR_H
|
---|
53 | #define QABSTRACTXMLFORWARDITERATOR_H
|
---|
54 |
|
---|
55 | #include <QtCore/QList>
|
---|
56 | #include <QtCore/QVector>
|
---|
57 | #include <QtCore/QSharedData>
|
---|
58 |
|
---|
59 |
|
---|
60 | QT_BEGIN_HEADER
|
---|
61 |
|
---|
62 | QT_BEGIN_NAMESPACE
|
---|
63 |
|
---|
64 | QT_MODULE(XmlPatterns)
|
---|
65 |
|
---|
66 | template<typename T> class QVector;
|
---|
67 |
|
---|
68 | /* In this file we in some cases do not use QAbstractXmlForwardIterator's Ptr typedef.
|
---|
69 | * This is a compiler workaround for MS VS 6.0. */
|
---|
70 |
|
---|
71 | template<typename T>
|
---|
72 | inline bool qIsForwardIteratorEnd(const T &unit)
|
---|
73 | {
|
---|
74 | return !unit;
|
---|
75 | }
|
---|
76 |
|
---|
77 | template<typename T> class QAbstractXmlForwardIterator;
|
---|
78 |
|
---|
79 | class QAbstractXmlForwardIteratorPrivate;
|
---|
80 |
|
---|
81 | template<typename T>
|
---|
82 | class QAbstractXmlForwardIterator : public QSharedData
|
---|
83 | {
|
---|
84 | public:
|
---|
85 | typedef QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > Ptr;
|
---|
86 | typedef QList<QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > > List;
|
---|
87 | typedef QVector<QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > > Vector;
|
---|
88 |
|
---|
89 | inline QAbstractXmlForwardIterator() {}
|
---|
90 | virtual ~QAbstractXmlForwardIterator() {}
|
---|
91 |
|
---|
92 | virtual T next() = 0;
|
---|
93 | virtual T current() const = 0;
|
---|
94 |
|
---|
95 | virtual qint64 position() const = 0;
|
---|
96 |
|
---|
97 | virtual typename QAbstractXmlForwardIterator<T>::Ptr toReversed();
|
---|
98 | virtual QList<T> toList();
|
---|
99 | virtual typename QAbstractXmlForwardIterator<T>::Ptr copy() const;
|
---|
100 | virtual T last();
|
---|
101 | virtual bool isEmpty();
|
---|
102 | virtual qint64 count();
|
---|
103 | virtual qint64 sizeHint() const;
|
---|
104 |
|
---|
105 | private:
|
---|
106 | Q_DISABLE_COPY(QAbstractXmlForwardIterator<T>)
|
---|
107 |
|
---|
108 | QAbstractXmlForwardIteratorPrivate *d_ptr; /* Currently not used. */
|
---|
109 | };
|
---|
110 |
|
---|
111 | /* The namespace QPatternist and its members are internal, not part of the public API, and
|
---|
112 | * unsupported. Using them leads to undefined behavior. */
|
---|
113 | namespace QPatternist
|
---|
114 | {
|
---|
115 | class DeduplicateIterator;
|
---|
116 |
|
---|
117 | template<typename InputType,
|
---|
118 | typename OutputType,
|
---|
119 | typename Derived,
|
---|
120 | typename ListType = QList<InputType> >
|
---|
121 | class ListIteratorPlatform : public QAbstractXmlForwardIterator<OutputType>
|
---|
122 | {
|
---|
123 | /* This declaration is a workaround for a set of GCC versions on OS X,
|
---|
124 | * amongst others powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1. In
|
---|
125 | * DeduplicateIterator, it fails to see the protected inheritance. */
|
---|
126 | friend class DeduplicateIterator;
|
---|
127 |
|
---|
128 | public:
|
---|
129 | virtual OutputType next()
|
---|
130 | {
|
---|
131 | if(m_position == -1)
|
---|
132 | return OutputType();
|
---|
133 |
|
---|
134 | if(m_position == m_list.count())
|
---|
135 | {
|
---|
136 | m_position = -1;
|
---|
137 | m_current = OutputType();
|
---|
138 | return OutputType();
|
---|
139 | }
|
---|
140 |
|
---|
141 | m_current = static_cast<const Derived *>(this)->inputToOutputItem(m_list.at(m_position));
|
---|
142 | ++m_position;
|
---|
143 | return m_current;
|
---|
144 | }
|
---|
145 |
|
---|
146 | virtual OutputType current() const
|
---|
147 | {
|
---|
148 | return m_current;
|
---|
149 | }
|
---|
150 |
|
---|
151 | virtual qint64 position() const
|
---|
152 | {
|
---|
153 | return m_position;
|
---|
154 | }
|
---|
155 |
|
---|
156 | virtual qint64 count()
|
---|
157 | {
|
---|
158 | return m_list.count();
|
---|
159 | }
|
---|
160 |
|
---|
161 | virtual typename QAbstractXmlForwardIterator<OutputType>::Ptr copy() const
|
---|
162 | {
|
---|
163 | return QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<OutputType> >(new ListIteratorPlatform<InputType, OutputType, Derived, ListType>(m_list));
|
---|
164 | }
|
---|
165 |
|
---|
166 | protected:
|
---|
167 | inline ListIteratorPlatform(const ListType &list) : m_list(list)
|
---|
168 | , m_position(0)
|
---|
169 | {
|
---|
170 | }
|
---|
171 |
|
---|
172 | const ListType m_list;
|
---|
173 | qint64 m_position;
|
---|
174 | OutputType m_current;
|
---|
175 | };
|
---|
176 |
|
---|
177 | template<typename T,
|
---|
178 | typename ListType = QList<T> >
|
---|
179 | class ListIterator : public ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>
|
---|
180 | {
|
---|
181 | /*
|
---|
182 | * This declaration is needed for MSVC 2005, 14.00.50727.42 for 80x86.
|
---|
183 | */
|
---|
184 | friend class IteratorVector;
|
---|
185 |
|
---|
186 | using ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>::m_list;
|
---|
187 |
|
---|
188 | static inline QVector<T> toVector(const QVector<T> &vector)
|
---|
189 | {
|
---|
190 | return vector;
|
---|
191 | }
|
---|
192 |
|
---|
193 | static inline QVector<T> toVector(const QList<T> &list)
|
---|
194 | {
|
---|
195 | return list.toVector();
|
---|
196 | }
|
---|
197 |
|
---|
198 | static inline QList<T> toList(const QVector<T> &vector)
|
---|
199 | {
|
---|
200 | return vector.toList();
|
---|
201 | }
|
---|
202 |
|
---|
203 | static inline QList<T> toList(const QList<T> &list)
|
---|
204 | {
|
---|
205 | return list;
|
---|
206 | }
|
---|
207 |
|
---|
208 | public:
|
---|
209 | inline ListIterator(const ListType &list) : ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>(list)
|
---|
210 | {
|
---|
211 | }
|
---|
212 |
|
---|
213 | virtual QList<T> toList()
|
---|
214 | {
|
---|
215 | return toList(m_list);
|
---|
216 | }
|
---|
217 |
|
---|
218 | virtual QVector<T> toVector()
|
---|
219 | {
|
---|
220 | return toVector(m_list);
|
---|
221 | }
|
---|
222 |
|
---|
223 | private:
|
---|
224 | inline const T &inputToOutputItem(const T &inputType) const
|
---|
225 | {
|
---|
226 | return inputType;
|
---|
227 | }
|
---|
228 | friend class ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>;
|
---|
229 |
|
---|
230 | // needed for MSVC 2005
|
---|
231 | friend class DeduplicateIterator;
|
---|
232 | };
|
---|
233 |
|
---|
234 | template<typename T>
|
---|
235 | inline
|
---|
236 | typename QAbstractXmlForwardIterator<T>::Ptr
|
---|
237 | makeListIterator(const QList<T> &list)
|
---|
238 | {
|
---|
239 | return typename ListIterator<T>::Ptr(new ListIterator<T>(list));
|
---|
240 | }
|
---|
241 |
|
---|
242 | template<typename T>
|
---|
243 | inline
|
---|
244 | typename QAbstractXmlForwardIterator<T>::Ptr
|
---|
245 | makeVectorIterator(const QVector<T> &vector)
|
---|
246 | {
|
---|
247 | return typename ListIterator<T, QVector<T> >::Ptr(new ListIterator<T, QVector<T> >(vector));
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | template<typename T>
|
---|
252 | QList<T> QAbstractXmlForwardIterator<T>::toList()
|
---|
253 | {
|
---|
254 | QList<T> result;
|
---|
255 | T item(next());
|
---|
256 |
|
---|
257 | while(!qIsForwardIteratorEnd(item))
|
---|
258 | {
|
---|
259 | result.append(item);
|
---|
260 | item = next();
|
---|
261 | }
|
---|
262 |
|
---|
263 | return result;
|
---|
264 | }
|
---|
265 |
|
---|
266 | template<typename T>
|
---|
267 | qint64 QAbstractXmlForwardIterator<T>::count()
|
---|
268 | {
|
---|
269 | qint64 retval = 0;
|
---|
270 |
|
---|
271 | while(!qIsForwardIteratorEnd(next()))
|
---|
272 | ++retval;
|
---|
273 |
|
---|
274 | return retval;
|
---|
275 | }
|
---|
276 |
|
---|
277 | template<typename T>
|
---|
278 | typename QAbstractXmlForwardIterator<T>::Ptr QAbstractXmlForwardIterator<T>::toReversed()
|
---|
279 | {
|
---|
280 | T item(next());
|
---|
281 | QList<T> result;
|
---|
282 |
|
---|
283 | while(!qIsForwardIteratorEnd(item))
|
---|
284 | {
|
---|
285 | result.prepend(item);
|
---|
286 | item = next();
|
---|
287 | }
|
---|
288 |
|
---|
289 | return QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> >(new QPatternist::ListIterator<T>(result));
|
---|
290 | }
|
---|
291 |
|
---|
292 | template<typename T>
|
---|
293 | T QAbstractXmlForwardIterator<T>::last()
|
---|
294 | {
|
---|
295 | T item(next());
|
---|
296 |
|
---|
297 | while(!qIsForwardIteratorEnd(item))
|
---|
298 | item = next();
|
---|
299 |
|
---|
300 | return item;
|
---|
301 | }
|
---|
302 |
|
---|
303 | template<typename T>
|
---|
304 | typename QAbstractXmlForwardIterator<T>::Ptr QAbstractXmlForwardIterator<T>::copy() const
|
---|
305 | {
|
---|
306 | Q_ASSERT_X(false, Q_FUNC_INFO,
|
---|
307 | "This function is internal, unsupported, and should never be called.");
|
---|
308 | return typename QAbstractXmlForwardIterator<T>::Ptr();
|
---|
309 | }
|
---|
310 |
|
---|
311 | template<typename T>
|
---|
312 | bool QAbstractXmlForwardIterator<T>::isEmpty()
|
---|
313 | {
|
---|
314 | return qIsForwardIteratorEnd(next());
|
---|
315 | }
|
---|
316 |
|
---|
317 | template<typename T>
|
---|
318 | qint64 QAbstractXmlForwardIterator<T>::sizeHint() const
|
---|
319 | {
|
---|
320 | Q_ASSERT_X(false, Q_FUNC_INFO, "This function is currently not expected to be used.");
|
---|
321 | return -1;
|
---|
322 | }
|
---|
323 |
|
---|
324 | QT_END_NAMESPACE
|
---|
325 |
|
---|
326 | QT_END_HEADER
|
---|
327 |
|
---|
328 | #endif
|
---|