DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SimpleRandomAccessConstRangeFromPoint.h
1 
17 #pragma once
18 
33 #if defined(SimpleRandomAccessConstRangeFromPoint_RECURSES)
34 #error Recursive header files inclusion detected in SimpleRandomAccessConstRangeFromPoint.h
35 #else // defined(SimpleRandomAccessConstRangeFromPoint_RECURSES)
36 
37 #define SimpleRandomAccessConstRangeFromPoint_RECURSES
38 
39 #if !defined SimpleRandomAccessConstRangeFromPoint_h
40 
41 #define SimpleRandomAccessConstRangeFromPoint_h
42 
44 // Inclusions
45 #include "DGtal/base/BasicFunctors.h"
46 #include "DGtal/base/Circulator.h"
47 #include "DGtal/base/ConstIteratorAdapter.h"
48 #include "DGtal/base/CConstBidirectionalRangeFromPoint.h"
49 #include "boost/concept_check.hpp"
51 
52 namespace DGtal
53 {
54 
55 
57  // class SimpleRandomAccessConstRangeFromPoint
59 
71  template <typename TConstIterator, typename DistanceFunctor>
72 
74  {
75 
76  BOOST_CONCEPT_ASSERT ( ( boost::RandomAccessIterator<TConstIterator> ) );
77  BOOST_CONCEPT_ASSERT ( ( boost::UnaryFunction<DistanceFunctor,typename DistanceFunctor::Difference,typename DistanceFunctor::Point > ) );
78 
79  // ------------------------- inner types --------------------------------
80 
81  public:
82 
83 
84  typedef typename DistanceFunctor::Point Point;
85 
86  typedef TConstIterator ConstIterator;
87  typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
88 
90  typedef std::reverse_iterator<ConstCirculator> ConstReverseCirculator;
91 
92  // ------------------------- standard services --------------------------------
93 
102  SimpleRandomAccessConstRangeFromPoint ( const TConstIterator& itb, const TConstIterator& ite, const DistanceFunctor & aDistance )
103  : myBegin ( itb ), myEnd ( ite ), myDistance ( aDistance ) {}
104 
110  : myBegin ( other.myBegin ), myEnd ( other.myEnd ), myDistance ( other.myDistance ) {}
111 
118  {
119  if ( this != &other )
120  {
121  myBegin = other.myBegin;
122  myEnd = other.myEnd;
123  myDistance = other.myDistance;
124  }
125 
126  return *this;
127  }
128 
133 
138  bool isValid() const
139  {
140  return true;
141  }
142 
143  // ------------------------- display --------------------------------
148  void selfDisplay ( std::ostream & out ) const
149  {
150  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Value;
151  out << "[SimpleRandomAccessConstRangeFromPoint]" << std::endl;
152  out << "\t";
153  std::copy ( myBegin, myEnd, ostream_iterator<Value> ( out, ", " ) );
154  out << std::endl;
155  }
156 
160  std::string className() const
161  {
162  return "SimpleRandomAccessConstRangeFromPoint";
163  }
164 
165 
166  // ------------------------- private data --------------------------------
167 
168  private:
172  TConstIterator myBegin;
176  TConstIterator myEnd;
177 
181  DistanceFunctor myDistance;
182 
183  // ------------------------- iterator services --------------------------------
184 
185  public:
186 
192  {
193  return ConstIterator ( myBegin );
194  }
195 
196 
201  ConstIterator begin ( const Point &aPoint ) const
202  {
203  return ConstIterator ( myBegin ) + myDistance ( aPoint );
204  }
205 
211  {
212  return ConstIterator ( myEnd );
213  }
214 
220  {
221  return ConstReverseIterator ( this->end() );
222  }
223 
228  ConstReverseIterator rbegin ( const Point &aPoint ) const
229  {
230  return ConstReverseIterator ( this->end() + myDistance ( aPoint ) );
231  }
232 
233 
239  {
240  return ConstReverseIterator ( this->begin() );
241  }
242 
248  {
249  return ConstCirculator ( this->begin(), this->begin(), this->end() );
250  }
251 
257  {
258  return ConstReverseCirculator ( this->c() );
259  }
260 
261  }; //end class SimpleRandomAccessConstRangeFromPoint
262 
263 } // namespace DGtal
264 
266 
267 
268 #endif // !defined SimpleRandomAccessConstRangeFromPoint_h
269 
270 #undef SimpleRandomAccessConstRangeFromPoint_RECURSES
271 #endif // else defined(SimpleRandomAccessConstRangeFromPoint_RECURSES)