SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stride_iterator.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
74 #ifndef SLIP_STRIDE_ITERATOR_HPP
75 #define SLIP_STRIDE_ITERATOR_HPP
76 
77 #include <iterator> //iterator tags & iterator_traits
78 #include <cassert>
79 
80 namespace slip
81 {
82 template<class Iter_T>
83 class stride_iterator
84 {
85 public:
86  //to specify the category of this iterator. Useful for optimazed algorithms
87  typedef std::random_access_iterator_tag iterator_category;
88 
89  //nested typedefs to define an iterator
90  typedef typename std::iterator_traits<Iter_T>::value_type value_type;
91  typedef typename std::iterator_traits<Iter_T>::difference_type difference_type;
92  typedef typename std::iterator_traits<Iter_T>::pointer pointer;
93  typedef typename std::iterator_traits<Iter_T>::reference reference;
94 
95  //typedef to simplify the class code
96  typedef stride_iterator self;
97 
98  //constructors
100  it_(),step_(0)
101  {}
102  stride_iterator(const self& o):
103  it_(o.it_),step_(o.step_)
104  {}
105  stride_iterator(Iter_T it,
106  difference_type n):
107  it_(it),step_(n)
108  {}
109 
110  //operators
111  self& operator++()
112  {
113  it_ += step_;
114  return *this;
115  }
116  //postfixed ++ operator
117  self operator++(int)
118  {
119  self tmp = *this;
120  it_ += step_;
121  return tmp;
122  }
123 
125  {
126  it_ += n * step_;
127  return *this;
128  }
129  self& operator--()
130  {
131  it_ -= step_;
132  return *this;
133  }
134 
135  //postfixed -- operator
136  self operator--(int)
137  {
138  self tmp = *this;
139  it_ -= step_;
140  return tmp;
141  }
143  {
144  it_ -= n * step_;
145  return *this;
146  }
147 
149  {
150  return *(it_ + (n * step_));
151  }
152 
154  {
155  return *(it_ + (n * step_));
156  }
157 
159  {
160  return *it_;
161  }
162 
164  {
165  return &(operator*());
166  }
167 
168  //friend operators
169  //Equality Comparable
170  friend bool operator==(const self& x,
171  const self& y)
172  {
173  assert(x.step_ == y.step_);
174  return x.it_ == y.it_;
175  }
176 
177  friend bool operator!=(const self& x,
178  const self& y)
179  {
180  assert(x.step_ == y.step_);
181  return x.it_ != y.it_;
182  }
183 
184  //Less Than Comparable
185  friend bool operator<(const self& x,
186  const self& y)
187  {
188  assert(x.step_ == y.step_);
189  return x.it_ < y.it_;
190  }
191 
192  friend bool operator>(const self& x,
193  const self& y)
194  {
195  return y < x;
196  }
197 
198  friend bool operator<=(const self& x,
199  const self& y)
200  {
201  return !(y < x);
202  }
203 
204  friend bool operator>=(const self& x,
205  const self& y)
206  {
207  return !(x < y);
208  }
209 
210  friend difference_type operator-(const self& x,
211  const self& y)
212  {
213  assert(x.step_ == y.step_);
214  return (x.it_ - y.it_) / x.step_;
215  }
216 
217  friend self operator+(const self& x,
218  difference_type n)
219  {
220  self tmp = x;
221  tmp += n;
222  return tmp;
223  }
224  friend self operator+(difference_type n,
225  const self& y)
226  {
227  self tmp = y;
228  tmp += n;
229  return tmp;
230  }
231 
232  friend self operator-(const self& x,
233  difference_type n)
234  {
235  self tmp = x;
236  tmp -= n;
237  return tmp;
238  }
239 
240 // friend self operator-(const self& x,
241 // difference_type n)
242 // {
243 // self tmp = x;
244 // tmp -= n;
245 // return tmp;
246 // }
247 
248 
249 
250 private:
251  Iter_T it_;
252  difference_type step_;
253 
254 };
255 }//slip::
256 #endif //SLIP_STRIDE_ITERATOR_HPP
std::iterator_traits< Iter_T >::difference_type difference_type
friend bool operator==(const self &x, const self &y)
const reference operator[](difference_type n) const
friend difference_type operator-(const self &x, const self &y)
reference operator[](difference_type n)
stride_iterator(const self &o)
self & operator+=(difference_type n)
friend bool operator>=(const self &x, const self &y)
friend bool operator!=(const self &x, const self &y)
std::iterator_traits< Iter_T >::reference reference
stride_iterator(Iter_T it, difference_type n)
friend self operator-(const self &x, difference_type n)
self & operator-=(difference_type n)
friend bool operator<(const self &x, const self &y)
friend bool operator<=(const self &x, const self &y)
std::random_access_iterator_tag iterator_category
friend self operator+(const self &x, difference_type n)
friend bool operator>(const self &x, const self &y)
std::iterator_traits< Iter_T >::value_type value_type
friend self operator+(difference_type n, const self &y)
std::iterator_traits< Iter_T >::pointer pointer