DGtal 1.3.0
|
Aim: Class that uses CRTP to add reverse iterators and ranges to a derived class. More...
#include <DGtal/base/IteratorCompletion.h>
Public Types | |
typedef IteratorCompletionTraits< TDerived >::Iterator | Iterator |
Mutable iterator type. More... | |
typedef IteratorCompletionTraits< TDerived >::ConstIterator | ConstIterator |
Constant iterator type. More... | |
typedef IteratorCompletionTraits< TDerived >::DistanceFunctor | DistanceFunctor |
Type of the functor calculating the distance between iterators. More... | |
typedef boost::reverse_iterator< Iterator > | ReverseIterator |
Mutable reverse iterator type. More... | |
typedef boost::reverse_iterator< ConstIterator > | ConstReverseIterator |
Constant reverse iterator type. More... | |
typedef SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctor > | Range |
Mutable range type. More... | |
typedef SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctor > | ConstRange |
Constant range type. More... | |
typedef std::ptrdiff_t | Difference |
Type of the distance between two iterators. More... | |
Public Member Functions | |
ReverseIterator | rbegin () |
ConstReverseIterator | rbegin () const |
ConstReverseIterator | crbegin () const |
ReverseIterator | rend () |
ConstReverseIterator | rend () const |
ConstReverseIterator | crend () const |
Range | range () |
ConstRange | constRange () const |
Protected Member Functions | |
~IteratorCompletion () | |
Protected destructor to avoid memory leak. More... | |
Aim: Class that uses CRTP to add reverse iterators and ranges to a derived class.
Description of template class 'IteratorCompletionTraits'
This class adds new iterators to a given class if it provides a minimal interface for random-access iterators related to points.
More precisely, it provides:
Each derived class of IteratorCompletion must specialize IteratorCompletionTraits in order to provide enough informations on his iterators, especially a distance functor between a given point and the begin iterator.
TDerived | Type of the derived class (CRTP). |
The following snippets illustrate how to use it to easily build a concepts::CImage model from a C-style array (better use ArrayImageAdapter for that purpose).
After common includes:
we start with the head of our class, including typedefs, constructor and destructor:
As you can see, the MyImage class inherits from IteratorCompletion templated with his own type (CRTP). The public inheritance is necessary is order to make visible the methods and typedefs provided by IteratorCompletion.
Then, we add the basic interface needed for images:
and the minimal iterator accessors:
The class is finally closed with the private members:
A specialization of IteratorCompletionTraits is needed in order to provide IteratorCompletion with the Iterator and ConstIterator type, and a DistanceFunctor that returns the distance from the begin iterator to a given point (see SimpleRandomAccessRangeFromPoint and SimpleRandomAccessConstRangeFromPoint):
We have now a concepts::CImage model that can be used like any image:
Definition at line 116 of file IteratorCompletion.h.
typedef IteratorCompletionTraits<TDerived>::ConstIterator DGtal::IteratorCompletion< TDerived >::ConstIterator |
Constant iterator type.
Definition at line 121 of file IteratorCompletion.h.
typedef SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctor > DGtal::IteratorCompletion< TDerived >::ConstRange |
Constant range type.
Definition at line 127 of file IteratorCompletion.h.
typedef boost::reverse_iterator<ConstIterator> DGtal::IteratorCompletion< TDerived >::ConstReverseIterator |
Constant reverse iterator type.
Definition at line 125 of file IteratorCompletion.h.
typedef std::ptrdiff_t DGtal::IteratorCompletion< TDerived >::Difference |
Type of the distance between two iterators.
Definition at line 128 of file IteratorCompletion.h.
typedef IteratorCompletionTraits<TDerived>::DistanceFunctor DGtal::IteratorCompletion< TDerived >::DistanceFunctor |
Type of the functor calculating the distance between iterators.
Definition at line 122 of file IteratorCompletion.h.
typedef IteratorCompletionTraits<TDerived>::Iterator DGtal::IteratorCompletion< TDerived >::Iterator |
Mutable iterator type.
Definition at line 120 of file IteratorCompletion.h.
typedef SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctor > DGtal::IteratorCompletion< TDerived >::Range |
Mutable range type.
Definition at line 126 of file IteratorCompletion.h.
typedef boost::reverse_iterator<Iterator> DGtal::IteratorCompletion< TDerived >::ReverseIterator |
Mutable reverse iterator type.
Definition at line 124 of file IteratorCompletion.h.
|
inlineprotected |
Protected destructor to avoid memory leak.
Definition at line 224 of file IteratorCompletion.h.
|
inline |
Definition at line 211 of file IteratorCompletion.h.
|
inline |
Definition at line 154 of file IteratorCompletion.h.
|
inline |
Definition at line 184 of file IteratorCompletion.h.
|
inline |
Definition at line 195 of file IteratorCompletion.h.
|
inline |
Definition at line 134 of file IteratorCompletion.h.
|
inline |
Definition at line 144 of file IteratorCompletion.h.
|
inline |
Definition at line 164 of file IteratorCompletion.h.
|
inline |
Definition at line 174 of file IteratorCompletion.h.