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

Removes one items at a specified position from an input QAbstractXmlForwardIterator. More...

#include <qremovaliterator_p.h>

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

Public Functions

virtual Item::Iterator::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual xsInteger count ()
 
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...
 
 RemovalIterator (const Item::Iterator::Ptr &target, const xsInteger position)
 
- 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< Item >::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
 
xsInteger m_position
 
const xsInteger m_removalPos
 
const Item::Iterator::Ptr m_target
 

Additional Inherited Members

- 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 Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Removes one items at a specified position from an input QAbstractXmlForwardIterator.

RemoveIterator removes an item from a sequence at a certain position, while retaining the pull-based characteristic of being an QAbstractXmlForwardIterator itself. The RemovalIterator's constructor is passed an QAbstractXmlForwardIterator, the QAbstractXmlForwardIterator to remove from, and the position of the item to remove. When calling the RemovalIterator's functions, it acts as an ordinary QAbstractXmlForwardIterator, taking into account that one item is removed from the source QAbstractXmlForwardIterator.

The RemovalIterator class contains the central business logic for implementing the fn:remove() function, whose definition therefore specifies the detailed behaviors of RemovalIterator.

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

Definition at line 83 of file qremovaliterator_p.h.

Constructors and Destructors

◆ RemovalIterator()

RemovalIterator::RemovalIterator ( const Item::Iterator::Ptr target,
const xsInteger  position 
)

Creates an RemovalIterator.

Parameters
targetthe QAbstractXmlForwardIterator containing the sequence of items which the item at position position should be removed from.
positionthe position of the item to remove. Must be 1 or larger.

Definition at line 49 of file qremovaliterator.cpp.

Referenced by copy().

50  : m_target(target),
51  m_removalPos(pos),
52  m_position(0)
53 {
54  Q_ASSERT(target);
55  Q_ASSERT(pos >= 1);
56 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const Item::Iterator::Ptr m_target

Functions

◆ copy()

Item::Iterator::Ptr RemovalIterator::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 104 of file qremovaliterator.cpp.

105 {
107 }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
RemovalIterator(const Item::Iterator::Ptr &target, const xsInteger position)
const Item::Iterator::Ptr m_target

◆ count()

xsInteger RemovalIterator::count ( )
virtual

The QAbstractXmlForwardIterator's count is computed by subtracting one from the source QAbstractXmlForwardIterator's count.

Reimplemented from QAbstractXmlForwardIterator< Item >.

Definition at line 84 of file qremovaliterator.cpp.

85 {
86  const xsInteger itc = m_target->count();
87 
88  if(itc < m_removalPos)
89  return itc;
90  else
91  return itc - 1;
92 }
qint64 xsInteger
const Item::Iterator::Ptr m_target

◆ current()

Item RemovalIterator::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 94 of file qremovaliterator.cpp.

95 {
96  return m_current;
97 }

◆ next()

Item RemovalIterator::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 58 of file qremovaliterator.cpp.

59 {
60  if(m_position == -1)
61  return Item();
62 
63  m_current = m_target->next();
64 
65  if(!m_current)
66  {
67  m_position = -1;
68  m_current.reset();
69  return Item();
70  }
71 
72  ++m_position;
73 
75  {
76  next(); /* Recurse, return the next item. */
77  --m_position; /* Don't count the one we removed. */
78  return m_current;
79  }
80 
81  return m_current;
82 }
virtual Item next()
Returns the next item in the sequence, or a null object if the end has been reached.
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
const Item::Iterator::Ptr m_target

◆ position()

xsInteger RemovalIterator::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 99 of file qremovaliterator.cpp.

100 {
101  return m_position;
102 }

Properties

◆ m_current

Item QPatternist::RemovalIterator::m_current
private

Definition at line 113 of file qremovaliterator_p.h.

Referenced by current(), and next().

◆ m_position

xsInteger QPatternist::RemovalIterator::m_position
private

Definition at line 114 of file qremovaliterator_p.h.

Referenced by next(), and position().

◆ m_removalPos

const xsInteger QPatternist::RemovalIterator::m_removalPos
private

Definition at line 112 of file qremovaliterator_p.h.

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

◆ m_target

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

Definition at line 111 of file qremovaliterator_p.h.

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


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