Qt 4.8
qacceliterators_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef Patternist_AccelIterators_H
53 #define Patternist_AccelIterators_H
54 
55 #include "qacceltree_p.h"
56 #include "qitem_p.h"
57 
59 
61 
62 namespace QPatternist
63 {
71  {
72  public:
73  virtual xsInteger position() const;
74  virtual QXmlNodeModelIndex current() const;
75 
76  protected:
77  inline AccelIterator(const AccelTree *const doc,
78  const AccelTree::PreNumber pre,
79  const AccelTree::PreNumber currentPre) : m_document(doc)
80  , m_preNumber(pre)
81  , m_currentPre(currentPre)
82  , m_position(0)
83 
84  {
86  Q_ASSERT(m_preNumber >= 0);
87  }
88 
90  {
91  m_position = -1;
92  m_current.reset();
93  return QXmlNodeModelIndex();
94  }
95 
99  const AccelTree *const m_document;
100 
108  };
109 
115  template<const bool IncludeSelf>
117  {
118  public:
125  inline AncestorIterator(const AccelTree *const doc,
126  const AccelTree::PreNumber pre) : AccelIterator(doc, pre, IncludeSelf ? pre : doc->basicData.at(pre).parent())
127  {
128  Q_ASSERT(IncludeSelf || m_document->hasParent(pre));
129  }
130 
132  {
133  if(m_currentPre == -1)
134  return closedExit();
135  else
136  {
137  ++m_position;
140 
141  return m_current;
142  }
143  }
144 
146  {
148  }
149  };
150 
157  {
158  public:
162  inline ChildIterator(const AccelTree *const doc,
163  const AccelTree::PreNumber pre) : AccelIterator(doc, pre, pre + 1),
164  m_depth(m_document->depth(m_currentPre))
165  {
167 
168  /* Skip the attributes, that are children in the pre/post plane, of
169  * the node we're applying the child axis to. */
171  {
172  ++m_currentPre;
173  /* We check the depth here because we would otherwise include
174  * following siblings. */
176  {
177  m_currentPre = -1;
178  break;
179  }
180  }
181  }
182 
183  virtual QXmlNodeModelIndex next();
184  virtual QXmlNodeModelIndex::Iterator::Ptr copy() const;
185 
186  private:
188  };
189 
195  template<const bool IsFollowing>
197  {
198  public:
199  inline SiblingIterator(const AccelTree *const doc,
200  const AccelTree::PreNumber pre) : AccelIterator(doc, pre, pre + (IsFollowing ? 0 : -1)),
201  m_depth(doc->depth(pre))
202  {
203  Q_ASSERT_X(IsFollowing || pre != 0, "",
204  "When being preceding-sibling, the context node cannot be the first node in the document.");
205  Q_ASSERT_X(!IsFollowing || pre != m_document->maximumPreNumber(), "",
206  "When being following-sibling, the context node cannot be the last node in the document.");
207  }
208 
210  {
211  if(m_currentPre == -1)
212  return QXmlNodeModelIndex();
213 
214  if(IsFollowing)
215  {
216  /* Skip the descendants, and jump to the next node. */
218 
220  return closedExit();
221  else
222  {
223  ++m_position;
225  return m_current;
226  }
227  }
228  else
229  {
230  while(m_document->depth(m_currentPre) > m_depth)
231  --m_currentPre;
232 
234  --m_currentPre;
235 
236  if(m_document->depth(m_currentPre) == m_depth &&
238  {
240  ++m_position;
241  --m_currentPre;
242  return m_current;
243  }
244  else
245  {
246  m_currentPre = -1;
247  return closedExit();
248  }
249  }
250  }
251 
253  {
255  }
256 
257  private:
259  };
260 
267  template<const bool IncludeSelf>
269  {
270  public:
274  inline DescendantIterator(const AccelTree *const doc,
275  const AccelTree::PreNumber pre) : AccelIterator(doc, pre, pre + (IncludeSelf ? 0 : 1)),
276  m_postNumber(doc->postNumber(pre))
277  {
278  Q_ASSERT(IncludeSelf || m_document->hasChildren(pre));
279 
280  /* Make sure that m_currentPre is the first node part of this axis.
281  * Since we're not including ourself, advance to the node after our
282  * attributes, if any. */
283  if(!IncludeSelf)
284  {
286  {
287  ++m_currentPre;
288  /* We check the depth here because we would otherwise include
289  * following siblings. */
291  {
292  m_currentPre = -1;
293  break;
294  }
295  }
296  }
297  }
298 
300  {
301  if(m_currentPre == -1)
302  return closedExit();
303 
304  ++m_position;
306 
307  ++m_currentPre;
308 
310  {
311  m_currentPre = -1;
312  return m_current;
313  }
314 
315  if(m_document->postNumber(m_currentPre) < m_postNumber)
316  {
318  {
319  ++m_currentPre;
321  {
322  m_currentPre = -1;
323  break;
324  }
325  }
326  }
327  else
328  m_currentPre = -1;
329 
330  return m_current;
331  }
332 
334  {
336  }
337 
338  private:
340  };
341 
348  {
349  public:
353  inline FollowingIterator(const AccelTree *const doc,
354  const AccelTree::PreNumber pre) : AccelIterator(doc, pre, pre)
355  {
356  }
357 
358  virtual QXmlNodeModelIndex next();
359  virtual QXmlNodeModelIndex::Iterator::Ptr copy() const;
360  };
361 
368  {
369  public:
373  inline PrecedingIterator(const AccelTree *const doc,
374  const AccelTree::PreNumber pre) : AccelIterator(doc, pre,
375  pre - 1 /* currentPre */)
376  , m_postNumber(m_document->postNumber(m_preNumber))
377  {
378  }
379 
380  virtual QXmlNodeModelIndex next();
381  virtual QXmlNodeModelIndex::Iterator::Ptr copy() const;
382 
383  private:
385  };
386 
393  {
394  public:
398  inline AttributeIterator(const AccelTree *const doc, const AccelTree::PreNumber pre) : AccelIterator(doc, pre, pre + 1)
399  {
402  }
403 
404  virtual QXmlNodeModelIndex next();
405  virtual QXmlNodeModelIndex::Iterator::Ptr copy() const;
406  };
407 }
408 
410 
412 
413 #endif
virtual QXmlNodeModelIndex::Iterator::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
Iterates along the ancestor or ancestor-or-self axis in an AccelTree.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
Implements axis attribute for the AccelTree.
Iterates along the sibling axes in an AccelTree.
virtual QXmlNodeModelIndex next()
Returns the next item in the sequence, or a null object if the end has been reached.
qint64 xsInteger
#define at(className, varName)
Due to strong interdependencies, this file contains the definitions for the classes Item...
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
DescendantIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AncestorIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
bool hasParent(const PreNumber pre) const
Definition: qacceltree_p.h:312
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
PrecedingIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
virtual QXmlNodeModelIndex next()
Returns the next item in the sequence, or a null object if the end has been reached.
QVector< BasicNodeData > basicData
Definition: qacceltree_p.h:276
FollowingIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
The QAbstractXmlForwardIterator class is a base class for forward iterators.
The namespace for the internal API of QtXmlPatterns.
Implements axis following for the AccelTree.
bool hasChildren(const PreNumber pre) const
Returns true if the node identified by pre has child nodes(in the sense of the XDM), but also if it has namespace nodes, or attribute nodes.
Definition: qacceltree_p.h:294
QXmlNodeModelIndex m_current
Depth depth(const PreNumber pre) const
Definition: qacceltree_p.h:350
const AccelTree::Depth m_depth
SiblingIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
const AccelTree::Depth m_depth
virtual QAbstractXmlForwardIterator< T >::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
Implements axis preceding for the AccelTree.
Abstract base class for Iterators for the AccelTree, that contains common functions and members...
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Implements axis descendant and descendant-or-self for the AccelTree.
virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const
Returns a value indicating the kind of node identified by ni.
Definition: qacceltree.cpp:214
const AccelTree::PreNumber m_preNumber
Stores an XML document using the XPath Accelerator scheme, also known as pre/post numbering...
Definition: qacceltree_p.h:92
QXmlNodeModelIndex createIndex(qint64 data) const
Creates a node index with data as its internal data.
AccelIterator(const AccelTree *const doc, const AccelTree::PreNumber pre, const AccelTree::PreNumber currentPre)
PostNumber postNumber(const PreNumber pre) const
Definition: qacceltree_p.h:322
virtual QXmlNodeModelIndex::Iterator::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
virtual QXmlNodeModelIndex next()
Returns the next item in the sequence, or a null object if the end has been reached.
Iterates along the child axis in an AccelTree.
AccelTree::PreNumber m_currentPre
PreNumber maximumPreNumber() const
Definition: qacceltree_p.h:333
PreNumber size(const PreNumber pre) const
Definition: qacceltree_p.h:343
ChildIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
virtual QXmlNodeModelIndex current() const
Returns the current item in the sequence.
virtual QXmlNodeModelIndex::Iterator::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
AttributeIterator(const AccelTree *const doc, const AccelTree::PreNumber pre)
QXmlNodeModelIndex closedExit()
#define QT_END_HEADER
Definition: qglobal.h:137
virtual xsInteger position() const
Returns the current position in the sequence represented by this.
const AccelTree *const m_document
const AccelTree::PreNumber m_postNumber
const AccelTree::PreNumber m_postNumber
virtual T next()=0
Returns the next item in the sequence, or a null object if the end has been reached.