[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[651] | 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | **
|
---|
[561] | 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.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include <QtDebug>
|
---|
| 43 |
|
---|
| 44 | #include "qacceliterators_p.h"
|
---|
| 45 |
|
---|
| 46 | QT_BEGIN_NAMESPACE
|
---|
| 47 |
|
---|
| 48 | using namespace QPatternist;
|
---|
| 49 |
|
---|
| 50 | xsInteger AccelIterator::position() const
|
---|
| 51 | {
|
---|
| 52 | return m_position;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | QXmlNodeModelIndex AccelIterator::current() const
|
---|
| 56 | {
|
---|
| 57 | return m_current;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | QXmlNodeModelIndex FollowingIterator::next()
|
---|
| 61 | {
|
---|
| 62 | /* "the following axis contains all nodes that are descendants
|
---|
| 63 | * of the root of the tree in which the context node is found,
|
---|
| 64 | * are not descendants of the context node, and occur after
|
---|
| 65 | * the context node in document order." */
|
---|
| 66 |
|
---|
| 67 | if(m_position == 0)
|
---|
| 68 | {
|
---|
| 69 | /* Skip the descendants. */
|
---|
| 70 | m_currentPre += m_document->size(m_preNumber) + 1;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | if(m_currentPre > m_document->maximumPreNumber())
|
---|
| 74 | return closedExit();
|
---|
| 75 |
|
---|
| 76 | while(m_document->kind(m_currentPre) == QXmlNodeModelIndex::Attribute)
|
---|
| 77 | {
|
---|
| 78 | ++m_currentPre;
|
---|
| 79 | if(m_currentPre > m_document->maximumPreNumber())
|
---|
| 80 | return closedExit();
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | m_current = m_document->createIndex(m_currentPre);
|
---|
| 84 | ++m_position;
|
---|
| 85 | ++m_currentPre;
|
---|
| 86 | return m_current;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | QXmlNodeModelIndex PrecedingIterator::next()
|
---|
| 90 | {
|
---|
| 91 | if(m_currentPre == -1)
|
---|
| 92 | return closedExit();
|
---|
| 93 |
|
---|
| 94 | /* We skip ancestors and attributes and take into account that they can be intermixed. If one
|
---|
| 95 | * skips them in two separate loops, one can end up with skipping all the attributes to then
|
---|
| 96 | * be positioned at an ancestor(which will be accepted because the ancestor loop was before the
|
---|
| 97 | * attributes loop). */
|
---|
| 98 | while(m_document->kind(m_currentPre) == QXmlNodeModelIndex::Attribute ||
|
---|
| 99 | m_document->postNumber(m_currentPre) > m_postNumber)
|
---|
| 100 | {
|
---|
| 101 | --m_currentPre;
|
---|
| 102 | if(m_currentPre == -1)
|
---|
| 103 | return closedExit();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | if(m_currentPre == -1)
|
---|
| 107 | {
|
---|
| 108 | m_currentPre = -1;
|
---|
| 109 | return closedExit();
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | /* Phew, m_currentPre is now 1) not an ancestor; and
|
---|
| 113 | * 2) not an attribute; and 3) preceds the context node. */
|
---|
| 114 |
|
---|
| 115 | m_current = m_document->createIndex(m_currentPre);
|
---|
| 116 | ++m_position;
|
---|
| 117 | --m_currentPre;
|
---|
| 118 |
|
---|
| 119 | return m_current;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | QXmlNodeModelIndex::Iterator::Ptr PrecedingIterator::copy() const
|
---|
| 123 | {
|
---|
| 124 | return QXmlNodeModelIndex::Iterator::Ptr(new PrecedingIterator(m_document, m_preNumber));
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | QXmlNodeModelIndex::Iterator::Ptr FollowingIterator::copy() const
|
---|
| 128 | {
|
---|
| 129 | return QXmlNodeModelIndex::Iterator::Ptr(new FollowingIterator(m_document, m_preNumber));
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | QXmlNodeModelIndex ChildIterator::next()
|
---|
| 133 | {
|
---|
| 134 | if(m_currentPre == -1)
|
---|
| 135 | return closedExit();
|
---|
| 136 |
|
---|
| 137 | ++m_position;
|
---|
| 138 | m_current = m_document->createIndex(m_currentPre);
|
---|
| 139 |
|
---|
| 140 | /* We get the count of the descendants, and increment m_currentPre. After
|
---|
| 141 | * this, m_currentPre is the node after the descendants. */
|
---|
| 142 | m_currentPre += m_document->size(m_currentPre);
|
---|
| 143 | ++m_currentPre;
|
---|
| 144 |
|
---|
| 145 | if(m_currentPre > m_document->maximumPreNumber() || m_document->depth(m_currentPre) != m_depth)
|
---|
| 146 | m_currentPre = -1;
|
---|
| 147 |
|
---|
| 148 | return m_current;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | QXmlNodeModelIndex::Iterator::Ptr ChildIterator::copy() const
|
---|
| 152 | {
|
---|
| 153 | return QXmlNodeModelIndex::Iterator::Ptr(new ChildIterator(m_document, m_preNumber));
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | QXmlNodeModelIndex AttributeIterator::next()
|
---|
| 157 | {
|
---|
| 158 | if(m_currentPre == -1)
|
---|
| 159 | return closedExit();
|
---|
| 160 | else
|
---|
| 161 | {
|
---|
| 162 | m_current = m_document->createIndex(m_currentPre);
|
---|
| 163 | ++m_position;
|
---|
| 164 |
|
---|
| 165 | ++m_currentPre;
|
---|
| 166 |
|
---|
| 167 | if(m_currentPre > m_document->maximumPreNumber() ||
|
---|
| 168 | m_document->kind(m_currentPre) != QXmlNodeModelIndex::Attribute)
|
---|
| 169 | m_currentPre = -1;
|
---|
| 170 |
|
---|
| 171 | return m_current;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | QXmlNodeModelIndex::Iterator::Ptr AttributeIterator::copy() const
|
---|
| 176 | {
|
---|
| 177 | return QXmlNodeModelIndex::Iterator::Ptr(new AttributeIterator(m_document, m_preNumber));
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | QT_END_NAMESPACE
|
---|
| 181 |
|
---|