DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
76  BOOST_CONCEPT_ASSERT ( ( boost::RandomAccessIterator<TIterator> ) );
77  BOOST_CONCEPT_ASSERT ( ( boost::RandomAccessIterator<TConstIterator> ) );
78  BOOST_CONCEPT_ASSERT ( ( boost::UnaryFunction<DistanceFunctor,typename DistanceFunctor::Difference,typename DistanceFunctor::Point > ) );
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 
95  // typedef Circulator<Iterator> Circulator;
96  // typedef std::reverse_iterator<Circulator> ReverseCirculator;
97 
98  // ------------------------- standard services --------------------------------
99 
108  SimpleRandomAccessRangeFromPoint ( const TIterator& itb,
109  const TIterator& ite,
110  const DistanceFunctor & aDistance )
111  : myBegin ( itb ), myEnd ( ite ), myDistance ( aDistance ) {}
112 
118  : myBegin ( other.myBegin ), myEnd ( other.myEnd ),
119  myDistance ( other.myDistance ) {}
120 
127  {
128  if ( this != &other )
129  {
130  myBegin = other.myBegin;
131  myEnd = other.myEnd;
132  myDistance = other.myDistance;
133  }
134 
135  return *this;
136  }
137 
142 
147  bool isValid() const
148  {
149  return true;
150  }
151 
152  // ------------------------- display --------------------------------
157  void selfDisplay ( std::ostream & out ) const
158  {
159  typedef typename IteratorCirculatorTraits<Iterator>::Value Value;
160  out << "[SimpleRandomAccessRangeFromPoint]" << std::endl;
161  out << "\t";
162  std::copy ( myBegin, myEnd, ostream_iterator<Value> ( out, ", " ) );
163  out << std::endl;
164  }
165 
169  std::string className() const
170  {
171  return "SimpleRandomAccessRangeFromPoint";
172  }
173 
174 
175  // ------------------------- private data --------------------------------
176 
177  private:
181  TIterator myBegin;
185  TIterator myEnd;
186 
190  DistanceFunctor myDistance;
191 
192  // ------------------------- iterator services --------------------------------
193 
194  public:
195 
201  {
202  return Iterator ( myBegin );
203  }
204 
205 
211  Iterator begin ( const Point &aPoint )
212  {
213  return Iterator ( myBegin ) + myDistance ( aPoint );
214  }
215 
221  {
222  return ConstIterator ( myBegin );
223  }
224 
225 
231  ConstIterator begin ( const Point &aPoint ) const
232  {
233  return ConstIterator ( myBegin ) + myDistance ( aPoint );
234  }
235 
241  {
242  return Iterator ( myEnd );
243  }
244 
250  {
251  return ConstIterator ( myEnd );
252  }
253 
259  {
260  return OutputIterator ( myBegin );
261  }
262 
269  {
270  return OutputIterator ( myBegin ) + myDistance ( aPoint ) ;
271  }
272 
278  {
279  return ReverseOutputIterator ( myBegin );
280  }
281 
288  {
289  return ReverseOutputIterator ( myBegin ) + myDistance ( aPoint ) ;
290  }
291 
292 
293 
299  {
300  return ReverseIterator ( this->end() );
301  }
302 
308  ReverseIterator rbegin ( const Point &aPoint )
309  {
310  return ReverseIterator ( this->end() + myDistance ( aPoint ) );
311  }
312 
313 
319  {
320  return ReverseIterator ( this->begin() );
321  }
322 
323 
329  {
330  return ConstReverseIterator ( this->end() );
331  }
332 
338  ConstReverseIterator rbegin ( const Point &aPoint ) const
339  {
340  return ConstReverseIterator ( this->end() + myDistance ( aPoint ) );
341  }
342 
343 
349  {
350  return ConstReverseIterator ( this->begin() );
351  }
352 
353  // /**
354  // * Circulator service.
355  // * @return a circulator
356  // */
357  // Circulator c() const
358  // {
359  // return Circulator ( this->begin(), this->begin(), this->end() );
360  // }
361 
362  // /**
363  // * Circulator service.
364  // * @return a reverse circulator
365  // */
366  // ReverseCirculator rc() const
367  // {
368  // return ReverseCirculator ( this->c() );
369  // }
370 
371  }; //end class SimpleRandomAccessRangeFromPoint
372 
373 } // namespace DGtal
374 
376 
377 
378 #endif // !defined SimpleRandomAccessRangeFromPoint_h
379 
380 #undef SimpleRandomAccessRangeFromPoint_RECURSES
381 #endif // else defined(SimpleRandomAccessRangeFromPoint_RECURSES)