Qt 4.8
Public Functions | Properties | Related Functions | List of all members
QPatternist::SingletonIterator< T > Class Template Reference

An QAbstractXmlForwardIterator over exactly one item. More...

#include <qsingletoniterator_p.h>

Inheritance diagram for QPatternist::SingletonIterator< T >:
QAbstractXmlForwardIterator< T > QSharedData

Public Functions

virtual QAbstractXmlForwardIterator< T >::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual xsInteger count ()
 
virtual T current () const
 Returns the current item in the sequence. More...
 
virtual T 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...
 
 SingletonIterator (const T &item)
 
virtual QAbstractXmlForwardIterator< T >::Ptr toReversed ()
 
- Public Functions inherited from QAbstractXmlForwardIterator< T >
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 ()
 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 T m_item
 
qint8 m_position
 

Related Functions

(Note that these are not member functions.)

template<typename T >
SingletonIterator< T >::Ptr makeSingletonIterator (const T &item)
 An object generator for SingletonIterator. More...
 

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

template<typename T>
class QPatternist::SingletonIterator< T >

An QAbstractXmlForwardIterator over exactly one item.

SingletonIterator's constructor takes one value which is the item it forms an QAbstractXmlForwardIterator over. Other QAbstractXmlForwardIterator instances can also form an QAbstractXmlForwardIterator with one in length, but by that SingletonIterator has this as it only task, it means it is efficient at it.

Having to represent single items in Iterators is relatively common.

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

Definition at line 79 of file qsingletoniterator_p.h.

Constructors and Destructors

◆ SingletonIterator()

template<typename T >
QPatternist::SingletonIterator< T >::SingletonIterator ( const T &  item)
inline

Creates an iterator over item.

Note
item may not be null. Use the EmptyIterator for the empty sequence

Definition at line 88 of file qsingletoniterator_p.h.

Referenced by QPatternist::SingletonIterator< T >::copy().

88  : m_item(item),
89  m_position(0)
90  {
92  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool qIsForwardIteratorEnd(const T &unit)
The Callback QAbstractXmlForwardIterator uses for determining whether unit is the end of a sequence...

Functions

◆ copy()

template<typename T >
virtual QAbstractXmlForwardIterator<T>::Ptr QPatternist::SingletonIterator< T >::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< T >.

Definition at line 145 of file qsingletoniterator_p.h.

146  {
148  }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.

◆ count()

template<typename T >
virtual xsInteger QPatternist::SingletonIterator< T >::count ( )
inlinevirtual
Returns
always 1

Reimplemented from QAbstractXmlForwardIterator< T >.

Definition at line 140 of file qsingletoniterator_p.h.

141  {
142  return 1;
143  }

◆ current()

template<typename T >
virtual T QPatternist::SingletonIterator< T >::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< T >.

Definition at line 116 of file qsingletoniterator_p.h.

117  {
118  if(m_position == 1)
119  return m_item;
120  else
121  return T();
122  }

◆ next()

template<typename T >
virtual T QPatternist::SingletonIterator< T >::next ( )
inlinevirtual

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

Implements QAbstractXmlForwardIterator< T >.

Definition at line 94 of file qsingletoniterator_p.h.

95  {
96  switch(m_position)
97  {
98  case 0:
99  {
100  ++m_position;
101  return m_item;
102  }
103  case 1:
104  {
105  m_position = -1;
106  return T();
107  }
108  default:
109  {
110  Q_ASSERT(m_position == -1);
111  return T();
112  }
113  }
114  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ position()

template<typename T >
virtual xsInteger QPatternist::SingletonIterator< T >::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< T >.

Definition at line 124 of file qsingletoniterator_p.h.

125  {
126  return m_position;
127  }

◆ toReversed()

template<typename T >
virtual QAbstractXmlForwardIterator<T>::Ptr QPatternist::SingletonIterator< T >::toReversed ( )
inlinevirtual
Returns
a copy of this instance, rewinded to the beginning.

Reimplemented from QAbstractXmlForwardIterator< T >.

Definition at line 132 of file qsingletoniterator_p.h.

133  {
134  return typename QAbstractXmlForwardIterator<T>::Ptr(new SingletonIterator<T>(m_item));
135  }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.

Friends and Related Functions

◆ makeSingletonIterator()

template<typename T >
SingletonIterator< T >::Ptr makeSingletonIterator ( const T &  item)
related

An object generator for SingletonIterator.

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

Definition at line 167 of file qsingletoniterator_p.h.

168  {
169  return typename SingletonIterator<T>::Ptr(new SingletonIterator<T>(item));
170  }
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.

Properties

◆ m_item

template<typename T >
const T QPatternist::SingletonIterator< T >::m_item
private

◆ m_position

template<typename T >
qint8 QPatternist::SingletonIterator< T >::m_position
private

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