SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
apply.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_APPLY_HPP
75 #define SLIP_APPLY_HPP
76 
77 #include <cmath>
78 #include <iterator>
79 
80 namespace slip
81 {
82 
84  /* @{ */
126  template<typename InputIterator, typename OutputIterator>
127  inline
128  void apply(InputIterator first, InputIterator last,
129  OutputIterator result,
130  typename std::iterator_traits<OutputIterator>::value_type
131  (*function)(typename std::iterator_traits<InputIterator>::value_type))
132  {
133  for (;first!=last;++first,++result)
134  *result=(*function)(*first);
135  }
136 
137 
173 template<typename InputIterator,typename OutputIterator,typename MaskIterator>
174  inline
175  void apply_mask(InputIterator first,
176  InputIterator last,
177  MaskIterator mask_first,
178  OutputIterator result,
179  typename std::iterator_traits<OutputIterator>::value_type (*function)(typename std::iterator_traits<InputIterator>::value_type),
180  typename std::iterator_traits<MaskIterator>::value_type value=typename std::iterator_traits<MaskIterator>::value_type(1))
181 {
182  for (;first!=last;++first,++result,++mask_first)
183  {
184  if(*mask_first == value)
185  {
186  *result=(*function)(*first);
187  }
188  }
189  }
230 template<typename InputIterator,typename OutputIterator,typename Predicate>
231  inline
232  void apply_if(InputIterator first,
233  InputIterator last,
234  OutputIterator result,
235  Predicate pred,
236  typename std::iterator_traits<OutputIterator>::value_type (*function)(typename std::iterator_traits<InputIterator>::value_type))
237 {
238  for (;first!=last;++first,++result)
239  {
240  if(pred(*first))
241  {
242  *result=(*function)(*first);
243  }
244  }
245  }
246  /* @} */
247 
249  /* @{ */
290  template<typename InputIterator, typename OutputIterator>
291  inline
292  void apply(InputIterator first, InputIterator last,
293  OutputIterator result,
294  typename std::iterator_traits<OutputIterator>::value_type
295  (*function)(const typename std::iterator_traits<InputIterator>::value_type&))
296  {
297  for (;first!=last;++first,++result)
298  *result=(*function)(*first);
299  }
300 
301 
302 
340 template<typename InputIterator,typename OutputIterator,typename MaskIterator>
341  inline
342  void apply_mask(InputIterator first,
343  InputIterator last,
344  MaskIterator mask_first,
345  OutputIterator result,
346  typename std::iterator_traits<OutputIterator>::value_type (*function)(const typename std::iterator_traits<InputIterator>::value_type&),
347  typename std::iterator_traits<MaskIterator>::value_type value=typename
348  std::iterator_traits<MaskIterator>::value_type(1))
349 {
350 
351  for (;first!=last;++first,++result,++mask_first)
352  {
353  if(*mask_first == value)
354  {
355  *result=(*function)(*first);
356  }
357  }
358  }
399 template<typename InputIterator,typename OutputIterator,typename Predicate>
400  inline
401  void apply_if(InputIterator first,
402  InputIterator last,
403  OutputIterator result,
404  Predicate pred,
405  typename std::iterator_traits<OutputIterator>::value_type (*function)(const typename std::iterator_traits<InputIterator>::value_type&))
406 {
407 
408  for (;first!=last;++first,++result)
409  {
410  if(pred(*first))
411  {
412  *result=(*function)(*first);
413  }
414  }
415  }
416  /* @} */
417 
419  /* @{ */
465  template<typename InputIterator1,
466  typename InputIterator2,
467  typename OutputIterator>
468  inline
469  void apply(InputIterator1 first, InputIterator1 last,
470  InputIterator2 first2,
471  OutputIterator result,
472  typename std::iterator_traits<OutputIterator>::value_type
473  (*function)(typename std::iterator_traits<InputIterator1>::value_type,
474  typename std::iterator_traits<InputIterator2>::value_type ))
475  {
476  for (;first!=last;++first,++first2,++result)
477  *result=(*function)(*first,*first2);
478  }
479 
480 
520 template<typename InputIterator1,
521  typename InputIterator2,
522  typename OutputIterator,
523  typename MaskIterator>
524  inline
525  void apply_mask(InputIterator1 first,
526  InputIterator1 last,
527  MaskIterator mask_first,
528  InputIterator2 first2,
529  OutputIterator result,
530 
531  typename std::iterator_traits<OutputIterator>::value_type
532  (*function)(typename std::iterator_traits<InputIterator1>::value_type,
533  typename std::iterator_traits<InputIterator2>::value_type ),
534  typename std::iterator_traits<MaskIterator>::value_type value=typename
535  std::iterator_traits<MaskIterator>::value_type(1))
536 
537 {
538  for (;first!=last;++first,++first2,++result,++mask_first)
539  if(*mask_first == value)
540  {
541  *result=(*function)(*first,*first2);
542  }
543  }
544 
589 template<typename InputIterator1,
590  typename InputIterator2,
591  typename OutputIterator,
592  typename Predicate>
593  inline
594  void apply_if(InputIterator1 first,
595  InputIterator1 last,
596  InputIterator2 first2,
597  OutputIterator result,
598  Predicate pred,
599  typename std::iterator_traits<OutputIterator>::value_type
600  (*function)(typename std::iterator_traits<InputIterator1>::value_type,
601  typename std::iterator_traits<InputIterator2>::value_type ))
602 
603 {
604  for (;first!=last;++first,++first2,++result)
605  if(pred(*first))
606  {
607  *result=(*function)(*first,*first2);
608  }
609  }
610 /* @} */
611 
613  /* @{ */
660  template<typename InputIterator1,
661  typename InputIterator2,
662  typename OutputIterator>
663  inline
664  void apply(InputIterator1 first, InputIterator1 last,
665  InputIterator2 first2,
666  OutputIterator result,
667  typename std::iterator_traits<OutputIterator>::value_type
668  (*function)(const typename std::iterator_traits<InputIterator1>::value_type&, const typename std::iterator_traits<InputIterator2>::value_type& ))
669  {
670  for (;first!=last;++first,++first2,++result)
671  *result=(*function)(*first,*first2);
672  }
673 
674 
714 template<typename InputIterator1,
715  typename InputIterator2,
716  typename OutputIterator,
717  typename MaskIterator>
718  inline
719  void apply_mask(InputIterator1 first,
720  InputIterator1 last,
721  MaskIterator mask_first,
722  InputIterator2 first2,
723  OutputIterator result,
724 
725  typename std::iterator_traits<OutputIterator>::value_type
726  (*function)(const typename std::iterator_traits<InputIterator1>::value_type&, const typename std::iterator_traits<InputIterator2>::value_type& ),
727  typename std::iterator_traits<MaskIterator>::value_type value=typename
728  std::iterator_traits<MaskIterator>::value_type(1))
729 
730 {
731  for (;first!=last;++first,++first2,++result,++mask_first)
732  if(*mask_first == value)
733  {
734  *result=(*function)(*first,*first2);
735  }
736  }
737 
781 template<typename InputIterator1,
782  typename InputIterator2,
783  typename OutputIterator,typename Predicate>
784  inline
785  void apply_if(InputIterator1 first,
786  InputIterator1 last,
787  InputIterator2 first2,
788  OutputIterator result,
789  Predicate pred,
790  typename std::iterator_traits<OutputIterator>::value_type
791  (*function)(const typename std::iterator_traits<InputIterator1>::value_type&, const typename std::iterator_traits<InputIterator2>::value_type& ))
792 
793 {
794  for (;first!=last;++first,++first2,++result)
795  if(pred(*first))
796  {
797  *result=(*function)(*first,*first2);
798  }
799  }
800 /* @} */
801 
802 }//slip::
803 
804 
805 #endif //SLIP_APPLY_HPP
void apply_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator result, typename std::iterator_traits< OutputIterator >::value_type(*function)(typename std::iterator_traits< InputIterator >::value_type), typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Applies a C-function to each element of a range according to a mask range.
Definition: apply.hpp:175
void apply(InputIterator first, InputIterator last, OutputIterator result, typename std::iterator_traits< OutputIterator >::value_type(*function)(typename std::iterator_traits< InputIterator >::value_type))
Applies a C-function to each element of a range.
Definition: apply.hpp:128
void apply_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, typename std::iterator_traits< OutputIterator >::value_type(*function)(typename std::iterator_traits< InputIterator >::value_type))
Applies a C-function to each element of a range according to a predicate.
Definition: apply.hpp:232