/**************************************************************************** ** ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** ** This file is part of the QtXmlPatterns module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial Usage ** Licensees holding valid Qt Commercial licenses may use this file in ** accordance with the Qt Commercial License Agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Nokia. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Nokia gives you certain additional ** rights. These rights are described in the Nokia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ // // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists purely as an // implementation detail. This header file may change from version to // version without notice, or even be removed. // // We mean it. #ifndef QABSTRACTXMLFORWARDITERATOR_H #define QABSTRACTXMLFORWARDITERATOR_H #include #include #include #include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_MODULE(XmlPatterns) template class QVector; /* In this file we in some cases do not use QAbstractXmlForwardIterator's Ptr typedef. * This is a compiler workaround for MS VS 6.0. */ template inline bool qIsForwardIteratorEnd(const T &unit) { return !unit; } /** * @short Helper class for StringSplitter * * Needed by the QAbstractXmlForwardIterator sub-class. * * @relates StringSplitter */ template<> inline bool qIsForwardIteratorEnd(const QString &unit) { return unit.isNull(); } template class QAbstractXmlForwardIterator; class QAbstractXmlForwardIteratorPrivate; template class QAbstractXmlForwardIterator : public QSharedData { public: typedef QExplicitlySharedDataPointer > Ptr; typedef QList > > List; typedef QVector > > Vector; inline QAbstractXmlForwardIterator() : d_ptr(0) {} virtual ~QAbstractXmlForwardIterator() {} virtual T next() = 0; virtual T current() const = 0; virtual qint64 position() const = 0; virtual typename QAbstractXmlForwardIterator::Ptr toReversed(); virtual QList toList(); virtual typename QAbstractXmlForwardIterator::Ptr copy() const; virtual T last(); virtual bool isEmpty(); virtual qint64 count(); virtual qint64 sizeHint() const; private: Q_DISABLE_COPY(QAbstractXmlForwardIterator) QAbstractXmlForwardIteratorPrivate *d_ptr; /* Currently not used. */ }; /* The namespace QPatternist and its members are internal, not part of the public API, and * unsupported. Using them leads to undefined behavior. */ namespace QPatternist { class DeduplicateIterator; template > class ListIteratorPlatform : public QAbstractXmlForwardIterator { /* This declaration is a workaround for a set of GCC versions on OS X, * amongst others powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1. In * DeduplicateIterator, it fails to see the protected inheritance. */ friend class DeduplicateIterator; public: virtual OutputType next() { if(m_position == -1) return OutputType(); if(m_position == m_list.count()) { m_position = -1; m_current = OutputType(); return OutputType(); } m_current = static_cast(this)->inputToOutputItem(m_list.at(m_position)); ++m_position; return m_current; } virtual OutputType current() const { return m_current; } virtual qint64 position() const { return m_position; } virtual qint64 count() { return m_list.count(); } virtual typename QAbstractXmlForwardIterator::Ptr copy() const { return QExplicitlySharedDataPointer >(new ListIteratorPlatform(m_list)); } protected: inline ListIteratorPlatform(const ListType &list) : m_list(list) , m_position(0) { } const ListType m_list; qint64 m_position; OutputType m_current; }; template > class ListIterator : public ListIteratorPlatform, ListType> { /* * This declaration is needed for MSVC 2005, 14.00.50727.42 for 80x86. */ friend class IteratorVector; using ListIteratorPlatform, ListType>::m_list; static inline QVector toVector(const QVector &vector) { return vector; } static inline QVector toVector(const QList &list) { return list.toVector(); } static inline QList toList(const QVector &vector) { return vector.toList(); } static inline QList toList(const QList &list) { return list; } public: inline ListIterator(const ListType &list) : ListIteratorPlatform, ListType>(list) { } virtual QList toList() { return toList(m_list); } virtual QVector toVector() { return toVector(m_list); } private: inline const T &inputToOutputItem(const T &inputType) const { return inputType; } friend class ListIteratorPlatform, ListType>; // needed for MSVC 2005 friend class DeduplicateIterator; }; template inline typename QAbstractXmlForwardIterator::Ptr makeListIterator(const QList &list) { return typename ListIterator::Ptr(new ListIterator(list)); } template inline typename QAbstractXmlForwardIterator::Ptr makeVectorIterator(const QVector &vector) { return typename ListIterator >::Ptr(new ListIterator >(vector)); } } template QList QAbstractXmlForwardIterator::toList() { QList result; T item(next()); while(!qIsForwardIteratorEnd(item)) { result.append(item); item = next(); } return result; } template qint64 QAbstractXmlForwardIterator::count() { qint64 retval = 0; while(!qIsForwardIteratorEnd(next())) ++retval; return retval; } template typename QAbstractXmlForwardIterator::Ptr QAbstractXmlForwardIterator::toReversed() { T item(next()); QList result; while(!qIsForwardIteratorEnd(item)) { result.prepend(item); item = next(); } return QExplicitlySharedDataPointer >(new QPatternist::ListIterator(result)); } template T QAbstractXmlForwardIterator::last() { T item(next()); while(!qIsForwardIteratorEnd(item)) item = next(); return item; } template typename QAbstractXmlForwardIterator::Ptr QAbstractXmlForwardIterator::copy() const { Q_ASSERT_X(false, Q_FUNC_INFO, "This function is internal, unsupported, and should never be called."); return typename QAbstractXmlForwardIterator::Ptr(); } template bool QAbstractXmlForwardIterator::isEmpty() { return qIsForwardIteratorEnd(next()); } template qint64 QAbstractXmlForwardIterator::sizeHint() const { Q_ASSERT_X(false, Q_FUNC_INFO, "This function is currently not expected to be used."); return -1; } QT_END_NAMESPACE QT_END_HEADER #endif