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

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

#include <qabstractxmlnodemodel.h>

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

Public Functions

virtual QAbstractXmlForwardIterator< TResult >::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual TResult current () const
 Returns the current item in the sequence. More...
 
 ItemMappingIterator (const TMapper &mapper, const typename QAbstractXmlForwardIterator< TSource >::Ptr &iterator, const Context &context)
 
virtual TResult next ()
 
virtual xsInteger position () const
 Returns the current position in the sequence represented by this. More...
 
- Public Functions inherited from QAbstractXmlForwardIterator< TResult >
virtual qint64 count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
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 Context m_context
 
TResult m_current
 
const QAbstractXmlForwardIterator< TSource >::Ptr m_it
 
const TMapper m_mapper
 
xsInteger m_position
 

Related Functions

(Note that these are not member functions.)

template<typename TResult , typename TSource , typename TMapper , typename Context >
static QAbstractXmlForwardIterator< TResult >::Ptr makeItemMappingIterator (const TMapper &mapper, const QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< TSource > > &source, const Context &context)
 An object generator for ItemMappingIterator. More...
 

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, typename Context = DynamicContext::Ptr>
class QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >

Proxies another QAbstractXmlForwardIterator, and for each item, returns the Item 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.

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

TResult::Ptr mapToItem(const TSource &item,
const Context &context) const

For each item in the QAbstractXmlForwardIterator ItemMappingIterator proxies, this function is called and its return value becomes the return value of the ItemMappingIterator. If the mapping function returns null, ItemMappingIterator maps the next item in the source sequence such that a contiguous sequence of items is returned.

Declaring the mapToItem() function as inline, can be a good way to improve performance.

See also
SequenceMappingIterator
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 75 of file qabstractxmlnodemodel.h.

Constructors and Destructors

◆ ItemMappingIterator()

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::ItemMappingIterator ( const TMapper &  mapper,
const typename QAbstractXmlForwardIterator< TSource >::Ptr iterator,
const Context &  context 
)
inline

Constructs an ItemMappingIterator.

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

Definition at line 103 of file qitemmappingiterator_p.h.

105  : m_mapper(mapper)
106  , m_it(iterator)
107  , m_context(context)
108  , m_position(0)
109  {
110  Q_ASSERT(mapper);
111  Q_ASSERT(iterator);
112  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const QAbstractXmlForwardIterator< TSource >::Ptr m_it

Functions

◆ copy()

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
virtual QAbstractXmlForwardIterator<TResult>::Ptr QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::copy ( ) const
inlinevirtual

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

Definition at line 151 of file qitemmappingiterator_p.h.

152  {
154  (new ItemMappingIterator<TResult, TSource, TMapper, Context>(m_mapper, m_it->copy(), m_context));
155  }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
virtual QAbstractXmlForwardIterator< T >::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
const QAbstractXmlForwardIterator< TSource >::Ptr m_it

◆ current()

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
virtual TResult QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::current ( ) const
inlinevirtual

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 141 of file qitemmappingiterator_p.h.

142  {
143  return m_current;
144  }

◆ next()

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
virtual TResult QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::next ( )
inlinevirtual
Returns
the next item in the sequence, or null if the end have been reached.

Implements QAbstractXmlForwardIterator< TResult >.

Definition at line 118 of file qitemmappingiterator_p.h.

119  {
120  const TSource sourceItem(m_it->next());
121 
122  if(qIsForwardIteratorEnd(sourceItem))
123  {
124  m_current = TResult();
125  m_position = -1;
126  return TResult();
127  }
128  else
129  {
130  m_current = m_mapper->mapToItem(sourceItem, m_context);
132  return next(); /* The mapper returned null, so continue with the next in the source. */
133  else
134  {
135  ++m_position;
136  return m_current;
137  }
138  }
139  }
bool qIsForwardIteratorEnd(const TResult &unit)
The Callback QAbstractXmlForwardIterator uses for determining whether unit is the end of a sequence...
const QAbstractXmlForwardIterator< TSource >::Ptr m_it
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 , typename Context = DynamicContext::Ptr>
virtual xsInteger QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::position ( ) const
inlinevirtual

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 146 of file qitemmappingiterator_p.h.

147  {
148  return m_position;
149  }

Friends and Related Functions

◆ makeItemMappingIterator()

template<typename TResult , typename TSource , typename TMapper , typename Context >
static QAbstractXmlForwardIterator< TResult >::Ptr makeItemMappingIterator ( const TMapper &  mapper,
const QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< TSource > > &  source,
const Context &  context 
)
related

An object generator for ItemMappingIterator.

makeItemMappingIterator() is a convenience function for avoiding specifying the full template instantiation for ItemMappingIterator. Conceptually, it is identical to Qt's qMakePair().

Definition at line 177 of file qitemmappingiterator_p.h.

180  {
182  (new ItemMappingIterator<TResult, TSource, TMapper, Context>(mapper, source, context));
183  }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.

Properties

◆ m_context

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
const Context QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::m_context
private

◆ m_current

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
TResult QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::m_current
private

◆ m_it

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
const QAbstractXmlForwardIterator<TSource>::Ptr QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::m_it
private

◆ m_mapper

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
const TMapper QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::m_mapper
private

◆ m_position

template<typename TResult , typename TSource , typename TMapper , typename Context = DynamicContext::Ptr>
xsInteger QPatternist::ItemMappingIterator< TResult, TSource, TMapper, Context >::m_position
private

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