Public Member Functions | Protected Types | Protected Member Functions | Friends | Related Functions

TRTK::IteratorAdapter< T, InputIterator > Class Template Reference

Adapter class for arbitrary input iterator classes. More...

#include <Iterator.hpp>

Inheritance diagram for TRTK::IteratorAdapter< T, InputIterator >:
Collaboration diagram for TRTK::IteratorAdapter< T, InputIterator >:

List of all members.

Public Member Functions

 IteratorAdapter ()
 Default constructor.
 IteratorAdapter (InputIterator iterator)
 Constructor.
 IteratorAdapter (const IteratorAdapter< T, InputIterator > &other)
 Copy constructor.
 ~IteratorAdapter ()
 Destructor.
IteratorAdapteroperator= (const Iterator< T > &other)
 Assignment operator.
IteratorAdapteroperator= (const IteratorAdapter< T, InputIterator > &other)
 Assignment operator.
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 IteratorgetIterator () 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.

Detailed Description

template<class T, class InputIterator>
class TRTK::IteratorAdapter< T, InputIterator >

Adapter class for arbitrary input iterator classes.

Template Parameters:
TValue type of the dereferenced iterator (can differ from the container element type)
InputIteratorType 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.

Note:

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.

See also:
Iterator, make_iterator
Author:
Christoph Haenisch
Version:
0.4.0
Date:
last changed on 2019-06-24

Definition at line 481 of file Iterator.hpp.


Member Function Documentation

template<class T , class InputIterator >
Iterator< T > * TRTK::IteratorAdapter< T, InputIterator >::clone (  ) const [protected, virtual]

Clones the current object (i.e. *this).

Returns:
Returns a clone of the wrapped iterator created on the heap.

Reimplemented from TRTK::Iterator< T >.

Definition at line 670 of file Iterator.hpp.

template<class T , class InputIterator >
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.

template<class T , class InputIterator >
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
Note:
For convenience IteratorAdapter also provides a boolean conversion operator that allows you to write code like this:
       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.

template<class T , class InputIterator >
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.


Friends And Related Function Documentation

template<class T , class InputIterator >
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.

template<class T>
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.

template<class InputIterator >
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.

Returns:
Returns an instance of the Iterator<T> base class.
See also:
Iterator, IteratorAdapter

Definition at line 765 of file Iterator.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines