00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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 } 
00177 
00178 
00179 #endif // ! MLN_FUN_OPS_HH