Qt 4.8
Public Functions | Properties | List of all members
QPatternist::InsertionIterator Class Reference

Conceptually inserts one QAbstractXmlForwardIterator into another, make two QAbstractXmlForwardIterator instances appear as one. More...

#include <qinsertioniterator_p.h>

Inheritance diagram for QPatternist::InsertionIterator:
QAbstractXmlForwardIterator< T > QSharedData

Public Functions

virtual Item::Iterator::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual xsInteger count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
virtual Item current () const
 Returns the current item in the sequence. More...
 
 InsertionIterator (const Item::Iterator::Ptr &target, const xsInteger position, const Item::Iterator::Ptr &insertIterator)
 
virtual Item next ()
 Returns the next item in the sequence, or a null object if the end has been reached. More...
 
virtual xsInteger position () const
 Returns the current position in the sequence represented by this. More...
 
- Public Functions inherited from QAbstractXmlForwardIterator< T >
virtual bool isEmpty ()
 Returns true if the sequence is empty. More...
 
virtual T last ()
 Returns the item at the end of this QAbstractXmlForwardIterator. More...
 
 QAbstractXmlForwardIterator ()
 Default constructor. More...
 
virtual qint64 sizeHint () const
 Gives a hint to the size of the contained sequence. More...
 
virtual QList< T > toList ()
 Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList. More...
 
virtual QAbstractXmlForwardIterator< T >::Ptr toReversed ()
 Returns a reverse iterator for the sequence. More...
 
virtual ~QAbstractXmlForwardIterator ()
 Destructor. More...
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Properties

Item m_current
 
const xsInteger m_insertPos
 
const Item::Iterator::Ptr m_inserts
 
bool m_isInserting
 
xsInteger m_position
 
const Item::Iterator::Ptr m_target
 

Additional Inherited Members

- Public Types inherited from QAbstractXmlForwardIterator< T >
typedef QList< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > > List
 A QList containing QAbstractXmlForwardIterator::Ptr instances. More...
 
typedef QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
 A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass. More...
 
typedef QVector< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > > Vector
 A QVector containing QAbstractXmlForwardIterator::Ptr instances. More...
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Conceptually inserts one QAbstractXmlForwardIterator into another, make two QAbstractXmlForwardIterator instances appear as one.

An InsertionIterator represents a sequence that is the merge of two sequences, where one of the iterators is conceptually inserted at a given position. This is done while retaining the characteristic of being pull-based.

InsertionIterator contains the logic for the implementation of the fn:insert-before() function, whose definition therefore specifies the detailed behaviors of the InsertionIterator.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 15.1.7 fn:insert-before
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 81 of file qinsertioniterator_p.h.

Constructors and Destructors

◆ InsertionIterator()

InsertionIterator::InsertionIterator ( const Item::Iterator::Ptr target,
const xsInteger  position,
const Item::Iterator::Ptr insertIterator 
)

Creates an InsertionIterator whose result is a merge of the iterator insertIterator into the iterator target at position position.

Parameters
targetthe iterator containing the items that the item in insertIterator will be inserted into.
positionthe insertion position. Must be 1 or larger
insertIteratorthe iterator containing the items to insert at position position

Definition at line 49 of file qinsertioniterator.cpp.

Referenced by copy().

