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

Picks out a slice from another QAbstractXmlForwardIterator, specified by a start and end position. More...

#include <qsubsequenceiterator_p.h>

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

Public Functions

virtual Item::Iterator::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual Item current () const
 Returns the current item in the sequence. More...
 
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...
 
 SubsequenceIterator (const Item::Iterator::Ptr &iterator, const xsInteger start, const xsInteger length)
 
- Public Functions inherited from QAbstractXmlForwardIterator< T >
virtual qint64 count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
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

xsInteger m_counter
 
Item m_current
 
const Item::Iterator::Ptr m_it
 
const xsInteger m_len
 
xsInteger m_position
 
const xsInteger m_start
 
const xsInteger m_stop
 

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

Picks out a slice from another QAbstractXmlForwardIterator, specified by a start and end position.

SubsequenceIterator allows a "slice", a subsequence, from an QAbstractXmlForwardIterator to be extracted. The SubsequenceIterator's constructor takes a source QAbstractXmlForwardIterator, a start position, and the length of the subsequence to be extracted.

SubsequenceIterator contains the central business logic to implement the fn:subsequence() function. The detailed behavior, such as how it behaves if the source QAbstractXmlForwardIterator is empty or if the specified subsequence stretches beyond the source QAbstractXmlForwardIterator, is therefore consistent with the definition of the fn:subsequence() function.

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

Definition at line 81 of file qsubsequenceiterator_p.h.

Constructors and Destructors

◆ SubsequenceIterator()

SubsequenceIterator::SubsequenceIterator ( const Item::Iterator::Ptr iterator,
const xsInteger  start,
const xsInteger  length 
)

Creates a SubsequenceIterator that extracts a subsequence from the sequence in iterator, as specified by the start position and length parameter.

Parameters
iteratorthe iterator which the subsequence should be extracted from
startthe start position of extraction. Must be 1 or larger.
lengththe length of the subsequence to extract. If it is -1, to the end is returned. The value must be -1 or 1 or larger.

Definition at line 50 of file qsubsequenceiterator.cpp.

Referenced by copy().

53  : m_position(0),
54  m_it(iterator),
55  m_counter(start),
56  m_start(start),
57  m_len(len),
59 {
60  Q_ASSERT(iterator);
61  Q_ASSERT(start >= 1);
62  Q_ASSERT(len == -1 || len >= 1);
63 
64  /* Note, "The first item of a sequence is located at position 1, not position 0." */
65  for(xsInteger i = 1; i != m_start; ++i)
66  m_it->next();
67 }
qint64 xsInteger
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

Functions

◆ copy()

Item::Iterator::Ptr SubsequenceIterator::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 105 of file qsubsequenceiterator.cpp.

106 {
108 }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
SubsequenceIterator(const Item::Iterator::Ptr &iterator, const xsInteger start, const xsInteger length)

◆ current()

Item SubsequenceIterator::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 95 of file qsubsequenceiterator.cpp.

◆ next()

Item SubsequenceIterator::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 69 of file qsubsequenceiterator.cpp.

70 {
71  if(m_position == -1)
72  return Item();
73 
74  m_current = m_it->next();
75  ++m_position;
76 
77  if(m_len == -1)
78  {
79  if(!m_current)
80  m_position = -1;
81 
82  return m_current;
83  }
84 
85  ++m_counter;
86 
87  if(!(m_counter > m_stop) && m_current)
88  return m_current;
89 
90  m_position = -1;
91  m_current.reset();
92  return Item();
93 }
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182

◆ position()

xsInteger SubsequenceIterator::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 100 of file qsubsequenceiterator.cpp.

101 {
102  return m_position;
103 }

Properties

◆ m_counter

xsInteger QPatternist::SubsequenceIterator::m_counter
private

Definition at line 107 of file qsubsequenceiterator_p.h.

Referenced by next().

◆ m_current

Item QPatternist::SubsequenceIterator::m_current
private

Definition at line 105 of file qsubsequenceiterator_p.h.

Referenced by current(), and next().

◆ m_it

const Item::Iterator::Ptr QPatternist::SubsequenceIterator::m_it
private

Definition at line 106 of file qsubsequenceiterator_p.h.

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

◆ m_len

const xsInteger QPatternist::SubsequenceIterator::m_len
private

Definition at line 109 of file qsubsequenceiterator_p.h.

Referenced by copy(), and next().

◆ m_position

xsInteger QPatternist::SubsequenceIterator::m_position
private

Definition at line 104 of file qsubsequenceiterator_p.h.

Referenced by next(), and position().

◆ m_start

const xsInteger QPatternist::SubsequenceIterator::m_start
private

Definition at line 108 of file qsubsequenceiterator_p.h.

Referenced by copy(), and SubsequenceIterator().

◆ m_stop

const xsInteger QPatternist::SubsequenceIterator::m_stop
private

Definition at line 110 of file qsubsequenceiterator_p.h.

Referenced by next().


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