DGtal  0.9.2
IteratorCompletion.h
1 
17 #pragma once
18 
29 #if defined(IteratorCompletion_RECURSES)
30 #error Recursive header files inclusion detected in IteratorCompletion.h
31 #else // defined(IteratorCompletion_RECURSES)
32 
33 #define IteratorCompletion_RECURSES
34 
35 #if !defined IteratorCompletion_h
36 
37 #define IteratorCompletion_h
38 
40 // Inclusions
41 #include <boost/iterator/reverse_iterator.hpp>
42 #include <DGtal/base/SimpleRandomAccessRangeFromPoint.h>
43 #include <DGtal/base/SimpleRandomAccessConstRangeFromPoint.h>
45 
46 namespace DGtal
47 {
48 
50 
65  template < typename TDerived >
67 
113  template <
114  typename TDerived
115  >
117  {
118  public:
119 
123 
124  typedef boost::reverse_iterator<Iterator> ReverseIterator;
125  typedef boost::reverse_iterator<ConstIterator> ConstReverseIterator;
128  typedef std::ptrdiff_t Difference;
129 
134  ReverseIterator rbegin()
135  {
136  return ReverseIterator( static_cast<TDerived*>(this)->end() );
137  }
138 
143  inline
144  ConstReverseIterator rbegin() const
145  {
146  return ConstReverseIterator( static_cast<TDerived*>(this)->end() );
147  }
148 
153  inline
154  ConstReverseIterator crbegin() const
155  {
156  return ConstReverseIterator( static_cast<TDerived*>(this)->cend() );
157  }
158 
163  inline
164  ReverseIterator rend()
165  {
166  return ReverseIterator( static_cast<TDerived*>(this)->begin() );
167  }
168 
173  inline
174  ConstReverseIterator rend() const
175  {
176  return ConstReverseIterator( static_cast<TDerived*>(this)->begin() );
177  }
178 
183  inline
184  ConstReverseIterator crend() const
185  {
186  return ConstReverseIterator( static_cast<TDerived*>(this)->cbegin() );
187  }
188 
194  inline
195  Range range()
196  {
197  TDerived* const derived = static_cast<TDerived*>(this);
198  return Range(
199  derived->begin(),
200  derived->end(),
202  );
203  }
204 
210  inline
211  ConstRange constRange() const
212  {
213  TDerived const* const derived = static_cast<TDerived const*>(this);
214  return ConstRange(
215  derived->begin(),
216  derived->end(),
218  );
219  }
220 
221  protected:
222 
225  {}
226  };
227 
228 } // namespace DGtal
229 
230 // //
232 
233 #endif // !defined IteratorCompletion_h
234 
235 #undef IteratorCompletion_RECURSES
236 #endif // else defined(IteratorCompletion_RECURSES)
237 
Aim: Class that uses CRTP to add reverse iterators and ranges to a derived class. ...
boost::reverse_iterator< ConstIterator > ConstReverseIterator
Constant reverse iterator type.
IteratorCompletionTraits< TDerived >::ConstIterator ConstIterator
Constant iterator type.
ConstReverseIterator rend() const
ConstRange constRange() const
Aim: Traits that must be specialized for each IteratorCompletion derived class.
ConstReverseIterator rbegin() const
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
ConstReverseIterator crbegin() const
ConstReverseIterator crend() const
IteratorCompletionTraits< TDerived >::Iterator Iterator
Mutable iterator type.
IteratorCompletionTraits< TDerived >::DistanceFunctor DistanceFunctor
Type of the functor calculating the distance between iterators.
~IteratorCompletion()
Protected destructor to avoid memory leak.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ptrdiff_t Difference
Type of the distance between two iterators.
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctor > ConstRange
Constant range type.
boost::reverse_iterator< Iterator > ReverseIterator
Mutable reverse iterator type.
SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctor > Range
Mutable range type.