SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Range.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 
68 
75 #ifndef SLIP_RANGE_HPP
76 #define SLIP_RANGE_HPP
77 
78 #include <iostream>
79 #include <cassert>
80 #include <string>
81 
82 #include <boost/serialization/access.hpp>
83 #include <boost/serialization/split_member.hpp>
84 #include <boost/serialization/version.hpp>
85 
86 namespace slip
87 {
88 
89 
90 template <typename SubType>
91 class Range;
92 
93 template <typename SubType>
94 std::ostream& operator<<(std::ostream & out,
95  const Range<SubType>& b);
96 
97 template <typename SubType>
98 bool operator==(const Range<SubType>& b1,
99  const Range<SubType>& b2);
100 
101 template <typename SubType>
102 bool operator!=(const Range<SubType>& b1,
103  const Range<SubType>& b2);
104 
105 
115 template <typename SubType>
116 class Range
117 {
118 public:
119 
120  typedef Range<SubType> self;
121 
130  Range();
131 
138  Range(const SubType& start_sub,
139  const SubType& stop_sub,
140  const int stride = 1);
141 
148 
154  friend std::ostream& operator<< <>(std::ostream & out,
155  const self& r);
156 
173  friend bool operator== <>(const Range<SubType>& r1,
174  const Range<SubType>& r2);
175 
182  friend bool operator!= <>(const Range<SubType>& r1,
183  const Range<SubType>& r2);
191  std::string name() const;
192 
197  SubType start() const;
198 
203  SubType stop() const;
204 
209  int stride() const;
210 
215  std::size_t iterations() const;
216 
217 
228  bool is_valid() const;
229 
230 private :
231  SubType start_sub_;
232  SubType stop_sub_;
233  int stride_;
234 private :
235  friend class boost::serialization::access;
236  template<class Archive>
237  void save(Archive & ar, const unsigned int version) const
238  {
239  ar & start_sub_;
240  ar & stop_sub_;
241  ar & stride_;
242  }
243  template<class Archive>
244  void load(Archive & ar, const unsigned int version)
245  {
246  ar & start_sub_;
247  ar & stop_sub_;
248  ar & stride_;
249  }
250  BOOST_SERIALIZATION_SPLIT_MEMBER()
251 };
252 
253 }//slip::
254 
255 namespace slip
256 {
257 
258  template<typename SubType>
259  inline
261  start_sub_(0),stop_sub_(0),stride_(0)
262  {}
263 
264  template<typename SubType>
265  inline
266  Range<SubType>::Range(const SubType& start_sub,
267  const SubType& stop_sub,
268  int stride):
269  start_sub_(start_sub),stop_sub_(stop_sub),stride_(stride)
270  {}
271 
272 
273  template<typename SubType>
274  inline
275  std::string
277  {
278  return "Range";
279  }
280 
281 
282  template<typename SubType>
283  inline
284  SubType Range<SubType>::start() const
285  {
286  return start_sub_;
287  }
288 
289  template<typename SubType>
290  inline
291  SubType Range<SubType>::stop() const
292  {
293  return stop_sub_;
294  }
295 
296  template<typename SubType>
297  inline
299  {
300  return stride_;
301  }
302 
303  template<typename SubType>
304  inline
305  std::size_t Range<SubType>::iterations() const
306  {
307  int ret = 0;
308  if( stride_ != 0)
309  {
310  ret = ( (stop_sub_ - start_sub_) / stride_ );
311  }
312  if (ret < 0)
313  {
314  ret = - ret;
315  }
316  return (std::size_t)ret;
317  }
318 
319 
320  template<typename SubType>
321  inline
323  {
324  bool result = false;
325  if(stride_ >= 0)
326  result = (start_sub_ <= stop_sub_);
327  else
328  result = (start_sub_ >= stop_sub_);
329  return result;
330  }
331 
332 }//slip::
333 
334 
335 namespace slip
336 {
337  template<typename SubType>
338  inline
339  std::ostream& operator<<(std::ostream & out,
340  const Range<SubType>& b)
341  {
342  out<<"[ "<<b.start_sub_<<":"<<b.stop_sub_<<":"<<b.stride_<<" ]";
343  return out;
344  }
345 
346  template<typename SubType>
347  inline
348  bool operator==(const Range<SubType>& r1,
349  const Range<SubType>& r2)
350  {
351 
352  return (r1.start_sub_ == r2.start_sub_)
353  && (r1.stop_sub_ == r2.stop_sub_)
354  && (r1.stride_ == r2.stride_);
355  }
356 
357  template<typename SubType>
358  inline
359  bool operator!=(const Range<SubType>& r1,
360  const Range<SubType>& r2)
361  {
362 
363  return !(r1 == r2);
364  }
365 }//::slip
366 
367 #endif //SLIP_RANGE_HPP
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
std::size_t iterations() const
Rerturns the number of iterations of the range.
Definition: Range.hpp:305
std::string name() const
Returns the name of the class.
Definition: Range.hpp:276
This is a Range class.
Range()
Constructs a default Range start_sub = stop_sub = stride = 0.
Definition: Range.hpp:260
bool is_valid() const
Returns true if the range is valid :
Definition: Range.hpp:322
SubType start() const
Accessor of the start subscript of the Range.
Definition: Range.hpp:284
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
int stride() const
Accessor of the stride of the Range.
Definition: Range.hpp:298
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
SubType stop() const
Accessor of the stop subscript of the Range.
Definition: Range.hpp:291