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

An unfiltered RangeIterator with a custom dereferencer. More...

#include <utils.h>

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

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

Public Member Functions

 DereferencingRangeIterator (Iter start, Iter end)
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 TDereferenceFun = DefaultDeref<IterType, Iter>>
class itunesdb::utils::DereferencingRangeIterator< IterType, Iter, TDereferenceFun >

An unfiltered RangeIterator with a custom dereferencer.

Use this method if you don't want to return just *iter in your next() method. This is useful if you want to iterate over the keys of a map where you'd return iter->first in that case. The key dereferencer for a std::map with a key type of QString would look something like this:


    struct KeyDereferencer {
        const QString& operator() ( std::map<QString,whatever>::const_iterator& iter ) const {
            return (*iter).first;
        }
    };
 
A KeyIterator would then look something loke this:

    typedef itunesdb::utils::DereferencingRangeIterator<QString,std::map<QString,whatever>::const_iterator, KeyDereferencer> KeyIterator;
 
and its instantiation

    KeyIterator keyIter( map.begin(), map.end() );
 
To print out the keys of the map we use the keyIter above like this

    while( keyIter.hasNext() ) {
        printf( "%s\n", keyIter.next().ascii() );
    }
 


Constructor & Destructor Documentation

template<typename IterType, typename Iter, typename TDereferenceFun = DefaultDeref<IterType, Iter>>
itunesdb::utils::DereferencingRangeIterator< IterType, Iter, TDereferenceFun >::DereferencingRangeIterator ( Iter  start,
Iter  end 
) [inline]

Creates a DereferencingRangeIterator over the given range.


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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

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, inherited]

Internal implementors of the underlying functions


The documentation for this class was generated from the following file:
Generated on Wed Nov 28 03:04:38 2007 for libqtpod by  doxygen 1.5.0