SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
container_cast.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 
76 #ifndef SLIP_CONTAINER_CAST_HPP
77 #define SLIP_CONTAINER_CAST_HPP
78 
79 #include "DPoint2d.hpp"
80 #include "DPoint3d.hpp"
81 
82 namespace slip
83 {
84  //-----------------------------------------------------------
85  // Cast a container into its default iterators
86  //-----------------------------------------------------------
87  template<typename>
88  struct __container_iterator_cast
89  {
90  template<typename Container1,
91  typename Iterator1>
92  static void
93  container_iterator_cast(Container1& container,
94  Iterator1& first,
95  Iterator1& last)
96 
97  {
98  first = container.begin();
99  last = container.end();
100  }
101  };
102 
103  template<>
104  struct __container_iterator_cast<std::random_access_iterator_tag>
105  {
106  template<typename Container1,
107  typename Iterator1>
108  static void
109  container_iterator_cast(Container1& container,
110  Iterator1& first,
111  Iterator1& last)
112  {
113  first = container.begin();
114  last = container.end();
115  }
116  };
117 
118  template<>
119  struct __container_iterator_cast<std::random_access_iterator2d_tag>
120  {
121  template<typename Container1,
122  typename Iterator1>
123  static void
124  container_iterator_cast(Container1& container,
125  Iterator1& first,
126  Iterator1& last)
127  {
128  first = container.upper_left();
129  last = container.bottom_right();
130  }
131  };
132 
133  template<>
134  struct __container_iterator_cast<std::random_access_iterator3d_tag>
135  {
136  template<typename Container1,
137  typename Iterator1>
138  static void
139  container_iterator_cast(Container1& container,
140  Iterator1& first,
141  Iterator1& last)
142  {
143  first = container.front_upper_left();
144  last = container.back_bottom_right();
145  }
146  };
147 
148 
204  template<typename Container, typename _II>
205  void container_cast(Container& cont, _II& first, _II& last)
206  {
207  typedef typename std::iterator_traits<_II>::iterator_category _Category;
208  __container_iterator_cast<_Category>::container_iterator_cast(cont,first,last);
209  }
210 
211 
212 
213 
214  //-----------------------------------------------------------
215  // Cast a container into its reverse iterators
216  //-----------------------------------------------------------
217  template<typename>
218  struct __reverse_container_iterator_cast
219  {
220  template<typename Container1,
221  typename Iterator1>
222  static void
223  reverse_container_iterator_cast(Container1& container,
224  Iterator1& first,
225  Iterator1& last)
226 
227  {
228  first = container.rbegin();
229  last = container.rend();
230  }
231  };
232 
233  template<>
234  struct __reverse_container_iterator_cast<std::random_access_iterator_tag>
235  {
236  template<typename Container1,
237  typename Iterator1>
238  static void
239  reverse_container_iterator_cast(Container1& container,
240  Iterator1& first,
241  Iterator1& last)
242  {
243  first = container.rbegin();
244  last = container.rend();
245  }
246  };
247 
248  template<>
249  struct __reverse_container_iterator_cast<std::random_access_iterator2d_tag>
250  {
251  template<typename Container1,
252  typename Iterator1>
253  static void
254  reverse_container_iterator_cast(Container1& container,
255  Iterator1& first,
256  Iterator1& last)
257  {
258  slip::DPoint2d<int> dp(1,0);
259  first = container.bottom_right() - dp;
260  last = container.upper_left();
261  //can not access to i() and j() function like that
262  //for that we should have to define our own reverse_iterator2d
263  // first = container.rbottom_right();
264  // last = container.rupper_left();
265  }
266  };
267 
268  template<>
269  struct __reverse_container_iterator_cast<std::random_access_iterator3d_tag>
270  {
271  template<typename Container1,
272  typename Iterator1>
273  static void
274  reverse_container_iterator_cast(Container1& container,
275  Iterator1& first,
276  Iterator1& last)
277  {
278  // first = container.rfront_upper_left();
279  // last = container.rback_bottom_right();
280  //can not access to k(), i() and j() function like that
281  //for that we should have to define our own reverse_iterator3d
282  DPoint3d<int> dp(1,1,0);
283  first = container.back_bottom_right() - dp;
284  last = container.front_upper_left();
285  }
286  };
287 
288 
289 
307  template<typename Container, typename _II>
308  void reverse_container_cast(Container& cont, _II& first, _II& last)
309  {
310  typedef typename std::iterator_traits<_II>::iterator_category _Category;
311  __reverse_container_iterator_cast<_Category>::reverse_container_iterator_cast(cont,first,last);
312  }
313 
314 
315 
316  //DEPRECATED !!!!!
317  //-----------------------------------------------------------
318  // Cast a container into its reverse iterators
319  //-----------------------------------------------------------
320  template<typename>
321  struct __container_iterator_castR
322  {
323  template<typename Container1,
324  typename Iterator1>
325  static void
326  container_iterator_castR(Container1& container,
327  Iterator1& first,
328  Iterator1& last)
329 
330  {
331  first = container.rbegin();
332  last = container.rend();
333  }
334  };
335 
336  template<>
337  struct __container_iterator_castR<std::random_access_iterator_tag>
338  {
339  template<typename Container1,
340  typename Iterator1>
341  static void
342  container_iterator_castR(Container1& container,
343  Iterator1& first,
344  Iterator1& last)
345  {
346  first = container.rbegin();
347  last = container.rend();
348  }
349  };
350 
351  template<>
352  struct __container_iterator_castR<std::random_access_iterator2d_tag>
353  {
354  template<typename Container1,
355  typename Iterator1>
356  static void
357  container_iterator_castR(Container1& container,
358  Iterator1& first,
359  Iterator1& last)
360  {
361  slip::DPoint2d<int> dp(1,0);
362  first = container.bottom_right() - dp;
363  last = container.upper_left();
364  }
365  };
366 
367  template<>
368  struct __container_iterator_castR<std::random_access_iterator3d_tag>
369  {
370  template<typename Container1,
371  typename Iterator1>
372  static void
373  container_iterator_castR(Container1& container,
374  Iterator1& first,
375  Iterator1& last)
376  {
377  first = container.rfront_upper_left();
378  last = container.rback_bottom_right();
379  }
380  };
381 
382 
383 
401  template<typename Container, typename _II>
402  void container_castR(Container& cont, _II& first, _II& last)
403  {
404  typedef typename std::iterator_traits<_II>::iterator_category _Category;
405  __container_iterator_castR<_Category>::container_iterator_castR(cont,first,last);
406  }
407 
408 }//::slip
409 
410 #endif //CONTAINER_CAST_HPP
void container_cast(Container &cont, _II &first, _II &last)
Get the default iterators of a SLIP container.
Provides a class to modelize the difference of slip::Point2d.
Provides a class to modelize the difference of slip::Point3d.
void reverse_container_cast(Container &cont, _II &first, _II &last)
Get the reverse default iterators of a SLIP container.
void container_castR(Container &cont, _II &first, _II &last)
Get the reverse default iterators of a SLIP container.
Difference of Point2D class, specialization of DPoint<CoordType,DIM> with DIM = 2.
Definition: Array2d.hpp:129