/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtXmlPatterns module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or (at your option) the GNU General ** Public license version 3 or any later version approved by the KDE Free ** Qt Foundation. The licenses are as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 ** included in the packaging of this file. Please review the following ** information to ensure the GNU General Public License requirements will ** be met: https://www.gnu.org/licenses/gpl-2.0.html and ** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $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 #include QT_BEGIN_NAMESPACE 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 QVector toVector(); 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: OutputType next() override { 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; } OutputType current() const override { return m_current; } qint64 position() const override { return m_position; } qint64 count() override { return m_list.count(); } typename QAbstractXmlForwardIterator::Ptr copy() const override { 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; public: inline ListIterator(const ListType &list) : ListIteratorPlatform, ListType>(list) { } QVector toVector() override { return 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 QVector QAbstractXmlForwardIterator::toVector() { QVector 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 #endif