0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
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 |
**
|
|
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.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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 |
#include <QtCore/QString>
|
|
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 |
/**
|
|
78 |
* @short Helper class for StringSplitter
|
|
79 |
*
|
|
80 |
* Needed by the QAbstractXmlForwardIterator sub-class.
|
|
81 |
*
|
|
82 |
* @relates StringSplitter
|
|
83 |
*/
|
|
84 |
template<>
|
|
85 |
inline bool qIsForwardIteratorEnd(const QString &unit)
|
|
86 |
{
|
|
87 |
return unit.isNull();
|
|
88 |
}
|
|
89 |
|
|
90 |
template<typename T> class QAbstractXmlForwardIterator;
|
|
91 |
|
|
92 |
class QAbstractXmlForwardIteratorPrivate;
|
|
93 |
|
|
94 |
template<typename T>
|
|
95 |
class QAbstractXmlForwardIterator : public QSharedData
|
|
96 |
{
|
|
97 |
public:
|
|
98 |
typedef QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > Ptr;
|
|
99 |
typedef QList<QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > > List;
|
|
100 |
typedef QVector<QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > > Vector;
|
|
101 |
|
|
102 |
inline QAbstractXmlForwardIterator() : d_ptr(0) {}
|
|
103 |
virtual ~QAbstractXmlForwardIterator() {}
|
|
104 |
|
|
105 |
virtual T next() = 0;
|
|
106 |
virtual T current() const = 0;
|
|
107 |
|
|
108 |
virtual qint64 position() const = 0;
|
|
109 |
|
|
110 |
virtual typename QAbstractXmlForwardIterator<T>::Ptr toReversed();
|
|
111 |
virtual QList<T> toList();
|
|
112 |
virtual typename QAbstractXmlForwardIterator<T>::Ptr copy() const;
|
|
113 |
virtual T last();
|
|
114 |
virtual bool isEmpty();
|
|
115 |
virtual qint64 count();
|
|
116 |
virtual qint64 sizeHint() const;
|
|
117 |
|
|
118 |
private:
|
|
119 |
Q_DISABLE_COPY(QAbstractXmlForwardIterator<T>)
|
|
120 |
|
|
121 |
QAbstractXmlForwardIteratorPrivate *d_ptr; /* Currently not used. */
|
|
122 |
};
|
|
123 |
|
|
124 |
/* The namespace QPatternist and its members are internal, not part of the public API, and
|
|
125 |
* unsupported. Using them leads to undefined behavior. */
|
|
126 |
namespace QPatternist
|
|
127 |
{
|
|
128 |
class DeduplicateIterator;
|
|
129 |
|
|
130 |
template<typename InputType,
|
|
131 |
typename OutputType,
|
|
132 |
typename Derived,
|
|
133 |
typename ListType = QList<InputType> >
|
|
134 |
class ListIteratorPlatform : public QAbstractXmlForwardIterator<OutputType>
|
|
135 |
{
|
|
136 |
/* This declaration is a workaround for a set of GCC versions on OS X,
|
|
137 |
* amongst others powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1. In
|
|
138 |
* DeduplicateIterator, it fails to see the protected inheritance. */
|
|
139 |
friend class DeduplicateIterator;
|
|
140 |
|
|
141 |
public:
|
|
142 |
virtual OutputType next()
|
|
143 |
{
|
|
144 |
if(m_position == -1)
|
|
145 |
return OutputType();
|
|
146 |
|
|
147 |
if(m_position == m_list.count())
|
|
148 |
{
|
|
149 |
m_position = -1;
|
|
150 |
m_current = OutputType();
|
|
151 |
return OutputType();
|
|
152 |
}
|
|
153 |
|
|
154 |
m_current = static_cast<const Derived *>(this)->inputToOutputItem(m_list.at(m_position));
|
|
155 |
++m_position;
|
|
156 |
return m_current;
|
|
157 |
}
|
|
158 |
|
|
159 |
virtual OutputType current() const
|
|
160 |
{
|
|
161 |
return m_current;
|
|
162 |
}
|
|
163 |
|
|
164 |
virtual qint64 position() const
|
|
165 |
{
|
|
166 |
return m_position;
|
|
167 |
}
|
|
168 |
|
|
169 |
virtual qint64 count()
|
|
170 |
{
|
|
171 |
return m_list.count();
|
|
172 |
}
|
|
173 |
|
|
174 |
virtual typename QAbstractXmlForwardIterator<OutputType>::Ptr copy() const
|
|
175 |
{
|
|
176 |
return QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<OutputType> >(new ListIteratorPlatform<InputType, OutputType, Derived, ListType>(m_list));
|
|
177 |
}
|
|
178 |
|
|
179 |
protected:
|
|
180 |
inline ListIteratorPlatform(const ListType &list) : m_list(list)
|
|
181 |
, m_position(0)
|
|
182 |
{
|
|
183 |
}
|
|
184 |
|
|
185 |
const ListType m_list;
|
|
186 |
qint64 m_position;
|
|
187 |
OutputType m_current;
|
|
188 |
};
|
|
189 |
|
|
190 |
template<typename T,
|
|
191 |
typename ListType = QList<T> >
|
|
192 |
class ListIterator : public ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>
|
|
193 |
{
|
|
194 |
/*
|
|
195 |
* This declaration is needed for MSVC 2005, 14.00.50727.42 for 80x86.
|
|
196 |
*/
|
|
197 |
friend class IteratorVector;
|
|
198 |
|
|
199 |
using ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>::m_list;
|
|
200 |
|
|
201 |
static inline QVector<T> toVector(const QVector<T> &vector)
|
|
202 |
{
|
|
203 |
return vector;
|
|
204 |
}
|
|
205 |
|
|
206 |
static inline QVector<T> toVector(const QList<T> &list)
|
|
207 |
{
|
|
208 |
return list.toVector();
|
|
209 |
}
|
|
210 |
|
|
211 |
static inline QList<T> toList(const QVector<T> &vector)
|
|
212 |
{
|
|
213 |
return vector.toList();
|
|
214 |
}
|
|
215 |
|
|
216 |
static inline QList<T> toList(const QList<T> &list)
|
|
217 |
{
|
|
218 |
return list;
|
|
219 |
}
|
|
220 |
|
|
221 |
public:
|
|
222 |
inline ListIterator(const ListType &list) : ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>(list)
|
|
223 |
{
|
|
224 |
}
|
|
225 |
|
|
226 |
virtual QList<T> toList()
|
|
227 |
{
|
|
228 |
return toList(m_list);
|
|
229 |
}
|
|
230 |
|
|
231 |
virtual QVector<T> toVector()
|
|
232 |
{
|
|
233 |
return toVector(m_list);
|
|
234 |
}
|
|
235 |
|
|
236 |
private:
|
|
237 |
inline const T &inputToOutputItem(const T &inputType) const
|
|
238 |
{
|
|
239 |
return inputType;
|
|
240 |
}
|
|
241 |
friend class ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>;
|
|
242 |
|
|
243 |
// needed for MSVC 2005
|
|
244 |
friend class DeduplicateIterator;
|
|
245 |
};
|
|
246 |
|
|
247 |
template<typename T>
|
|
248 |
inline
|
|
249 |
typename QAbstractXmlForwardIterator<T>::Ptr
|
|
250 |
makeListIterator(const QList<T> &list)
|
|
251 |
{
|
|
252 |
return typename ListIterator<T>::Ptr(new ListIterator<T>(list));
|
|
253 |
}
|
|
254 |
|
|
255 |
template<typename T>
|
|
256 |
inline
|
|
257 |
typename QAbstractXmlForwardIterator<T>::Ptr
|
|
258 |
makeVectorIterator(const QVector<T> &vector)
|
|
259 |
{
|
|
260 |
return typename ListIterator<T, QVector<T> >::Ptr(new ListIterator<T, QVector<T> >(vector));
|
|
261 |
}
|
|
262 |
}
|
|
263 |
|
|
264 |
template<typename T>
|
|
265 |
QList<T> QAbstractXmlForwardIterator<T>::toList()
|
|
266 |
{
|
|
267 |
QList<T> result;
|
|
268 |
T item(next());
|
|
269 |
|
|
270 |
while(!qIsForwardIteratorEnd(item))
|
|
271 |
{
|
|
272 |
result.append(item);
|
|
273 |
item = next();
|
|
274 |
}
|
|
275 |
|
|
276 |
return result;
|
|
277 |
}
|
|
278 |
|
|
279 |
template<typename T>
|
|
280 |
qint64 QAbstractXmlForwardIterator<T>::count()
|
|
281 |
{
|
|
282 |
qint64 retval = 0;
|
|
283 |
|
|
284 |
while(!qIsForwardIteratorEnd(next()))
|
|
285 |
++retval;
|
|
286 |
|
|
287 |
return retval;
|
|
288 |
}
|
|
289 |
|
|
290 |
template<typename T>
|
|
291 |
typename QAbstractXmlForwardIterator<T>::Ptr QAbstractXmlForwardIterator<T>::toReversed()
|
|
292 |
{
|
|
293 |
T item(next());
|
|
294 |
QList<T> result;
|
|
295 |
|
|
296 |
while(!qIsForwardIteratorEnd(item))
|
|
297 |
{
|
|
298 |
result.prepend(item);
|
|
299 |
item = next();
|
|
300 |
}
|
|
301 |
|
|
302 |
return QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> >(new QPatternist::ListIterator<T>(result));
|
|
303 |
}
|
|
304 |
|
|
305 |
template<typename T>
|
|
306 |
T QAbstractXmlForwardIterator<T>::last()
|
|
307 |
{
|
|
308 |
T item(next());
|
|
309 |
|
|
310 |
while(!qIsForwardIteratorEnd(item))
|
|
311 |
item = next();
|
|
312 |
|
|
313 |
return item;
|
|
314 |
}
|
|
315 |
|
|
316 |
template<typename T>
|
|
317 |
typename QAbstractXmlForwardIterator<T>::Ptr QAbstractXmlForwardIterator<T>::copy() const
|
|
318 |
{
|
|
319 |
Q_ASSERT_X(false, Q_FUNC_INFO,
|
|
320 |
"This function is internal, unsupported, and should never be called.");
|
|
321 |
return typename QAbstractXmlForwardIterator<T>::Ptr();
|
|
322 |
}
|
|
323 |
|
|
324 |
template<typename T>
|
|
325 |
bool QAbstractXmlForwardIterator<T>::isEmpty()
|
|
326 |
{
|
|
327 |
return qIsForwardIteratorEnd(next());
|
|
328 |
}
|
|
329 |
|
|
330 |
template<typename T>
|
|
331 |
qint64 QAbstractXmlForwardIterator<T>::sizeHint() const
|
|
332 |
{
|
|
333 |
Q_ASSERT_X(false, Q_FUNC_INFO, "This function is currently not expected to be used.");
|
|
334 |
return -1;
|
|
335 |
}
|
|
336 |
|
|
337 |
QT_END_NAMESPACE
|
|
338 |
|
|
339 |
QT_END_HEADER
|
|
340 |
|
|
341 |
#endif
|