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

Implements the intersect operator. That is, the computation of the intersection between two sequences of nodes. More...

#include <qintersectiterator_p.h>

Inheritance diagram for QPatternist::IntersectIterator:
QAbstractXmlForwardIterator< Item > 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...
 
 IntersectIterator (const Item::Iterator::Ptr &it1, const Item::Iterator::Ptr &it2)
 
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< Item >
virtual qint64 count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
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...
 

Private Functions

Item closedExit ()
 

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< 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

Implements the intersect operator. That is, the computation of the intersection between two sequences of nodes.

The intersect operator can be seen as logical AND of the two sets.

Definition at line 71 of file qintersectiterator_p.h.

Constructors and Destructors

◆ IntersectIterator()

IntersectIterator::IntersectIterator ( 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 qintersectiterator.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 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const Item::Iterator::Ptr m_it2
const Item::Iterator::Ptr m_it1

Functions

◆ closedExit()

Item QPatternist::IntersectIterator::closedExit ( )
inlineprivate

Definition at line 87 of file qintersectiterator_p.h.

Referenced by next().

88  {
89  m_position = -1;
90  m_current = Item();
91  return Item();
92  }
The Item is the most basic of all visual items in QML.

◆ copy()

Item::Iterator::Ptr IntersectIterator::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 110 of file qintersectiterator.cpp.

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

◆ current()

Item IntersectIterator::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 100 of file qintersectiterator.cpp.

101 {
102  return m_current;
103 }

◆ next()

Item IntersectIterator::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 61 of file qintersectiterator.cpp.

62 {
63  if(!m_node1 || !m_node2)
64  return closedExit();
65 
66  do
67  {
68  if(m_node1.asNode().model() == m_node2.asNode().model())
69  {
71  {
73  {
74  m_node1 = m_it1->next();
75  break;
76  }
78  {
79  m_node2 = m_it2->next();
80  break;
81  }
82  default:
83  {
85  m_node1 = m_it1->next();
86  m_node2 = m_it2->next();
87  ++m_position;
88  return m_current;
89  }
90  }
91  }
92  else
93  m_node2 = m_it2->next();
94  }
95  while(m_node1 && m_node2);
96 
97  return Item();
98 }
DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const
Definition: qitem_p.h:481
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
const Item::Iterator::Ptr m_it2
const Item::Iterator::Ptr m_it1
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182

◆ position()

xsInteger IntersectIterator::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 105 of file qintersectiterator.cpp.

106 {
107  return m_position;
108 }

Properties

◆ m_current

Item QPatternist::IntersectIterator::m_current
private

Definition at line 96 of file qintersectiterator_p.h.

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

◆ m_it1

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

Definition at line 94 of file qintersectiterator_p.h.

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

◆ m_it2

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

Definition at line 95 of file qintersectiterator_p.h.

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

◆ m_node1

Item QPatternist::IntersectIterator::m_node1
private

Definition at line 98 of file qintersectiterator_p.h.

Referenced by next().

◆ m_node2

Item QPatternist::IntersectIterator::m_node2
private

Definition at line 99 of file qintersectiterator_p.h.

Referenced by next().

◆ m_position

xsInteger QPatternist::IntersectIterator::m_position
private

Definition at line 97 of file qintersectiterator_p.h.

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


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