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_LITERAL_OPS_HH
00027 # define MLN_LITERAL_OPS_HH
00028 
00035 # include <mln/core/concept/literal.hh>
00036 # include <mln/trait/all.hh>
00037 # include <mln/metal/equal.hh>
00038 # include <mln/metal/converts_to.hh>
00039 
00040 
00041 
00042 namespace mln
00043 {
00044 
00045 
00046   namespace trait
00047   {
00048 
00049     template < template <class, class> class Name,
00050                typename L, typename O >
00051     struct set_binary_< Name, mln::Literal, L, mln::Object, O >
00052     {
00053       typedef mln_trait_binary(Name, O, O) ret;
00054     };
00055 
00056     template < template <class, class> class Name,
00057                typename O, typename L >
00058     struct set_binary_< Name, mln::Object, O, mln::Literal, L >
00059     {
00060       typedef mln_trait_binary(Name, O, O) ret;
00061     };
00062 
00063     template < typename L1, typename L2 >
00064     struct set_binary_< op::eq, mln::Literal, L1, mln::Literal, L2 >
00065     {
00066       typedef bool ret;
00067     };
00068 
00069     template < typename L1, typename L2 >
00070     struct set_binary_< op::neq, mln::Literal, L1, mln::Literal, L2 >
00071     {
00072       typedef bool ret;
00073     };
00074 
00075   } 
00076 
00077 
00078   
00079 
00080   template <typename O, typename L>
00081   mln_trait_op_plus(O, O)
00082   operator+(const Object<O>& lhs, const Literal<L>& rhs);
00083 
00084   template <typename L, typename O>
00085   mln_trait_op_plus(O, O)
00086   operator+(const Literal<L>& lhs, const Object<O>& rhs);
00087 
00088   template <typename O, typename L>
00089   mln_trait_op_minus(O, O)
00090   operator-(const Object<O>& lhs, const Literal<L>& rhs);
00091 
00092   template <typename L, typename O>
00093   mln_trait_op_minus(O, O)
00094   operator-(const Literal<L>& lhs, const Object<O>& rhs);
00095 
00096   template <typename O, typename L>
00097   mln_trait_op_times(O, O)
00098   operator*(const Object<O>& lhs, const Literal<L>& rhs);
00099 
00100   template <typename L, typename O>
00101   mln_trait_op_times(O, O)
00102   operator*(const Literal<L>& lhs, const Object<O>& rhs);
00103 
00104   template <typename O, typename L>
00105   mln_trait_op_div(O, O)
00106   operator/(const Object<O>& lhs, const Literal<L>& rhs);
00107 
00108   template <typename L, typename O>
00109   mln_trait_op_div(O, O)
00110   operator/(const Literal<L>& lhs, const Object<O>& rhs);
00111 
00112   template <typename O, typename L>
00113   mln_trait_op_mod(O, O)
00114   operator%(const Object<O>& lhs, const Literal<L>& rhs);
00115 
00116   template <typename L, typename O>
00117   mln_trait_op_mod(O, O)
00118   operator%(const Literal<L>& lhs, const Object<O>& rhs);
00119 
00120 
00121   
00122 
00123   template <typename O, typename L>
00124   mln_trait_op_eq(O, O)
00125   operator==(const Object<O>& lhs, const Literal<L>& rhs);
00126 
00127   template <typename L, typename O>
00128   mln_trait_op_eq(O, O)
00129   operator==(const Literal<L>& lhs, const Object<O>& rhs);
00130 
00131   template <typename L1, typename L2>
00132   bool operator==(const Literal<L1>& lhs, const Literal<L2>& rhs);
00133 
00134   
00135 
00136 
00137 
00138 # ifndef MLN_INCLUDE_ONLY
00139 
00140   
00141   
00142 
00143 
00144   
00145 
00146   template <typename O, typename L>
00147   inline
00148   mln_trait_op_plus(O, O)
00149   operator+(const Object<O>& lhs, const Literal<L>& rhs)
00150   {
00151     
00152     return exact(lhs) + O(exact(rhs));
00153   }
00154 
00155   template <typename L, typename O>
00156   inline
00157   mln_trait_op_plus(O, O)
00158   operator+(const Literal<L>& lhs, const Object<O>& rhs)
00159   {
00160     
00161     return O(exact(lhs)) + exact(rhs);
00162   }
00163 
00164   
00165 
00166   template <typename O, typename L>
00167   inline
00168   mln_trait_op_minus(O, O)
00169   operator-(const Object<O>& lhs, const Literal<L>& rhs)
00170   {
00171     
00172     return exact(lhs) - O(exact(rhs));
00173   }
00174 
00175   template <typename L, typename O>
00176   inline
00177   mln_trait_op_minus(O, O)
00178   operator-(const Literal<L>& lhs, const Object<O>& rhs)
00179   {
00180     
00181     return O(exact(lhs)) - exact(rhs);
00182   }
00183 
00184   
00185 
00186   template <typename O, typename L>
00187   inline
00188   mln_trait_op_times(O, O)
00189   operator*(const Object<O>& lhs, const Literal<L>& rhs)
00190   {
00191     
00192     return exact(lhs) * O(exact(rhs));
00193   }
00194 
00195   template <typename L, typename O>
00196   inline
00197   mln_trait_op_times(O, O)
00198   operator*(const Literal<L>& lhs, const Object<O>& rhs)
00199   {
00200     
00201     return O(exact(lhs)) * exact(rhs);
00202   }
00203 
00204   
00205 
00206   template <typename O, typename L>
00207   inline
00208   mln_trait_op_div(O, O)
00209   operator/(const Object<O>& lhs, const Literal<L>& rhs)
00210   {
00211     
00212     return exact(lhs) / O(exact(rhs));
00213   }
00214 
00215   template <typename L, typename O>
00216   inline
00217   mln_trait_op_div(O, O)
00218   operator/(const Literal<L>& lhs, const Object<O>& rhs)
00219   {
00220     
00221     return O(exact(lhs)) / exact(rhs);
00222   }
00223 
00224   
00225 
00226   template <typename O, typename L>
00227   inline
00228   mln_trait_op_mod(O, O)
00229   operator%(const Object<O>& lhs, const Literal<L>& rhs)
00230   {
00231     
00232     return exact(lhs) % O(exact(rhs));
00233   }
00234 
00235   template <typename L, typename O>
00236   inline
00237   mln_trait_op_mod(O, O)
00238   operator%(const Literal<L>& lhs, const Object<O>& rhs)
00239   {
00240     
00241     return O(exact(lhs)) % exact(rhs);
00242   }
00243 
00244 
00245   
00246 
00247   template <typename O, typename L>
00248   inline
00249   mln_trait_op_eq(O, O)
00250   operator==(const Object<O>& lhs, const Literal<L>& rhs)
00251   {
00252     
00253     return exact(lhs) == O(exact(rhs));
00254   }
00255 
00256   template <typename L, typename O>
00257   inline
00258   mln_trait_op_eq(O, O)
00259   operator==(const Literal<L>& lhs, const Object<O>& rhs)
00260   {
00261     
00262     return O(exact(lhs)) == exact(rhs);
00263   }
00264 
00265   template <typename L1, typename L2>
00266   inline
00267   bool
00268   operator==(const Literal<L1>&, const Literal<L2>&)
00269   {
00270     return mlc_equal(L1, L2)::value;
00271   }
00272 
00273   
00274 
00275 # endif // ! MLN_INCLUDE_ONLY
00276 
00277 } 
00278 
00279 
00280 #endif // ! MLN_LITERAL_OPS_HH