$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fun/ops.hh
1 // Copyright (C) 2007, 2008, 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_OPS_HH
27 # define MLN_FUN_OPS_HH
28 
32 
33 # include <mln/core/concept/function.hh>
34 # include <mln/fun/internal/selector.hh>
35 # include <mln/trait/all.hh>
36 
37 
38 
39 # define mln_decl_binary_expr_(In, Out, Name, Symbol) \
40  \
41  namespace fun \
42  { \
43  \
44  template <typename L, typename R> \
45  struct Name##_##Out##_expr_ \
46  : public Function_##Out < Name##_##Out##_expr_<L,R> > \
47  { \
48  typedef typename mln::trait::op:: Name < mln_result(L), \
49  mln_result(R) >::ret result; \
50  \
51  Name##_##Out##_expr_() \
52  { \
53  } \
54  \
55  Name##_##Out##_expr_(const L& l, const R& r) \
56  : l_(l), r_(r) \
57  { \
58  } \
59  \
60  template <typename P> \
61  result operator()(const P& p) const \
62  { \
63  return l_(p) Symbol r_(p); \
64  } \
65  \
66  protected: \
67  L l_; \
68  R r_; \
69  }; \
70  \
71  } \
72  \
73  namespace trait \
74  { \
75  \
76  template <typename L, typename R> \
77  struct set_binary_< op::Name, \
78  Function_##In, L, \
79  Function_##In, R > \
80  { \
81  typedef fun::Name##_##Out##_expr_<L,R> ret; \
82  }; \
83  } \
84  \
85  template <typename L, typename R> \
86  fun::Name##_##Out##_expr_<L,R> \
87  operator Symbol (const Function_##In<L>& lhs, const Function_##In<R>& rhs) \
88  { \
89  fun::Name##_##Out##_expr_<L,R> tmp(exact(lhs), exact(rhs)); \
90  return tmp; \
91  } \
92  \
93  struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
94 
95 
96 # define mln_decl_unary_expr_(In, Out, Name, Symbol) \
97  \
98  namespace fun \
99  { \
100  \
101  template <typename F> \
102  struct Name##_##Out##_expr_ \
103  : public Function_##Out< Name##_##Out##_expr_<F> > \
104  { \
105  typedef typename mln::trait::op:: Name < mln_result(F) >::ret result; \
106  \
107  Name##_##Out##_expr_() \
108  { \
109  } \
110  \
111  Name##_##Out##_expr_(const F& f) \
112  : f_(f) \
113  { \
114  } \
115  \
116  template <typename P> \
117  result operator()(const P& p) const \
118  { \
119  return Symbol f_(p); \
120  } \
121  \
122  protected: \
123  F f_; \
124  }; \
125  \
126  } \
127  \
128  namespace trait \
129  { \
130  template <typename F> \
131  struct set_unary_< op::Name, \
132  Function_##In, F > \
133  { \
134  typedef fun::Name##_##Out##_expr_<F> ret; \
135  }; \
136  } \
137  \
138  template <typename F> \
139  fun::Name##_##Out##_expr_<F> \
140  operator Symbol (const Function_##In<F>& f) \
141  { \
142  fun::Name##_##Out##_expr_<F> tmp(exact(f)); \
143  return tmp; \
144  } \
145  \
146  struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n
147 
148 
149 
150 namespace mln
151 {
152 
153  mln_decl_binary_expr_(v2v, v2b, eq, ==);
154  mln_decl_binary_expr_(v2v, v2b, neq, !=);
155 
156  mln_decl_binary_expr_(v2v, v2b, less, <);
157  mln_decl_binary_expr_(v2v, v2b, leq , <=);
158  mln_decl_binary_expr_(v2v, v2b, geq, >=);
159  mln_decl_binary_expr_(v2v, v2b, greater, >);
160 
161  mln_decl_binary_expr_(v2b, v2b, and_, &&);
162  mln_decl_binary_expr_(v2b, v2b, or_, ||);
163  mln_decl_binary_expr_(v2b, v2b, xor_, ^);
164 
165  mln_decl_unary_expr_(v2b, v2b, not_, !);
166 
167  mln_decl_binary_expr_(v2v, v2v, plus, +);
168  mln_decl_binary_expr_(v2v, v2v, minus, -);
169  mln_decl_binary_expr_(v2v, v2v, times, *);
170  mln_decl_binary_expr_(v2v, v2v, div, /);
171  mln_decl_binary_expr_(v2v, v2v, mod, %);
172 
173  mln_decl_unary_expr_(v2v, v2v, uplus, +);
174  mln_decl_unary_expr_(v2v, v2v, uminus, -);
175 
176 } // end of namespace mln
177 
178 
179 #endif // ! MLN_FUN_OPS_HH