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

Filters another sequence by removing duplicates such that the items are unique. More...

#include <qdistinctiterator_p.h>

Inheritance diagram for QPatternist::DistinctIterator:
QAbstractXmlForwardIterator< T > QPatternist::ComparisonPlatform< DistinctIterator, false > QPatternist::SourceLocationReflection QSharedData

Public Functions

virtual const SourceLocationReflectionactualReflection () const
 
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...
 
 DistinctIterator (const Item::Iterator::Ptr &seq, const AtomicComparator::Ptr &comp, const Expression::ConstPtr &expression, const DynamicContext::Ptr &context)
 
virtual Item next ()
 Returns the next item in the sequence, or a null object if the end has been reached. More...
 
AtomicComparator::Operator operatorID () const
 
virtual xsInteger position () const
 Returns the current position in the sequence represented by this. More...
 
- 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...
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QString description () const
 
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Properties

const DynamicContext::Ptr m_context
 
Item m_current
 
const Expression::ConstPtr m_expr
 
xsInteger m_position
 
Item::List m_processed
 
const Item::Iterator::Ptr m_seq
 

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
 
- Protected Functions inherited from QPatternist::ComparisonPlatform< DistinctIterator, false >
const AtomicComparator::Ptrcomparator () const
 
bool compare (const Item &i1, const Item &i2, const AtomicComparator::Ptr &comp, const AtomicComparator::Operator op) const
 Compares i1 and i2 with operator op, using comparator comp. All input arguments must be valid, and not null. More...
 
 ComparisonPlatform ()
 
AtomicComparator::ComparisonResult detailedFlexibleCompare (const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
 like flexibleCompare(), but returns the result as an AtomicComparator::Operator instead of bool. More...
 
AtomicComparator::Ptr fetchComparator (const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
 
bool flexibleCompare (const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
 Compares it1 against it2, using comparator() and operatorID(). More...
 
void prepareComparison (const AtomicComparator::Ptr &comparator)
 
void useCaseInsensitiveComparator ()
 

Detailed Description

Filters another sequence by removing duplicates such that the items are unique.

DistinctIterator takes an input sequence, and returns a sequence where each item is unique. Thus, DistinctIterator removes the duplicates of items in a sequence. DistinctIterator is central in the implementation of the fn:distinct-values() function.

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

Definition at line 83 of file qdistinctiterator_p.h.

Constructors and Destructors

◆ DistinctIterator()

DistinctIterator::DistinctIterator ( const Item::Iterator::Ptr seq,
const AtomicComparator::Ptr comp,
const Expression::ConstPtr expression,
const DynamicContext::Ptr context 
)

Creates a DistinctIterator.

Parameters
compthe AtomicComparator to be used for comparing values. This may be null, meaning the IndexOfIterator iterator will dynamically determine what comparator to use
seqthe sequence whose duplicates should be filtered out
contextthe usual context, used for error reporting and by AtomicComparators.
expressionthe Expression that this DistinctIterator is evaluating for. It is used for error reporting, via actualReflection().

Definition at line 49 of file qdistinctiterator.cpp.

Referenced by copy().

53  : m_seq(seq)
54  , m_context(context)
55  , m_expr(expression)
56  , m_position(0)
57 {
58  Q_ASSERT(seq);
59  prepareComparison(comp);
60 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const Expression::ConstPtr m_expr
const DynamicContext::Ptr m_context
const Item::Iterator::Ptr m_seq
void prepareComparison(const AtomicComparator::Ptr &comparator)

Functions

◆ actualReflection()

const SourceLocationReflection * DistinctIterator::actualReflection ( ) const
virtual

Implements QPatternist::SourceLocationReflection.

Definition at line 107 of file qdistinctiterator.cpp.

108 {
109  return m_expr.data();
110 }
const Expression::ConstPtr m_expr
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145

◆ copy()

Item::Iterator::Ptr DistinctIterator::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 102 of file qdistinctiterator.cpp.

103 {
105 }
const Expression::ConstPtr m_expr
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
const DynamicContext::Ptr m_context
const Item::Iterator::Ptr m_seq
DistinctIterator(const Item::Iterator::Ptr &seq, const AtomicComparator::Ptr &comp, const Expression::ConstPtr &expression, const DynamicContext::Ptr &context)

◆ current()

Item DistinctIterator::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 92 of file qdistinctiterator.cpp.

93 {
94  return m_current;
95 }

◆ next()

Item DistinctIterator::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 62 of file qdistinctiterator.cpp.

63 {
64  if(m_position == -1)
65  return Item();
66 
67  const Item nitem(m_seq->next());
68  if(!nitem)
69  {
70  m_position = -1;
71  m_current.reset();
72  return Item();
73  }
74 
77 
78  for(; it != end; ++it)
79  {
80  if(flexibleCompare(*it, nitem, m_context))
81  {
82  return next();
83  }
84  }
85 
86  m_current = nitem;
87  ++m_position;
88  m_processed.append(nitem);
89  return nitem;
90 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const DynamicContext::Ptr m_context
virtual Item next()
Returns the next item in the sequence, or a null object if the end has been reached.
const Item::Iterator::Ptr m_seq
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool flexibleCompare(const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
Compares it1 against it2, using comparator() and operatorID().
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ operatorID()

AtomicComparator::Operator QPatternist::DistinctIterator::operatorID ( ) const
inline

◆ position()

xsInteger DistinctIterator::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 97 of file qdistinctiterator.cpp.

98 {
99  return m_position;
100 }

Properties

◆ m_context

const DynamicContext::Ptr QPatternist::DistinctIterator::m_context
private

Definition at line 116 of file qdistinctiterator_p.h.

Referenced by copy(), and next().

◆ m_current

Item QPatternist::DistinctIterator::m_current
private

Definition at line 118 of file qdistinctiterator_p.h.

Referenced by current(), and next().

◆ m_expr

const Expression::ConstPtr QPatternist::DistinctIterator::m_expr
private

Definition at line 117 of file qdistinctiterator_p.h.

Referenced by actualReflection(), and copy().

◆ m_position

xsInteger QPatternist::DistinctIterator::m_position
private

Definition at line 119 of file qdistinctiterator_p.h.

Referenced by next(), and position().

◆ m_processed

Item::List QPatternist::DistinctIterator::m_processed
private

Definition at line 120 of file qdistinctiterator_p.h.

Referenced by next().

◆ m_seq

const Item::Iterator::Ptr QPatternist::DistinctIterator::m_seq
private

Definition at line 115 of file qdistinctiterator_p.h.

Referenced by copy(), and next().


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