Qt 4.8
Public Functions | Properties | List of all members
QPatternist::SequenceMappingIterator< TResult, TSource, TMapper > Class Template Reference

Proxies another QAbstractXmlForwardIterator, and for each item, returns the Sequence returned from a mapping function. More...

#include <qabstractxmlnodemodel.h>

Inheritance diagram for QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >:
QAbstractXmlForwardIterator< TResult > QSharedData

Public Functions

virtual QAbstractXmlForwardIterator< TResult >::Ptr copy () const
 
virtual xsInteger count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
virtual TResult current () const
 Returns the current item in the sequence. More...
 
virtual TResult 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...
 
 SequenceMappingIterator (const TMapper &mapper, const typename QAbstractXmlForwardIterator< TSource >::Ptr &sourceIterator, const DynamicContext::Ptr &context)
 
- Public Functions inherited from QAbstractXmlForwardIterator< TResult >
virtual bool isEmpty ()
 Returns true if the sequence is empty. More...
 
virtual TResult 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< TResult > toList ()
 Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList. More...
 
virtual QAbstractXmlForwardIterator< TResult >::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

const DynamicContext::Ptr m_context
 
TResult m_current
 
QAbstractXmlForwardIterator< TResult >::Ptr m_currentIterator
 
QAbstractXmlForwardIterator< TSource >::Ptr m_mainIterator
 
const TMapper m_mapper
 
xsInteger m_position
 

Additional Inherited Members

- Public Types inherited from QAbstractXmlForwardIterator< TResult >
typedef QList< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< TResult > > > List
 A QList containing QAbstractXmlForwardIterator::Ptr instances. More...
 
typedef QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< TResult > > Ptr
 A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass. More...
 
typedef QVector< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< TResult > > > Vector
 A QVector containing QAbstractXmlForwardIterator::Ptr instances. More...
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

template<typename TResult, typename TSource, typename TMapper>
class QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >

Proxies another QAbstractXmlForwardIterator, and for each item, returns the Sequence returned from a mapping function.

ItemMappingIterator is practical when the items in an QAbstractXmlForwardIterator needs to be translated to another sequence, while still doing it in a pipe-lined fashion. In contrast to ItemMappingIterator, SequenceMappingIterator maps each item into another QAbstractXmlForwardIterator, and where the SequenceMappingIterator's own result is the concatenation of all those Iterators. Hence, while ItemMappingIterator is better tailored for one-to-one or one-to-zero conversion, SequenceMappingIterator is more suitable for one-to-many conversion.

This is achieved by that SequenceMappingIterator's constructor takes an instance of a class, that must have the following member:

QAbstractXmlForwardIterator<TResult>::Ptr mapToSequence(const TSource::Ptr &item,
const DynamicContext::Ptr &context) const;
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com
See also
ItemMappingIterator

Definition at line 76 of file qabstractxmlnodemodel.h.

Constructors and Destructors

◆ SequenceMappingIterator()

template<typename TResult , typename TSource , typename TMapper >
QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::SequenceMappingIterator ( const TMapper &  mapper,
const typename QAbstractXmlForwardIterator< TSource >::Ptr sourceIterator,
const DynamicContext::Ptr context 
)

Constructs a SequenceMappingIterator.

Parameters
mapperthe object that has the mapToItem() sequence.
sourceIteratorthe QAbstractXmlForwardIterator whose items should be mapped.
contextthe DynamicContext that will be passed to the map function. May be null.

Definition at line 131 of file qsequencemappingiterator_p.h.

