itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun > Class Template Reference

An Iterator over a range of elements (in most cases backed by some container). More...

#include <utils.h>

Inheritance diagram for itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >:

itunesdb::utils::DereferencingRangeIterator< IterType, Iter, TDereferenceFun > List of all members.

Public Member Functions

 RangeIterator (Iter start, Iter end, const TUnaryPredicate &predicate=TUnaryPredicate(), TDereferenceFun deref=TDereferenceFun())
 Constructs a new Iterator from start to end with the given predicate.
bool hasNext () const
 Returns true if there are elements left so calling next() would return the next element rather than causing a segfault.
IterType next ()
 Returns the next element of the range of elements we iterate over.
IterType current () const
 Returns the element returned by the last next() call.
unsigned int remaining () const
 Returns the number of elements remaining in this iterator.
IterType last () const
 Returns the last element this iterator would return.

Protected Member Functions

void setRange (Iter pos, Iter end)
 Sets the range to the given iterators.
Iter currentPos ()
 Returns the iterator pointing to the element returned by the last next() call.
bool empty () const
 Returns true if there are no elements left to be iterated over.

Protected Attributes

TDereferenceFun m_dereferenceFun
RangeIteratorFunctions< IterType,
Iter, TUnaryPredicate, TDereferenceFun > 
m_helper

Detailed Description

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
class itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >

An Iterator over a range of elements (in most cases backed by some container).

The RangeIterator can be used to iterate over a collection of elements using its hasNext() and next() methods. For example to iterate over all the Tracks of a itunesdb::TrackPtrList :


    itunesdb::TrackPtrList::Iterator trackIter = tlist.iterator();
    while( trackIter.hasNext() ) {
        itunesdb::Track * track = trackIter.next();
        ... some code ...
    }
 
The TUnaryPredicate decides if an element is part of the range and therefore should be taken into account by hasNext() and next() or not. The Dereference Function dereferences an iterator and returns IterType. That's helpful if you need to create an iterator over the keys of a map without being too obvious about your implementation details.
See also:
DereferencingRangeIterator for an example dereferencing the keys of a map.
Author:
Michael Schulze


Constructor & Destructor Documentation

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::RangeIterator ( Iter  start,
Iter  end,
const TUnaryPredicate &  predicate = TUnaryPredicate(),
TDereferenceFun  deref = TDereferenceFun() 
) [inline]

Constructs a new Iterator from start to end with the given predicate.


Member Function Documentation

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
void itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::setRange ( Iter  pos,
Iter  end 
) [inline, protected]

Sets the range to the given iterators.

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
Iter itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::currentPos (  )  [inline, protected]

Returns the iterator pointing to the element returned by the last next() call.

Returns:
the iterator pointing to the element returned by the last next() call

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
bool itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::empty (  )  const [inline, protected]

Returns true if there are no elements left to be iterated over.

Returns:
true if there are no elements left to be iterated over

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
bool itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::hasNext (  )  const [inline]

Returns true if there are elements left so calling next() would return the next element rather than causing a segfault.

Returns:
true if there are elements left

Reimplemented in itunesdb::utils::SortablePtrVector< ElemType >::ContainerVersionAwareIterator< Container_T, Iter_T, TUnaryPredicate >, itunesdb::utils::SortablePtrVector< ElemType >::ContainerVersionAwareIterator< itunesdb::utils::SortablePtrVector< ElemType >, std::vector< ElemType * >::iterator, TUnaryPredicate >, itunesdb::utils::SortablePtrVector< ElemType >::ContainerVersionAwareIterator< itunesdb::utils::SortablePtrVector< ElemType >, std::vector< ElemType * >::const_iterator, TrackPredicate_T >, and itunesdb::utils::SortablePtrVector< ElemType >::ContainerVersionAwareIterator< itunesdb::utils::SortablePtrVector< ElemType >, std::vector< ElemType * >::const_iterator, TUnaryPredicate >.

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
IterType itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::next (  )  [inline]

Returns the next element of the range of elements we iterate over.

This method positions the Iterator at the next element and returns it. The first call to this method will return the first element of the range.
If the iterator is filtered only those elements where the given predicate returned true are returned.

Attention:
Always check if hasNext() returns true before calling next. Calling next() on an iterator already at the end of the range will cause a segfault.
Precondition:
hasNext() returns true
Postcondition:
a successive call to current() returns the element returned by this method

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
IterType itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::current (  )  const [inline]

Returns the element returned by the last next() call.

Returns:
the element returned by the last next() call

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
unsigned int itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::remaining (  )  const [inline]

Returns the number of elements remaining in this iterator.

... meaning the number of times the next() method can be called before the hasNext() method willreturn false. For filtered iterators this may be a lengthy operation since the iterator needs to apply its filter over all elements to determine how many elements are left.

Returns:
the number of elements left

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
IterType itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::last (  )  const [inline]

Returns the last element this iterator would return.

This method is dangerous and makes no sense. Do not call this for empty iterators so at least check with hasNext() before.

Returns:
the last element this iterator would return
Precondition:
it must have been ensured that the iterator is nonempty


Member Data Documentation

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
TDereferenceFun itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::m_dereferenceFun [protected]

Dereferencer to dereference an iterator to IterType

template<typename IterType, typename Iter, typename TUnaryPredicate = TRUEPredicate, typename TDereferenceFun = DefaultDeref< IterType, Iter >>
RangeIteratorFunctions<IterType, Iter, TUnaryPredicate, TDereferenceFun> itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::m_helper [protected]

Internal implementors of the underlying functions


The documentation for this class was generated from the following file:
Generated on Wed Dec 19 00:15:20 2007 for libqtpod by  doxygen 1.5.0