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

Implements the except operator. That is, the computation of the sequence of nodes from one sequence, that doesn't appear in the other. More...

#include <qunioniterator_p.h>

Inheritance diagram for QPatternist::UnionIterator:
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...
 
 UnionIterator (const Item::Iterator::Ptr &it1, const Item::Iterator::Ptr &it2)
 
- 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...
 

Private Functions

Item nextFromFirstOperand ()
 

Properties

Item m_current
 
const Item::Iterator::Ptr m_it1
 
const Item::Iterator::Ptr m_it2
 
Item m_node1
 
Item m_node2
 
xsInteger m_position
 

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

Implements the except operator. That is, the computation of the sequence of nodes from one sequence, that doesn't appear in the other.

Definition at line 70 of file qunioniterator_p.h.

Constructors and Destructors

◆ UnionIterator()

UnionIterator::UnionIterator ( const Item::Iterator::Ptr it1,
const Item::Iterator::Ptr it2 
)

It is assumed that it1 and it2 are in document order and without duplicates.

Definition at line 50 of file qunioniterator.cpp.

Referenced by copy().

51  : m_it1(it1),
52  m_it2(it2),
53  m_position(0),
54  m_node1(m_it1->next()),
55  m_node2(m_it2->next())
56 {
57  Q_ASSERT(m_it1);
58  Q_ASSERT(m_it2);
59 }
const Item::Iterator::Ptr m_it1
const Item::Iterator::Ptr m_it2
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

Functions

◆ copy()

Item::Iterator::Ptr UnionIterator::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 126 of file qunioniterator.cpp.

127 {
128  return Item::Iterator::Ptr(new UnionIterator(m_it1->copy(), m_it2->copy()));
129 }
const Item::Iterator::Ptr m_it1
const Item::Iterator::Ptr m_it2
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
UnionIterator(const Item::Iterator::Ptr &it1, const Item::Iterator::Ptr &it2)

◆ current()

Item UnionIterator::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 116 of file qunioniterator.cpp.

117 {
118  return m_current;
119 }

◆ next()

Item UnionIterator::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 61 of file qunioniterator.cpp.

62 {
63  ++m_position;
64  if(m_node1 && m_node2)
65  {
66  if(m_node1.asNode().model() != m_node2.asNode().model())
67  {
69  m_node1 = m_it1->next();
70  return m_current;
71  }
72 
74  {
76  {
78  m_node1 = m_it1->next();
79  return m_current;
80  }
82  {
84  m_node2 = m_it2->next();
85  return m_current;
86  }
87  default:
88  {
90  m_node1 = m_it1->next();
91  m_node2 = m_it2->next();
92  return m_current;
93  }
94  }
95  }
96 
97  if(m_node1)
98  {
100  m_node1 = m_it1->next();
101  return m_current;
102  }
103 
104  if(m_node2)
105  {
106  m_current = m_node2;
107  m_node2 = m_it2->next();
108  return m_current;
109  }
110 
111  m_current.reset();
112  m_position = -1;
113  return Item();
114 }
DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const
Definition: qitem_p.h:481
const Item::Iterator::Ptr m_it1
const Item::Iterator::Ptr m_it2
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182

◆ nextFromFirstOperand()

Item QPatternist::UnionIterator::nextFromFirstOperand ( )
inlineprivate

Definition at line 86 of file qunioniterator_p.h.

87  {
88  ++m_position;
90  m_node1 = m_it1->next();
91  return m_current;
92  }
const Item::Iterator::Ptr m_it1

◆ position()

xsInteger UnionIterator::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 121 of file qunioniterator.cpp.

122 {
123  return m_position;
124 }

Properties

◆ m_current

Item QPatternist::UnionIterator::m_current
private

Definition at line 96 of file qunioniterator_p.h.

Referenced by current(), next(), and nextFromFirstOperand().

◆ m_it1

const Item::Iterator::Ptr QPatternist::UnionIterator::m_it1
private

Definition at line 94 of file qunioniterator_p.h.

Referenced by copy(), next(), nextFromFirstOperand(), and UnionIterator().

◆ m_it2

const Item::Iterator::Ptr QPatternist::UnionIterator::m_it2
private

Definition at line 95 of file qunioniterator_p.h.

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

◆ m_node1

Item QPatternist::UnionIterator::m_node1
private

Definition at line 98 of file qunioniterator_p.h.

Referenced by next(), and nextFromFirstOperand().

◆ m_node2

Item QPatternist::UnionIterator::m_node2
private

Definition at line 99 of file qunioniterator_p.h.

Referenced by next().

◆ m_position

xsInteger QPatternist::UnionIterator::m_position
private

Definition at line 97 of file qunioniterator_p.h.

Referenced by next(), nextFromFirstOperand(), and position().


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