DGtal  0.9.4.1
IntegerSequenceIterator.h
1 
17 #pragma once
18 
31 #if defined(IntegerSequenceIterator_RECURSES)
32 #error Recursive header files inclusion detected in IntegerSequenceIterator.h
33 #else // defined(IntegerSequenceIterator_RECURSES)
34 
35 #define IntegerSequenceIterator_RECURSES
36 
37 #if !defined IntegerSequenceIterator_h
38 
39 #define IntegerSequenceIterator_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <boost/iterator/iterator_facade.hpp>
45 #include "DGtal/base/Common.h"
47 
48 namespace DGtal
49 {
50 
52  // template class IntegerSequenceIterator
64  template <typename TInteger>
66  : public boost::iterator_facade< IntegerSequenceIterator< TInteger >,
67  TInteger const,
68  boost::random_access_traversal_tag >
69  {
70  public:
72  typedef TInteger Integer;
73 
74  // ----------------------- Standard services ------------------------------
75  public:
76 
82 
86  ~IntegerSequenceIterator() = default;
87 
92  IntegerSequenceIterator ( const IntegerSequenceIterator & other ) = default;
93 
98  IntegerSequenceIterator ( IntegerSequenceIterator && other ) = default;
99 
105  IntegerSequenceIterator & operator= ( const IntegerSequenceIterator & other ) = default;
106 
113 
114  // ----------------------- Boost facade services --------------------------------------
115  private:
117 
119  void increment() { myNumber++; }
121  void decrement() { myNumber--; }
124  void advance( std::ptrdiff_t n ) { myNumber += n; }
127  std::ptrdiff_t distance_to( IntegerSequenceIterator const& other )
128  { return other.myNumber - myNumber; }
131  bool equal( IntegerSequenceIterator const& other) const
132  { return this->myNumber == other.myNumber; }
135  Integer const& dereference() const { return myNumber; }
136 
137  // ----------------------- Interface --------------------------------------
138  public:
139 
140  // ------------------------- Protected Datas ------------------------------
141  protected:
144 
145  // ------------------------- Private Datas --------------------------------
146  private:
147 
148  // ------------------------- Hidden services ------------------------------
149  protected:
150 
151  // ------------------------- Internals ------------------------------------
152  private:
153 
154  }; // end of class IntegerSequenceIterator
155 
156 } // namespace DGtal
157 
158 
160 // //
162 
163 #endif // !defined IntegerSequenceIterator_h
164 
165 #undef IntegerSequenceIterator_RECURSES
166 #endif // else defined(IntegerSequenceIterator_RECURSES)
IntegerSequenceIterator(Integer n=Integer(0))
Integer myNumber
The current value of the interator.
void decrement()
Decrements the iterator. Required by boost::iterator_facade.
bool equal(IntegerSequenceIterator const &other) const
IntegerSequenceIterator & operator=(const IntegerSequenceIterator &other)=default
Aim: It is a simple class that mimics a (non mutable) iterator over integers. You can increment it...
std::ptrdiff_t distance_to(IntegerSequenceIterator const &other)
DGtal is the top-level namespace which contains all DGtal functions and types.
IntegerSequenceIterator< TInteger > Self
void increment()
Increments the iterator. Required by boost::iterator_facade.