|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 |