Adapter class for arbitrary input iterator classes. More...
#include <Iterator.hpp>
Public Member Functions | |
IteratorAdapter () | |
Default constructor. | |
IteratorAdapter (InputIterator iterator) | |
Constructor. | |
IteratorAdapter (const IteratorAdapter< T, InputIterator > &other) | |
Copy constructor. | |
~IteratorAdapter () | |
Destructor. | |
IteratorAdapter & | operator= (const Iterator< T > &other) |
Assignment operator. | |
IteratorAdapter & | operator= (const IteratorAdapter< T, InputIterator > &other) |
Assignment operator. | |
T | operator* () const |
Dereference operator. | |
Iterator< T > & | operator++ () |
Pre-Increment operator. | |
Iterator< T > | operator++ (int) |
Post-Increment operator. | |
bool | operator== (const Iterator< T > &other) const |
Comparison operator. | |
bool | operator!= (const Iterator< T > &other) const |
Comparison operator. | |
operator typename Iterator< T >::bool_type () const | |
Returns true if the instance was initialized with an iterator. | |
bool | isValid () const |
Returns true if the instance was initialized with an iterator. | |
virtual | operator bool_type () const |
const Iterator & | getIterator () const |
Returns a reference to the internally stored IteratorAdapter. | |
Protected Types | |
typedef Iterator< T > | super |
typedef void(Iterator< T >::* | bool_type )() const |
Used in the safe bool idiom implementation. | |
Protected Member Functions | |
Iterator< T > * | clone () const |
Clones the current object (i.e. *this ). | |
unsigned long | distance (const Iterator< T > &other) const |
Returns the distance to the given iterator. | |
void | safe_bool_idiom_helper_function () const |
Used in the safe bool idiom implementation. | |
Friends | |
unsigned long | TRTK::distance (IteratorAdapter< T, InputIterator > first, IteratorAdapter< T, InputIterator > last) |
unsigned long | distance (Iterator< T > first, Iterator< T > last) |
Returns the distance between to iterators. | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T , class InputIterator > | |
unsigned long | distance (IteratorAdapter< T, InputIterator > first, IteratorAdapter< T, InputIterator > last) |
Returns the distance between to iterators. | |
template<class InputIterator > | |
Iterator< typename InputIterator::value_type > | make_iterator (InputIterator iterator) |
Creates an iterator adapter for arbitrary input iterator types. |
Adapter class for arbitrary input iterator classes.
T | Value type of the dereferenced iterator (can differ from the container element type) |
InputIterator | Type of the wrapped input iterator |
In C++ templated virtual member functions are not allowed. Thus, classes offering a generic iterator interface are not directly feasible (the STL does not offer a common base class, for instance). However, an adapter can be used to delegate the required operations to the particular iterator class.
This class adapts (wraps) an input iterator such that it has a uniformcan interface (Iterator).
The first template parameter T
denotes the type of the return value of the dereference operator of this class. It can differ from that of the wrapped input iterator. The only requirement is that the latter type can be converted to the former one. This adapter can be assigned to instances of Iterator<T>.
The second template parameter denotes the type of the input iterator to be wrapped.
make_iterator can simplify the use of this class. It automatically determines the types T
and InputIterator
from its argument, creates an instance of IteratorAdapter, and returns an instance of Iterator.
See Iterator for an example.
Definition at line 481 of file Iterator.hpp.
Iterator< T > * TRTK::IteratorAdapter< T, InputIterator >::clone | ( | ) | const [protected, virtual] |
Clones the current object (i.e. *this
).
Reimplemented from TRTK::Iterator< T >.
Definition at line 670 of file Iterator.hpp.
unsigned long TRTK::IteratorAdapter< T, InputIterator >::distance | ( | const Iterator< T > & | other ) | const [protected, virtual] |
Returns the distance to the given iterator.
The given iterator must be from the same container otherwise the behaviour is undefined.
Reimplemented from TRTK::Iterator< T >.
Definition at line 683 of file Iterator.hpp.
bool TRTK::IteratorAdapter< T, InputIterator >::isValid | ( | ) | const [virtual] |
Returns true if the instance was initialized with an iterator.
The default instantiation does not reference an iterator and thus returns false.
IteratorAdapter<double, vector<double>::iterator> it;
it.isValid(); // returns false
IteratorAdapter<double, vector<double>::iterator> it = vec.begin(); if (it) doSomething(it); // instead of using it.isValid()
Reimplemented from TRTK::Iterator< T >.
Definition at line 728 of file Iterator.hpp.
TRTK::IteratorAdapter< T, InputIterator >::operator typename Iterator< T >::bool_type | ( | ) | const |
Returns true if the instance was initialized with an iterator.
The default instantiation does not reference a valid iterator and thus returns false.
Example:
IteratorAdapter<double, vector<double>::iterator> it; if (it) doSomething(it); // instead of using it.isValid()
Definition at line 663 of file Iterator.hpp.
unsigned long distance | ( | IteratorAdapter< T, InputIterator > | first, |
IteratorAdapter< T, InputIterator > | last | ||
) | [related] |
Returns the distance between to iterators.
This function call is delegated to the distance function specifically defined for the internally stored iterator type.
Definition at line 743 of file Iterator.hpp.
unsigned long distance | ( | Iterator< T > | first, |
Iterator< T > | last | ||
) | [friend, inherited] |
Returns the distance between to iterators.
This function call is delegated to the distance function specifically defined for the internally stored iterator type.
Definition at line 421 of file Iterator.hpp.
Iterator< typename InputIterator::value_type > make_iterator | ( | InputIterator | iterator ) | [related] |
Creates an iterator adapter for arbitrary input iterator types.
This is a convenience function which avoids the need of explicitly stating the template arguments. The input iterator must provide its value type via InputIterator::value_type
. See Iterator for an example.
Definition at line 765 of file Iterator.hpp.
Documentation generated by Doxygen