1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
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.
52 #ifndef QABSTRACTXMLFORWARDITERATOR_H
53 #define QABSTRACTXMLFORWARDITERATOR_H
55 #include <QtCore/QList>
56 #include <QtCore/QVector>
57 #include <QtCore/QSharedData>
58 #include <QtCore/QString>
65 template<typename T> class QVector;
67 /* In this file we in some cases do not use QAbstractXmlForwardIterator's Ptr typedef.
68 * This is a compiler workaround for MS VS 6.0. */
71 inline bool qIsForwardIteratorEnd(const T &unit)
77 * @short Helper class for StringSplitter
79 * Needed by the QAbstractXmlForwardIterator sub-class.
81 * @relates StringSplitter
84 inline bool qIsForwardIteratorEnd(const QString &unit)
89 template<typename T> class QAbstractXmlForwardIterator;
91 class QAbstractXmlForwardIteratorPrivate;
94 class QAbstractXmlForwardIterator : public QSharedData
97 typedef QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > Ptr;
98 typedef QList<QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > > List;
99 typedef QVector<QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> > > Vector;
101 inline QAbstractXmlForwardIterator() : d_ptr(0) {}
102 virtual ~QAbstractXmlForwardIterator() {}
104 virtual T next() = 0;
105 virtual T current() const = 0;
107 virtual qint64 position() const = 0;
109 virtual typename QAbstractXmlForwardIterator<T>::Ptr toReversed();
110 virtual QList<T> toList();
111 virtual typename QAbstractXmlForwardIterator<T>::Ptr copy() const;
113 virtual bool isEmpty();
114 virtual qint64 count();
115 virtual qint64 sizeHint() const;
118 Q_DISABLE_COPY(QAbstractXmlForwardIterator<T>)
120 QAbstractXmlForwardIteratorPrivate *d_ptr; /* Currently not used. */
123 /* The namespace QPatternist and its members are internal, not part of the public API, and
124 * unsupported. Using them leads to undefined behavior. */
125 namespace QPatternist
127 class DeduplicateIterator;
129 template<typename InputType,
132 typename ListType = QList<InputType> >
133 class ListIteratorPlatform : public QAbstractXmlForwardIterator<OutputType>
135 /* This declaration is a workaround for a set of GCC versions on OS X,
136 * amongst others powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1. In
137 * DeduplicateIterator, it fails to see the protected inheritance. */
138 friend class DeduplicateIterator;
141 virtual OutputType next()
146 if(m_position == m_list.count())
149 m_current = OutputType();
153 m_current = static_cast<const Derived *>(this)->inputToOutputItem(m_list.at(m_position));
158 virtual OutputType current() const
163 virtual qint64 position() const
168 virtual qint64 count()
170 return m_list.count();
173 virtual typename QAbstractXmlForwardIterator<OutputType>::Ptr copy() const
175 return QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<OutputType> >(new ListIteratorPlatform<InputType, OutputType, Derived, ListType>(m_list));
179 inline ListIteratorPlatform(const ListType &list) : m_list(list)
184 const ListType m_list;
186 OutputType m_current;
190 typename ListType = QList<T> >
191 class ListIterator : public ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>
194 * This declaration is needed for MSVC 2005, 14.00.50727.42 for 80x86.
196 friend class IteratorVector;
198 using ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>::m_list;
200 static inline QVector<T> toVector(const QVector<T> &vector)
205 static inline QVector<T> toVector(const QList<T> &list)
207 return list.toVector();
210 static inline QList<T> toList(const QVector<T> &vector)
212 return vector.toList();
215 static inline QList<T> toList(const QList<T> &list)
221 inline ListIterator(const ListType &list) : ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>(list)
225 virtual QList<T> toList()
227 return toList(m_list);
230 virtual QVector<T> toVector()
232 return toVector(m_list);
236 inline const T &inputToOutputItem(const T &inputType) const
240 friend class ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>;
242 // needed for MSVC 2005
243 friend class DeduplicateIterator;
248 typename QAbstractXmlForwardIterator<T>::Ptr
249 makeListIterator(const QList<T> &list)
251 return typename ListIterator<T>::Ptr(new ListIterator<T>(list));
256 typename QAbstractXmlForwardIterator<T>::Ptr
257 makeVectorIterator(const QVector<T> &vector)
259 return typename ListIterator<T, QVector<T> >::Ptr(new ListIterator<T, QVector<T> >(vector));
264 QList<T> QAbstractXmlForwardIterator<T>::toList()
269 while(!qIsForwardIteratorEnd(item))
279 qint64 QAbstractXmlForwardIterator<T>::count()
283 while(!qIsForwardIteratorEnd(next()))
290 typename QAbstractXmlForwardIterator<T>::Ptr QAbstractXmlForwardIterator<T>::toReversed()
295 while(!qIsForwardIteratorEnd(item))
297 result.prepend(item);
301 return QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<T> >(new QPatternist::ListIterator<T>(result));
305 T QAbstractXmlForwardIterator<T>::last()
309 while(!qIsForwardIteratorEnd(item))
316 typename QAbstractXmlForwardIterator<T>::Ptr QAbstractXmlForwardIterator<T>::copy() const
318 Q_ASSERT_X(false, Q_FUNC_INFO,
319 "This function is internal, unsupported, and should never be called.");
320 return typename QAbstractXmlForwardIterator<T>::Ptr();
324 bool QAbstractXmlForwardIterator<T>::isEmpty()
326 return qIsForwardIteratorEnd(next());
330 qint64 QAbstractXmlForwardIterator<T>::sizeHint() const
332 Q_ASSERT_X(false, Q_FUNC_INFO, "This function is currently not expected to be used.");