| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit. | 
| 7 | ** | 
| 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 The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 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 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 |  | 
| 40 | // | 
| 41 | //  W A R N I N G | 
| 42 | //  ------------- | 
| 43 | // | 
| 44 | // This file is not part of the Qt API.  It exists purely as an | 
| 45 | // implementation detail.  This header file may change from version to | 
| 46 | // version without notice, or even be removed. | 
| 47 | // | 
| 48 | // We mean it. | 
| 49 |  | 
| 50 | #ifndef Patternist_CachingIterator_H | 
| 51 | #define Patternist_CachingIterator_H | 
| 52 |  | 
| 53 | #include <QList> | 
| 54 | #include <QVector> | 
| 55 |  | 
| 56 | #include <private/qdynamiccontext_p.h> | 
| 57 | #include <private/qitem_p.h> | 
| 58 |  | 
| 59 | QT_BEGIN_NAMESPACE | 
| 60 |  | 
| 61 | namespace QPatternist | 
| 62 | { | 
| 63 |     /** | 
| 64 |      * @short An QAbstractXmlForwardIterator that gets its item from a cache unless its empty, in | 
| 65 |      * which case it continues to populate the cache as well as deliver on its | 
| 66 |      * own from a source QAbstractXmlForwardIterator. | 
| 67 |      * | 
| 68 |      * @author Frans Englich <frans.frans.englich@nokia.com> | 
| 69 |      * @ingroup Patternist_iterators | 
| 70 |      */ | 
| 71 |     class CachingIterator : public Item::Iterator | 
| 72 |     { | 
| 73 |     public: | 
| 74 |         /** | 
| 75 |          * We always use the same cache cell so why don't we use it directly, | 
| 76 |          * instead of passing the slot and ItemSequenceCacheCell::Vector to | 
| 77 |          * this class? Because the GenericDynamicContext might decide to resize | 
| 78 |          * the vector and that would invalidate the reference. | 
| 79 |          * | 
| 80 |          * We intentionally pass in a non-const reference here. | 
| 81 |          */ | 
| 82 |         CachingIterator(ItemSequenceCacheCell::Vector &cacheCells, | 
| 83 |                         const VariableSlotID slot, | 
| 84 |                         const DynamicContext::Ptr &context); | 
| 85 |  | 
| 86 |         virtual Item next(); | 
| 87 |         virtual Item current() const; | 
| 88 |         virtual xsInteger position() const; | 
| 89 |         virtual Item::Iterator::Ptr copy() const; | 
| 90 |  | 
| 91 |     private: | 
| 92 |         Item                        m_current; | 
| 93 |         xsInteger                   m_position; | 
| 94 |  | 
| 95 |         /** | 
| 96 |          * This variable cannot be called m_slot, because | 
| 97 |          * /usr/include/sys/sysmacros.h on hpuxi-acc defines it. | 
| 98 |          */ | 
| 99 |         const VariableSlotID        m_varSlot; | 
| 100 |  | 
| 101 |         /** | 
| 102 |          * We don't use the context. We only keep a reference such that it | 
| 103 |          * doesn't get deleted, and m_cacheCells starts to dangle. | 
| 104 |          */ | 
| 105 |         const DynamicContext::Ptr   m_context; | 
| 106 |  | 
| 107 |         /** | 
| 108 |          * We intentionally store a reference here such that we are able to | 
| 109 |          * modify the item. | 
| 110 |          */ | 
| 111 |         ItemSequenceCacheCell::Vector &m_cacheCells; | 
| 112 |  | 
| 113 |         /** | 
| 114 |          * Whether this CachingIterator is delivering items from | 
| 115 |          * m_cacheCell.cacheItems or from m_cacheCell.sourceIterator. | 
| 116 |          */ | 
| 117 |         bool m_usingCache; | 
| 118 |     }; | 
| 119 | } | 
| 120 |  | 
| 121 | QT_END_NAMESPACE | 
| 122 |  | 
| 123 | #endif | 
| 124 |  |