DGtal  1.5.beta
SimpleConstRange.h
1 
17 #pragma once
18 
33 #if defined(SimpleConstRange_RECURSES)
34 #error Recursive header files inclusion detected in SimpleConstRange.h
35 #else // defined(SimpleConstRange_RECURSES)
37 #define SimpleConstRange_RECURSES
38 
39 #if !defined SimpleConstRange_h
41 #define SimpleConstRange_h
42 
44 // Inclusions
45 #include <iterator>
46 #include <iostream>
47 #include "DGtal/base/BasicFunctors.h"
48 #include "DGtal/base/Circulator.h"
49 #include "DGtal/base/ConstIteratorAdapter.h"
50 #include "boost/concept_check.hpp"
52 
53 namespace DGtal
54 {
55 
56 
58  // class SimpleConstRange
60 
71  template <typename TConstIterator>
73  {
74 
76 
77  // ------------------------- inner types --------------------------------
78  public:
79 
80  typedef TConstIterator ConstIterator;
81  typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
82 
84  typedef std::reverse_iterator<ConstCirculator> ConstReverseCirculator;
85 
86  // ------------------------- standard services --------------------------------
87 
95  SimpleConstRange(const TConstIterator& itb, const TConstIterator& ite)
96  : myBegin(itb), myEnd(ite) {}
97 
103  : myBegin(other.myBegin), myEnd(other.myEnd) {}
104 
111  {
112  if ( this != &other )
113  {
114  myBegin = other.myBegin;
115  myEnd = other.myEnd;
116  }
117  return *this;
118  }
119 
124 
129  bool isValid() const { return true; }
130 
131  // ------------------------- display --------------------------------
136  void selfDisplay ( std::ostream & out ) const
137  {
139  out << "[SimpleConstRange]" << std::endl;
140  out << "\t";
141  std::copy( myBegin, myEnd, std::ostream_iterator<Value>(out, ", ") );
142  out << std::endl;
143  }
144 
148  std::string className() const
149  {
150  return "SimpleConstRange";
151  }
152 
153 
154  // ------------------------- private data --------------------------------
155  private:
159  TConstIterator myBegin;
163  TConstIterator myEnd;
164 
165  // ------------------------- iterator services --------------------------------
166  public:
167 
173  return ConstIterator( myBegin );
174  }
175 
180  ConstIterator end() const {
181  return ConstIterator( myEnd );
182  }
183 
189  return ConstReverseIterator(this->end());
190  }
191 
196  ConstReverseIterator rend() const {
197  return ConstReverseIterator(this->begin());
198  }
199 
204  ConstCirculator c() const {
205  return ConstCirculator( this->begin(), this->begin(), this->end() );
206  }
207 
212  ConstReverseCirculator rc() const {
213  return ConstReverseCirculator( this->c() );
214  }
215 
216  }; //end class SimpleConstRange
217 
218 } // namespace DGtal
219 
221 
222 
223 #endif // !defined SimpleConstRange_h
224 
225 #undef SimpleConstRange_RECURSES
226 #endif // else defined(SimpleConstRange_RECURSES)
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:86
Aim: model of CConstRange that adapts any range of elements bounded by two iterators [itb,...
BOOST_CONCEPT_ASSERT((boost::BidirectionalIterator< TConstIterator >))
std::reverse_iterator< ConstCirculator > ConstReverseCirculator
SimpleConstRange(const SimpleConstRange &other)
ConstIterator end() const
std::string className() const
ConstReverseIterator rbegin() const
SimpleConstRange & operator=(const SimpleConstRange &other)
ConstReverseCirculator rc() const
std::reverse_iterator< ConstIterator > ConstReverseIterator
Circulator< ConstIterator > ConstCirculator
SimpleConstRange(const TConstIterator &itb, const TConstIterator &ite)
TConstIterator ConstIterator
ConstIterator begin() const
ConstReverseIterator rend() const
ConstCirculator c() const
void selfDisplay(std::ostream &out) const
DGtal is the top-level namespace which contains all DGtal functions and types.
Go to http://www.sgi.com/tech/stl/BidirectionalIterator.html.
Definition: Boost.dox:42