DGtal  0.9.2
SimpleRandomAccessRangeFromPoint.h
1 
17 #pragma once
18 
33 #if defined(SimpleRandomAccessRangeFromPoint_RECURSES)
34 #error Recursive header files inclusion detected in SimpleRandomAccessRangeFromPoint.h
35 #else // defined(SimpleRandomAccessRangeFromPoint_RECURSES)
36 
37 #define SimpleRandomAccessRangeFromPoint_RECURSES
38 
39 #if !defined SimpleRandomAccessRangeFromPoint_h
40 
41 #define SimpleRandomAccessRangeFromPoint_h
42 
44 // Inclusions
45 #include "DGtal/base/BasicFunctors.h"
46 #include "DGtal/base/Circulator.h"
47 #include "DGtal/base/IteratorAdapter.h"
48 #include "DGtal/base/CBidirectionalRangeFromPoint.h"
49 #include "boost/concept_check.hpp"
51 
52 namespace DGtal
53 {
54 
55 
57  // class SimpleRandomAccessRangeFromPoint
59 
71  template <typename TConstIterator, typename TIterator, typename DistanceFunctor>
72 
74  {
75 
79 
80  // ------------------------- inner types --------------------------------
81 
82  public:
83 
84  typedef typename DistanceFunctor::Point Point;
85 
86  typedef TIterator Iterator;
87  typedef TConstIterator ConstIterator;
88 
89  typedef std::reverse_iterator<Iterator> ReverseIterator;
90  typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
91 
92  typedef TIterator OutputIterator;
93  typedef std::reverse_iterator<Iterator> ReverseOutputIterator;
94 
96  typedef std::reverse_iterator<Circulator> ReverseCirculator;
97 
99  typedef std::reverse_iterator<ConstCirculator> ConstReverseCirculator;
100 
101  // ------------------------- standard services --------------------------------
102 
111  SimpleRandomAccessRangeFromPoint ( const TIterator& itb,
112  const TIterator& ite,
113  const DistanceFunctor & aDistance )
114  : myBegin ( itb ), myEnd ( ite ), myDistance ( aDistance ) {}
115 
121  : myBegin ( other.myBegin ), myEnd ( other.myEnd ),
122  myDistance ( other.myDistance ) {}
123 
130  {
131  if ( this != &other )
132  {
133  myBegin = other.myBegin;
134  myEnd = other.myEnd;
135  myDistance = other.myDistance;
136  }
137 
138  return *this;
139  }
140 
145 
150  bool isValid() const
151  {
152  return true;
153  }
154 
155  // ------------------------- display --------------------------------
160  void selfDisplay ( std::ostream & out ) const
161  {
162  typedef typename IteratorCirculatorTraits<Iterator>::Value Value;
163  out << "[SimpleRandomAccessRangeFromPoint]" << std::endl;
164  out << "\t";
165  std::copy ( myBegin, myEnd, std::ostream_iterator<Value> ( out, ", " ) );
166  out << std::endl;
167  }
168 
172  std::string className() const
173  {
174  return "SimpleRandomAccessRangeFromPoint";
175  }
176 
177 
178  // ------------------------- private data --------------------------------
179 
180  private:
184  TIterator myBegin;
188  TIterator myEnd;
189 
193  DistanceFunctor myDistance;
194 
195  // ------------------------- iterator services --------------------------------
196 
197  public:
198 
203  Iterator begin()
204  {
205  return Iterator ( myBegin );
206  }
207 
208 
214  Iterator begin ( const Point &aPoint )
215  {
216  return Iterator ( myBegin ) + myDistance ( aPoint );
217  }
218 
223  ConstIterator begin() const
224  {
225  return ConstIterator ( myBegin );
226  }
227 
228 
234  ConstIterator begin ( const Point &aPoint ) const
235  {
236  return ConstIterator ( myBegin ) + myDistance ( aPoint );
237  }
238 
243  Iterator end()
244  {
245  return Iterator ( myEnd );
246  }
247 
252  ConstIterator end() const
253  {
254  return ConstIterator ( myEnd );
255  }
256 
261  OutputIterator outputIterator()
262  {
263  return OutputIterator ( myBegin );
264  }
265 
271  OutputIterator outputIterator ( const Point &aPoint )
272  {
273  return OutputIterator ( myBegin ) + myDistance ( aPoint ) ;
274  }
275 
280  ReverseOutputIterator routputIterator()
281  {
282  return ReverseOutputIterator ( this->end() );
283  }
284 
290  ReverseOutputIterator routputIterator ( const Point &aPoint )
291  {
292  return ReverseOutputIterator ( myBegin + myDistance ( aPoint ) + 1 ) ;
293  }
294 
299  ReverseIterator rbegin()
300  {
301  return ReverseIterator ( this->end() );
302  }
303 
309  ReverseIterator rbegin ( const Point &aPoint )
310  {
311  return ReverseIterator ( myBegin + myDistance ( aPoint ) + 1 );
312  }
313 
314 
319  ReverseIterator rend()
320  {
321  return ReverseIterator ( myBegin );
322  }
323 
324 
329  ConstReverseIterator rbegin() const
330  {
331  return ConstReverseIterator ( this->end() );
332  }
333 
339  ConstReverseIterator rbegin ( const Point &aPoint ) const
340  {
341  return ConstReverseIterator ( myBegin + myDistance ( aPoint ) + 1 );
342  }
343 
344 
349  ConstReverseIterator rend() const
350  {
351  return ConstReverseIterator ( myBegin );
352  }
353 
358  Circulator c()
359  {
360  return Circulator ( this->begin(), this->begin(), this->end() );
361  }
362 
367  ReverseCirculator rc()
368  {
369  return ReverseCirculator ( this->c() );
370  }
371 
376  ConstCirculator c() const
377  {
378  return ConstCirculator ( this->begin(), this->begin(), this->end() );
379  }
380 
385  ConstReverseCirculator rc() const
386  {
387  return ConstReverseCirculator ( this->c() );
388  }
389 
390  }; //end class SimpleRandomAccessRangeFromPoint
391 
392 } // namespace DGtal
393 
395 
396 
397 #endif // !defined SimpleRandomAccessRangeFromPoint_h
398 
399 #undef SimpleRandomAccessRangeFromPoint_RECURSES
400 #endif // else defined(SimpleRandomAccessRangeFromPoint_RECURSES)
Go to http://www.sgi.com/tech/stl/UnaryFunction.html.
Definition: Boost.dox:73
OutputIterator outputIterator(const Point &aPoint)
ConstIterator begin(const Point &aPoint) const
std::reverse_iterator< Circulator > ReverseCirculator
ConstReverseIterator rbegin(const Point &aPoint) const
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
SimpleRandomAccessRangeFromPoint(const TIterator &itb, const TIterator &ite, const DistanceFunctor &aDistance)
std::reverse_iterator< Iterator > ReverseOutputIterator
std::reverse_iterator< ConstIterator > ConstReverseIterator
ReverseOutputIterator routputIterator(const Point &aPoint)
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::Circulator< ConstIterator > ConstCirculator
SimpleRandomAccessRangeFromPoint & operator=(const SimpleRandomAccessRangeFromPoint &other)
std::reverse_iterator< ConstCirculator > ConstReverseCirculator
Go to http://www.sgi.com/tech/stl/RandomAccessIterator.html.
Definition: Boost.dox:44
BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator< TIterator >))
SimpleRandomAccessRangeFromPoint(const SimpleRandomAccessRangeFromPoint &other)