Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_FUN_OPS_HH 00027 # define MLN_FUN_OPS_HH 00028 00032 00033 # include <mln/core/concept/function.hh> 00034 # include <mln/fun/internal/selector.hh> 00035 # include <mln/trait/all.hh> 00036 00037 00038 00039 # define mln_decl_binary_expr_(In, Out, Name, Symbol) \ 00040 \ 00041 namespace fun \ 00042 { \ 00043 \ 00044 template <typename L, typename R> \ 00045 struct Name##_##Out##_expr_ \ 00046 : public Function_##Out < Name##_##Out##_expr_<L,R> > \ 00047 { \ 00048 typedef typename mln::trait::op:: Name < mln_result(L), \ 00049 mln_result(R) >::ret result; \ 00050 \ 00051 Name##_##Out##_expr_() \ 00052 { \ 00053 } \ 00054 \ 00055 Name##_##Out##_expr_(const L& l, const R& r) \ 00056 : l_(l), r_(r) \ 00057 { \ 00058 } \ 00059 \ 00060 template <typename P> \ 00061 result operator()(const P& p) const \ 00062 { \ 00063 return l_(p) Symbol r_(p); \ 00064 } \ 00065 \ 00066 protected: \ 00067 L l_; \ 00068 R r_; \ 00069 }; \ 00070 \ 00071 } \ 00072 \ 00073 namespace trait \ 00074 { \ 00075 \ 00076 template <typename L, typename R> \ 00077 struct set_binary_< op::Name, \ 00078 Function_##In, L, \ 00079 Function_##In, R > \ 00080 { \ 00081 typedef fun::Name##_##Out##_expr_<L,R> ret; \ 00082 }; \ 00083 } \ 00084 \ 00085 template <typename L, typename R> \ 00086 fun::Name##_##Out##_expr_<L,R> \ 00087 operator Symbol (const Function_##In<L>& lhs, const Function_##In<R>& rhs) \ 00088 { \ 00089 fun::Name##_##Out##_expr_<L,R> tmp(exact(lhs), exact(rhs)); \ 00090 return tmp; \ 00091 } \ 00092 \ 00093 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n 00094 00095 00096 # define mln_decl_unary_expr_(In, Out, Name, Symbol) \ 00097 \ 00098 namespace fun \ 00099 { \ 00100 \ 00101 template <typename F> \ 00102 struct Name##_##Out##_expr_ \ 00103 : public Function_##Out< Name##_##Out##_expr_<F> > \ 00104 { \ 00105 typedef typename mln::trait::op:: Name < mln_result(F) >::ret result; \ 00106 \ 00107 Name##_##Out##_expr_() \ 00108 { \ 00109 } \ 00110 \ 00111 Name##_##Out##_expr_(const F& f) \ 00112 : f_(f) \ 00113 { \ 00114 } \ 00115 \ 00116 template <typename P> \ 00117 result operator()(const P& p) const \ 00118 { \ 00119 return Symbol f_(p); \ 00120 } \ 00121 \ 00122 protected: \ 00123 F f_; \ 00124 }; \ 00125 \ 00126 } \ 00127 \ 00128 namespace trait \ 00129 { \ 00130 template <typename F> \ 00131 struct set_unary_< op::Name, \ 00132 Function_##In, F > \ 00133 { \ 00134 typedef fun::Name##_##Out##_expr_<F> ret; \ 00135 }; \ 00136 } \ 00137 \ 00138 template <typename F> \ 00139 fun::Name##_##Out##_expr_<F> \ 00140 operator Symbol (const Function_##In<F>& f) \ 00141 { \ 00142 fun::Name##_##Out##_expr_<F> tmp(exact(f)); \ 00143 return tmp; \ 00144 } \ 00145 \ 00146 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_u_m_n 00147 00148 00149 00150 namespace mln 00151 { 00152 00153 mln_decl_binary_expr_(v2v, v2b, eq, ==); 00154 mln_decl_binary_expr_(v2v, v2b, neq, !=); 00155 00156 mln_decl_binary_expr_(v2v, v2b, less, <); 00157 mln_decl_binary_expr_(v2v, v2b, leq , <=); 00158 mln_decl_binary_expr_(v2v, v2b, geq, >=); 00159 mln_decl_binary_expr_(v2v, v2b, greater, >); 00160 00161 mln_decl_binary_expr_(v2b, v2b, and_, &&); 00162 mln_decl_binary_expr_(v2b, v2b, or_, ||); 00163 mln_decl_binary_expr_(v2b, v2b, xor_, ^); 00164 00165 mln_decl_unary_expr_(v2b, v2b, not_, !); 00166 00167 mln_decl_binary_expr_(v2v, v2v, plus, +); 00168 mln_decl_binary_expr_(v2v, v2v, minus, -); 00169 mln_decl_binary_expr_(v2v, v2v, times, *); 00170 mln_decl_binary_expr_(v2v, v2v, div, /); 00171 mln_decl_binary_expr_(v2v, v2v, mod, %); 00172 00173 mln_decl_unary_expr_(v2v, v2v, uplus, +); 00174 mln_decl_unary_expr_(v2v, v2v, uminus, -); 00175 00176 } // end of namespace mln 00177 00178 00179 #endif // ! MLN_FUN_OPS_HH