$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ternary.hh
1 // Copyright (C) 2007, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_FUN_P2V_TERNARY_HH
27 # define MLN_FUN_P2V_TERNARY_HH
28 
34 # include <mln/fun/internal/selector.hh>
35 
36 
37 namespace mln
38 {
39 
40  namespace fun
41  {
42 
43  namespace p2v
44  {
45 
46  template <typename P, typename T, typename F>
47  struct ternary_
48  : fun::internal::selector_from_result_<mln_result(T), ternary_<P,T,F> >::ret
49  {
50  typedef mln_result(T) result;
51 
52  ternary_(const Function_v2b<P>& f_pred,
53  const Function_v2v<T>& f_true,
54  const Function_v2v<F>& f_false);
55 
56  template <typename Pt>
57  result operator()(const Pt& p) const;
58 
59  protected:
60  const P f_pred_;
61  const T f_true_;
62  const F f_false_;
63  };
64 
65 
66  template <typename P, typename T, typename F>
67  ternary_<P, T, F>
68  ternary(const Function_v2b<P>& f_pred,
69  const Function_v2v<T>& f_true,
70  const Function_v2v<F>& f_false);
71 
72 
73 # ifndef MLN_INCLUDE_ONLY
74 
75  template <typename P, typename T, typename F>
76  inline
78  const Function_v2v<T>& f_true,
79  const Function_v2v<F>& f_false)
80  : f_pred_(exact(f_pred)),
81  f_true_(exact(f_true)),
82  f_false_(exact(f_false))
83  {
84  }
85 
86  template <typename P, typename T, typename F>
87  template <typename Pt>
88  inline
89  mln_result(T)
90  ternary_<P,T,F>::operator()(const Pt& p) const
91  {
92  return f_pred_(p) ? f_true_(p) : f_false_(p);
93  }
94 
95 
96  template <typename P, typename T, typename F>
97  inline
98  ternary_<P, T, F>
99  ternary(const Function_v2b<P>& f_pred,
100  const Function_v2v<T>& f_true,
101  const Function_v2v<F>& f_false)
102  {
103  ternary_<P, T, F> tmp(exact(f_pred),
104  exact(f_true),
105  exact(f_false));
106  return tmp;
107  }
108 
109 # endif // ! MLN_INCLUDE_ONLY
110 
111  } // end of namespace mln::fun::p2v
112 
113  } // end of namespace mln::fun
114 
115 } // end of namespace mln
116 
117 
118 #endif // ! MLN_FUN_P2V_TERNARY_HH