DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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)
36 
37 #define SimpleConstRange_RECURSES
38 
39 #if !defined SimpleConstRange_h
40 
41 #define SimpleConstRange_h
42 
44 // Inclusions
45 #include "DGtal/base/BasicFunctors.h"
46 #include "DGtal/base/Circulator.h"
47 #include "DGtal/base/ConstIteratorAdapter.h"
48 #include "boost/concept_check.hpp"
50 
51 namespace DGtal
52 {
53 
54 
56  // class SimpleConstRange
58 
69  template <typename TConstIterator>
71  {
72 
73  BOOST_CONCEPT_ASSERT(( boost::BidirectionalIterator<TConstIterator> ));
74 
75  // ------------------------- inner types --------------------------------
76  public:
77 
78  typedef TConstIterator ConstIterator;
79  typedef std::reverse_iterator<ConstIterator> ConstReverseIterator;
80 
82  typedef std::reverse_iterator<ConstCirculator> ConstReverseCirculator;
83 
84  // ------------------------- standard services --------------------------------
85 
94  SimpleConstRange(const TConstIterator& itb, const TConstIterator& ite)
95  : myBegin(itb), myEnd(ite) {}
96 
102  : myBegin(other.myBegin), myEnd(other.myEnd) {}
103 
110  {
111  if ( this != &other )
112  {
113  myBegin = other.myBegin;
114  myEnd = other.myEnd;
115  }
116  return *this;
117  }
118 
123 
128  bool isValid() const { return true; }
129 
130  // ------------------------- display --------------------------------
135  void selfDisplay ( std::ostream & out ) const
136  {
137  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Value;
138  out << "[SimpleConstRange]" << std::endl;
139  out << "\t";
140  std::copy( myBegin, myEnd, ostream_iterator<Value>(out, ", ") );
141  out << std::endl;
142  }
143 
147  std::string className() const
148  {
149  return "SimpleConstRange";
150  }
151 
152 
153  // ------------------------- private data --------------------------------
154  private:
158  TConstIterator myBegin;
162  TConstIterator myEnd;
163 
164  // ------------------------- iterator services --------------------------------
165  public:
166 
172  return ConstIterator( myBegin );
173  }
174 
179  ConstIterator end() const {
180  return ConstIterator( myEnd );
181  }
182 
188  return ConstReverseIterator(this->end());
189  }
190 
196  return ConstReverseIterator(this->begin());
197  }
198 
203  ConstCirculator c() const {
204  return ConstCirculator( this->begin(), this->begin(), this->end() );
205  }
206 
212  return ConstReverseCirculator( this->c() );
213  }
214 
215  }; //end class SimpleConstRange
216 
217 } // namespace DGtal
218 
220 
221 
222 #endif // !defined SimpleConstRange_h
223 
224 #undef SimpleConstRange_RECURSES
225 #endif // else defined(SimpleConstRange_RECURSES)