#include <utils.h>
Inheritance diagram for itunesdb::utils::DereferencingRangeIterator< IterType, Iter, TDereferenceFun >:
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 |
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() );
}
itunesdb::utils::DereferencingRangeIterator< IterType, Iter, TDereferenceFun >::DereferencingRangeIterator | ( | Iter | start, | |
Iter | end | |||
) | [inline] |
Creates a DereferencingRangeIterator over the given range.
void itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::setRange | ( | Iter | pos, | |
Iter | end | |||
) | [inline, protected, inherited] |
Sets the range to the given iterators.
Iter itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::currentPos | ( | ) | [inline, protected, inherited] |
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.
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.
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, 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.
IterType itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::current | ( | ) | const [inline, inherited] |
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.
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.
TDereferenceFun itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::m_dereferenceFun [protected, inherited] |
Dereferencer to dereference an iterator to IterType
RangeIteratorFunctions<IterType, Iter, TUnaryPredicate, TDereferenceFun> itunesdb::utils::RangeIterator< IterType, Iter, TUnaryPredicate, TDereferenceFun >::m_helper [protected, inherited] |
Internal implementors of the underlying functions