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

RangeIterator represents a sequence of integers between a start and end value. More...

#include <qrangeiterator_p.h>

Inheritance diagram for QPatternist::RangeIterator:
QAbstractXmlForwardIterator< Item > QSharedData

Public Types

enum  Direction { Backward = 0, Forward = 1 }
 
- Public Types inherited from QAbstractXmlForwardIterator< Item >
typedef QList< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > > List
 A QList containing QAbstractXmlForwardIterator::Ptr instances. More...
 
typedef QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
 A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass. More...
 
typedef QVector< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > > Vector
 A QVector containing QAbstractXmlForwardIterator::Ptr instances. More...
 

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...
 
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...
 
 RangeIterator (const xsInteger start, const Direction direction, const xsInteger end)
 
virtual Item::Iterator::Ptr toReversed ()
 Returns a reverse iterator for the sequence. More...
 
- Public Functions inherited from QAbstractXmlForwardIterator< Item >
virtual bool isEmpty ()
 Returns true if the sequence is empty. More...
 
virtual Item 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< ItemtoList ()
 Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList. 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_count
 
Item m_current
 
const Direction m_direction
 
xsInteger m_end
 
const qint8 m_increment: 2
 
xsInteger m_position
 
xsInteger m_start
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

RangeIterator represents a sequence of integers between a start and end value.

The RangeIterator contains the evaluation logic for the range expression, N to M, and its behavior is therefore consistent with the definition of that XPath expression. Hence, the detailed behavior of the RangeIterator can be found in the XPath 2.0 specification.

See also
XML Path Language (XPath) 2.0, 3.3 Sequence Expressions, RangeExpr
RangeExpression
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 79 of file qrangeiterator_p.h.

Enumerations

◆ Direction

RangeIterator can iterate in both directions. This enumerator exist for identifying different directions.

Enumerator
Backward 

Signifies that the QAbstractXmlForwardIterator operates in a reverse direction, where the first item returned by the next() function is from the beginning of the source sequence.

Forward 

Signifies the forward direction. Iterators do conceptually operate in the forward direction by default.

Definition at line 87 of file qrangeiterator_p.h.

Constructors and Destructors

◆ RangeIterator()

RangeIterator::RangeIterator ( const xsInteger  start,
const Direction  direction,
const xsInteger  end 
)

Creates an QAbstractXmlForwardIterator that returns integer values from consecutive sequence of integers between start and end, where the step taken between each integer is 1 with polarity as specified in direction.

Note
start must be smaller than end, not larger or equal. This is not checked.

Definition at line 50 of file qrangeiterator.cpp.

Referenced by copy(), and toReversed().

53  : m_start(start),
54  m_end(end),
55  m_position(0),
56  m_count(start),
58  m_increment(m_direction == Forward ? 1 : -1)
59 {
62 
63  if(m_direction == Backward)
64  {
66  m_count = m_start;
67  }
68 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
static const KeyPair *const end
Qt::LayoutDirection direction

Functions

◆ copy()

Item::Iterator::Ptr RangeIterator::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< Item >.

Definition at line 118 of file qrangeiterator.cpp.

119 {
120  if(m_direction == Backward)
122  else
124 }
RangeIterator(const xsInteger start, const Direction direction, const xsInteger end)
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.

◆ count()

xsInteger RangeIterator::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< Item >.

Definition at line 90 of file qrangeiterator.cpp.

91 {
92  /* This complication is for handling that m_start & m_end may be reversed. */
93  xsInteger ret;
94 
95  if(m_start < m_end)
96  ret = m_end - m_start;
97  else
98  ret = m_start - m_end;
99 
100  return ret + 1;
101 }
qint64 xsInteger

◆ current()

Item RangeIterator::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< Item >.

Definition at line 108 of file qrangeiterator.cpp.

109 {
110  return m_current;
111 }

◆ next()

Item RangeIterator::next ( )
virtual

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

Implements QAbstractXmlForwardIterator< Item >.

Definition at line 70 of file qrangeiterator.cpp.

71 {
72  if(m_position == -1)
73  return Item();
74  else if((m_direction == Forward && m_count > m_end) ||
76  {
77  m_position = -1;
78  m_current.reset();
79  return Item();
80  }
81  else
82  {
85  ++m_position;
86  return m_current;
87  }
88 }
static Item fromValue(const xsInteger num)
Definition: qinteger.cpp:52
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182

◆ position()

xsInteger RangeIterator::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< Item >.

Definition at line 113 of file qrangeiterator.cpp.

114 {
115  return m_position;
116 }

◆ toReversed()

Item::Iterator::Ptr RangeIterator::toReversed ( )
virtual

Returns a reverse iterator for the sequence.

Warning
This function is not part of the public interface.

This function may modify the iterator, it can be considered a function that evaluates this QAbstractXmlForwardIterator. It is not a getter, but potentially alters the iterator in the same way the next() function does. If this QAbstractXmlForwardIterator must not be modified, such that it can be used for evaluation with next(), use a copy().

Reimplemented from QAbstractXmlForwardIterator< Item >.

Definition at line 103 of file qrangeiterator.cpp.

104 {
106 }
RangeIterator(const xsInteger start, const Direction direction, const xsInteger end)
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.

Properties

◆ m_count

xsInteger QPatternist::RangeIterator::m_count
private

Definition at line 127 of file qrangeiterator_p.h.

Referenced by next(), and RangeIterator().

◆ m_current

Item QPatternist::RangeIterator::m_current
private

Definition at line 125 of file qrangeiterator_p.h.

Referenced by current(), and next().

◆ m_direction

const Direction QPatternist::RangeIterator::m_direction
private

Definition at line 128 of file qrangeiterator_p.h.

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

◆ m_end

xsInteger QPatternist::RangeIterator::m_end
private

Definition at line 124 of file qrangeiterator_p.h.

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

◆ m_increment

const qint8 QPatternist::RangeIterator::m_increment
private

We only need to store -1 or 1, so save memory with a bit field.

Definition at line 133 of file qrangeiterator_p.h.

Referenced by next().

◆ m_position

xsInteger QPatternist::RangeIterator::m_position
private

Definition at line 126 of file qrangeiterator_p.h.

Referenced by next(), and position().

◆ m_start

xsInteger QPatternist::RangeIterator::m_start
private

Definition at line 123 of file qrangeiterator_p.h.

Referenced by copy(), count(), RangeIterator(), and toReversed().


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