DGtal  0.9.2
ConstRangeFromPointAdapter.h
1 
17 #pragma once
18 
34 #if defined(ConstRangeFromPointAdapter_RECURSES)
35 #error Recursive header files inclusion detected in ConstRangeFromPointAdapter.h
36 #else // defined(ConstRangeFromPointAdapter_RECURSES)
37 
38 #define ConstRangeFromPointAdapter_RECURSES
39 
40 #if !defined ConstRangeFromPointAdapter_h
41 
42 #define ConstRangeFromPointAdapter_h
43 
45 // Inclusions
46 #include "DGtal/base/ConstAlias.h"
47 #include "DGtal/base/BasicFunctors.h"
48 #include "DGtal/base/Circulator.h"
49 #include "DGtal/base/CConstBidirectionalRangeFromPoint.h"
50 #include "DGtal/base/ConstIteratorAdapter.h"
51 #include "boost/concept_check.hpp"
53 
54 namespace DGtal
55 {
56 
57 
59  // class ConstRangeFromPointAdapter
61 
85  template <typename TRange, typename TFunctor, typename TReturnType>
87  {
88 
89  BOOST_CONCEPT_ASSERT(( CConstBidirectionalRangeFromPoint<TRange> ));
90 
91  // ------------------------- inner types --------------------------------
92  public:
93 
94  typedef typename TRange::Point Point;
96  typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
97 
98  // ------------------------- standard services --------------------------------
99 
107  ConstAlias<TFunctor> aFunctor )
108  : myRangePtr(&aRange), myFunctorPtr(&aFunctor) {}
109 
115  : myRangePtr(other.myRangePtr), myFunctorPtr(other.myFunctorPtr) {}
116 
123  {
124  if ( this != &other )
125  {
126  myRangePtr = other.myRangePtr;
127  myFunctorPtr = other.myFunctorPtr;
128  }
129  return *this;
130  }
131 
136 
141  bool isValid() const { return true; }
142 
143 
144  // ------------------------- private data --------------------------------
145  private:
149  const TRange* myRangePtr;
153  const TFunctor* myFunctorPtr;
154 
155  // ------------------------- iterator services --------------------------------
156  public:
157 
162  ConstIterator begin() const {
163  return ConstIterator( myRangePtr->begin(), *myFunctorPtr );
164  }
165 
170  ConstIterator begin(const Point& aPoint) const {
171  return ConstIterator( myRangePtr->begin(aPoint), *myFunctorPtr );
172  }
173 
178  ConstIterator end() const {
179  return ConstIterator( myRangePtr->end(), *myFunctorPtr );
180  }
181 
186  ConstReverseIterator rbegin() const {
187  return ConstReverseIterator(this->end());
188  }
189 
194  ConstReverseIterator rbegin(const Point& aPoint) const {
195  ConstIterator it( myRangePtr->begin(aPoint), *myFunctorPtr );
196  if ( it != this->end() ) ++it;
197  return ConstReverseIterator( it );
198  }
199 
204  ConstReverseIterator rend() const {
205  return ConstReverseIterator(this->begin());
206  }
207 
208 
209  }; //end class ConstRangeFromPointAdapter
210 
211 } // namespace DGtal
212 
214 
215 
216 #endif // !defined ConstRangeFromPointAdapter_h
217 
218 #undef ConstRangeFromPointAdapter_RECURSES
219 #endif // else defined(ConstRangeFromPointAdapter_RECURSES)
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
ConstIterator begin(const Point &aPoint) const
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
ConstIteratorAdapter< typename TRange::ConstIterator, TFunctor, TReturnType > ConstIterator
BOOST_CONCEPT_ASSERT((CConstBidirectionalRangeFromPoint< TRange >))
std::reverse_iterator< ConstIterator > ConstReverseIterator
Aim: model of CConstBidirectionalRangeFromPoint that adapts any bidirectional range and provides serv...
DGtal is the top-level namespace which contains all DGtal functions and types.
ConstReverseIterator rbegin(const Point &aPoint) const
ConstRangeFromPointAdapter(ConstAlias< TRange > aRange, ConstAlias< TFunctor > aFunctor)
ConstRangeFromPointAdapter(const ConstRangeFromPointAdapter &other)
ConstRangeFromPointAdapter & operator=(const ConstRangeFromPointAdapter &other)