#include <utils.h>
Inheritance diagram for itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >:
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 |
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.
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.
void itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::setRange | ( | Iter | pos, | |
Iter | end | |||
) | [inline, protected] |
Sets the range to the given iterators.
Iter itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::currentPos | ( | ) | [inline, protected] |
bool itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::empty | ( | ) | const [inline, protected] |
Returns true if there are no elements left to be iterated over.
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.
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 >.
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.
IterType itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::current | ( | ) | const [inline] |
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.
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.
TDereferenceFun itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::m_dereferenceFun [protected] |
Dereferencer to dereference an iterator to IterType
RangeIteratorFunctions<IterType, Iter, TUnaryPredicate, TDereferenceFun> itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::m_helper [protected] |
Internal implementors of the underlying functions