• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

ops.hh

00001 // Copyright (C) 2007, 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_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   } // end of namespace mln::trait
00076 
00077 
00078   // Arithmetical operators.
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   // Operator equal.
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   // FIXME: ... 
00135 
00136 
00137 
00138 # ifndef MLN_INCLUDE_ONLY
00139 
00140   // FIXME: Static assertion code de-activated because when O's ctor
00141   // is explicit from literal the metal program does not compile...
00142 
00143 
00144   // Op +
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     // mlc_converts_to(L, O)::check();
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     // mlc_converts_to(L, O)::check();
00161     return O(exact(lhs)) + exact(rhs);
00162   }
00163 
00164   // Op -
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     // mlc_converts_to(L, O)::check();
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     // mlc_converts_to(L, O)::check();
00181     return O(exact(lhs)) - exact(rhs);
00182   }
00183 
00184   // Op *
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     // mlc_converts_to(L, O)::check();
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     // mlc_converts_to(L, O)::check();
00201     return O(exact(lhs)) * exact(rhs);
00202   }
00203 
00204   // Op /
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     // mlc_converts_to(L, O)::check();
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     // mlc_converts_to(L, O)::check();
00221     return O(exact(lhs)) / exact(rhs);
00222   }
00223 
00224   // Op %
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     // mlc_converts_to(L, O)::check();
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     // mlc_converts_to(L, O)::check();
00241     return O(exact(lhs)) % exact(rhs);
00242   }
00243 
00244 
00245   // Op ==
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     // mlc_converts_to(L, O)::check();
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     // mlc_converts_to(L, O)::check();
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   // FIXME: Add less, etc.
00274 
00275 # endif // ! MLN_INCLUDE_ONLY
00276 
00277 } // end of namespace mln
00278 
00279 
00280 #endif // ! MLN_LITERAL_OPS_HH

Generated on Tue Oct 4 2011 15:24:07 for Milena (Olena) by  doxygen 1.7.1