135  : m_position(0),
136  m_mainIterator(iterator),
137  m_context(context),
138  m_mapper(mapper)
139  {
140  Q_ASSERT(mapper);
141  Q_ASSERT(iterator);
142  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QAbstractXmlForwardIterator< TSource >::Ptr m_mainIterator

Functions

◆ copy()

template<typename TResult , typename TSource , typename TMapper >
virtual QAbstractXmlForwardIterator<TResult>::Ptr QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::copy ( ) const
inlinevirtual

The reason the implementation is placed in line here, is due to a bug in MSVC-2005 version 14.00.50727.762. Note that it works with version 14.00.50727.42.

Reimplemented from QAbstractXmlForwardIterator< TResult >.

Definition at line 113 of file qsequencemappingiterator_p.h.

114  {
116  (new SequenceMappingIterator<TResult, TSource, TMapper>(m_mapper,
117  m_mainIterator->copy(),
118  m_context));
119  }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
QAbstractXmlForwardIterator< TSource >::Ptr m_mainIterator
virtual QAbstractXmlForwardIterator< T >::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.

◆ count()

template<typename TResult , typename TSource , typename TMapper >
xsInteger QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::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< TResult >.

Definition at line 181 of file qsequencemappingiterator_p.h.

182  {
183  TSource unit(m_mainIterator->next());
184  xsInteger c = 0;
185 
186  while(!qIsForwardIteratorEnd(unit))
187  {
188  const typename QAbstractXmlForwardIterator<TResult>::Ptr sit(m_mapper->mapToSequence(unit, m_context));
189  c += sit->count();
190  unit = m_mainIterator->next();
191  }
192 
193  return c;
194  }
unsigned char c[8]
Definition: qnumeric_p.h:62
qint64 xsInteger
QAbstractXmlForwardIterator< TSource >::Ptr m_mainIterator
The QAbstractXmlForwardIterator class is a base class for forward iterators.
virtual qint64 count()
Determines the number of items this QAbstractXmlForwardIterator represents.
bool qIsForwardIteratorEnd(const TResult &unit)
The Callback QAbstractXmlForwardIterator uses for determining whether unit is the end of a sequence...
virtual T next()=0
Returns the next item in the sequence, or a null object if the end has been reached.

◆ current()

template<typename TResult , typename TSource , typename TMapper >
TResult QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::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< TResult >.

Definition at line 197 of file qsequencemappingiterator_p.h.

198  {
199  return m_current;
200  }

◆ next()

template<typename TResult , typename TSource , typename TMapper >
TResult QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::next ( )
virtual

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

Implements QAbstractXmlForwardIterator< TResult >.

Definition at line 145 of file qsequencemappingiterator_p.h.

146  {
147  /* This was once implemented with a recursive function, but the stack
148  * got blown for some inputs by that approach. */
149  while(true)
150  {
151  while(!m_currentIterator)
152  {
153  const TSource mainItem(m_mainIterator->next());
154 
155  if(qIsForwardIteratorEnd(mainItem)) /* We've reached the very end. */
156  {
157  m_position = -1;
158  m_current = TResult();
159  return TResult();
160  }
161  else
162  m_currentIterator = m_mapper->mapToSequence(mainItem, m_context);
163  }
164 
166 
168  {
169  m_currentIterator.reset();
170  continue;
171  }
172  else
173  {
174  ++m_position;
175  return m_current;
176  }
177  }
178  }
QAbstractXmlForwardIterator< TResult >::Ptr m_currentIterator
QAbstractXmlForwardIterator< TSource >::Ptr m_mainIterator
bool qIsForwardIteratorEnd(const TResult &unit)
The Callback QAbstractXmlForwardIterator uses for determining whether unit is the end of a sequence...
virtual T next()=0
Returns the next item in the sequence, or a null object if the end has been reached.

◆ position()

template<typename TResult , typename TSource , typename TMapper >
xsInteger QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::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< TResult >.

Definition at line 203 of file qsequencemappingiterator_p.h.

204  {
205  return m_position;
206  }

Properties

◆ m_context

template<typename TResult , typename TSource , typename TMapper >
const DynamicContext::Ptr QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::m_context
private

◆ m_current

template<typename TResult , typename TSource , typename TMapper >
TResult QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::m_current
private

◆ m_currentIterator

template<typename TResult , typename TSource , typename TMapper >
QAbstractXmlForwardIterator<TResult>::Ptr QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::m_currentIterator
private

◆ m_mainIterator

template<typename TResult , typename TSource , typename TMapper >
QAbstractXmlForwardIterator<TSource>::Ptr QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::m_mainIterator
private

◆ m_mapper

template<typename TResult , typename TSource , typename TMapper >
const TMapper QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::m_mapper
private

◆ m_position

template<typename TResult , typename TSource , typename TMapper >
xsInteger QPatternist::SequenceMappingIterator< TResult, TSource, TMapper >::m_position
private

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