52  : m_target(target),
53  m_insertPos(pos),
54  m_inserts(inserts),
55  m_position(0),
56  m_isInserting(pos == 1)
57 {
58  Q_ASSERT(target);
59  Q_ASSERT(inserts);
60  Q_ASSERT(m_insertPos >= 1);
61 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const Item::Iterator::Ptr m_target
const Item::Iterator::Ptr m_inserts

Functions

◆ copy()

Item::Iterator::Ptr InsertionIterator::copy ( ) const
virtual

Copies this QAbstractXmlForwardIterator and returns the copy.

Warning
This function is not part of the public interface.

A copy and the original instance are completely independent of each other. Because evaluating an QAbstractXmlForwardIterator modifies it, one should always use a copy when an QAbstractXmlForwardIterator needs to be used several times.

Reimplemented from QAbstractXmlForwardIterator< T >.

Definition at line 123 of file qinsertioniterator.cpp.

124 {
125  return Item::Iterator::Ptr(new InsertionIterator(m_target->copy(), m_insertPos, m_inserts->copy()));
126 }
const Item::Iterator::Ptr m_target
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
const Item::Iterator::Ptr m_inserts
InsertionIterator(const Item::Iterator::Ptr &target, const xsInteger position, const Item::Iterator::Ptr &insertIterator)

◆ count()

xsInteger InsertionIterator::count ( )
virtual

Determines the number of items this QAbstractXmlForwardIterator represents.

Warning
This function is not part of the public interface.

Note that this function is not const. It modifies the QAbstractXmlForwardIterator. The reason for this is efficiency. If this QAbstractXmlForwardIterator must not be changed, get a copy() before performing the count.

The default implementation simply calls next() until the end is reached. Hence, it may be of interest to override this function if the sub-class knows a better way of computing its count.

The number of items in the sequence is returned.

Reimplemented from QAbstractXmlForwardIterator< T >.

Definition at line 108 of file qinsertioniterator.cpp.

109 {
110  return m_target->count() + m_inserts->count();
111 }
const Item::Iterator::Ptr m_target
const Item::Iterator::Ptr m_inserts

◆ current()

Item InsertionIterator::current ( ) const
virtual

Returns the current item in the sequence.

If this function is called before the first call to next(), a null object is returned. If the end of the sequence has been reached, a null object is returned.

Implements QAbstractXmlForwardIterator< T >.

Definition at line 113 of file qinsertioniterator.cpp.

114 {
115  return m_current;
116 }

◆ next()

Item InsertionIterator::next ( )
virtual

Returns the next item in the sequence, or a null object if the end has been reached.

Implements QAbstractXmlForwardIterator< T >.

Definition at line 63 of file qinsertioniterator.cpp.

64 {
65  if(m_isInserting)
66  {
67  m_current = m_inserts->next();
68 
69  if(m_current)
70  {
71  ++m_position;
72  return m_current;
73  }
74  }
75  else if(m_position == (m_insertPos - 1) && !m_isInserting)
76  { /* Entered only the first time insertion starts. */
77  m_isInserting = true;
78  return next();
79  }
80 
81  ++m_position;
82  m_current = m_target->next();
83 
84  if(m_current)
85  return m_current;
86  else if(m_inserts->position() == -1) /* We're at the end of the both iterators. */
87  {
88  m_position = -1;
89  m_current.reset();
90  return Item();
91  }
92 
93  /* Insert the insertion iterator, since it's still left. */
94  Q_ASSERT(m_target->position() < m_insertPos);
95  m_isInserting = true;
96  m_current = m_inserts->next();
97 
98  if(m_current)
99  return m_current;
100  else
101  {
102  /* m_current is already null, so no need to reset it. */
103  m_position = -1;
104  return Item();
105  }
106 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const Item::Iterator::Ptr m_target
const Item::Iterator::Ptr m_inserts
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual Item next()
Returns the next item in the sequence, or a null object if the end has been reached.

◆ position()

xsInteger InsertionIterator::position ( ) const
virtual

Returns the current position in the sequence represented by this.

The first position is 1, not 0. If next() hasn't been called, 0 is returned. If this has reached the end, -1 is returned.

Implements QAbstractXmlForwardIterator< T >.

Definition at line 118 of file qinsertioniterator.cpp.

119 {
120  return m_position;
121 }

Properties

◆ m_current

Item QPatternist::InsertionIterator::m_current
private

Definition at line 110 of file qinsertioniterator_p.h.

Referenced by current(), and next().

◆ m_insertPos

const xsInteger QPatternist::InsertionIterator::m_insertPos
private

Definition at line 108 of file qinsertioniterator_p.h.

Referenced by copy(), InsertionIterator(), and next().

◆ m_inserts

const Item::Iterator::Ptr QPatternist::InsertionIterator::m_inserts
private

Definition at line 109 of file qinsertioniterator_p.h.

Referenced by copy(), count(), and next().

◆ m_isInserting

bool QPatternist::InsertionIterator::m_isInserting
private

Definition at line 112 of file qinsertioniterator_p.h.

Referenced by next().

◆ m_position

xsInteger QPatternist::InsertionIterator::m_position
private

Definition at line 111 of file qinsertioniterator_p.h.

Referenced by next(), and position().

◆ m_target

const Item::Iterator::Ptr QPatternist::InsertionIterator::m_target
private

Definition at line 107 of file qinsertioniterator_p.h.

Referenced by copy(), count(), and next().


The documentation for this class was generated from the following files: