optraits_real_defs.hh

00001 // Copyright (C) 2001, 2002, 2003  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef NTG_OPTRAITS_REAL_DEFS_HH
00029 # define NTG_OPTRAITS_REAL_DEFS_HH
00030 
00031 //
00032 // macros used in optraits_real definition
00033 //
00035 
00036 # define ASSIGN_SCALAR_OPERATOR(Name)                                   \
00037   template <class T1, class T2> inline                                  \
00038   static T1& Name##_equal(T1& lhs, const T2& rhs)                       \
00039   {                                                                     \
00040     ntg_is_a(T1, ntg::real)::ensure();                                  \
00041     ntg_is_a(T2, ntg::real)::ensure();                                  \
00042                                                                         \
00043     return Name##_equal_impl<T1,T2>(lhs, rhs);                          \
00044   }                                                                     \
00045                                                                         \
00046   template <class T1, class T2> inline                                  \
00047   static T1&                                                            \
00048   Name##_equal_impl(ntg::real_value<T1>& lhs,                           \
00049                     const ntg::real_value<T2>& rhs)                     \
00050   {                                                                     \
00051     typedef typename typetraits<T1>::behavior_type behavior_type;       \
00052     lhs.exact() = behavior_type::check_##Name(lhs.exact().val(),        \
00053                                               rhs.exact().val());       \
00054     return lhs.exact();                                                 \
00055   }                                                                     \
00056                                                                         \
00057   template <class T1, class T2> inline                                  \
00058   static T1&                                                            \
00059   Name##_equal_impl(ntg::real_value<T1>& lhs,                           \
00060                     const ntg::any_const_class<T2> rhs)                 \
00061   {                                                                     \
00062     typedef typename typetraits<T1>::behavior_type behavior_type;       \
00063     lhs.exact() = behavior_type::check_##Name(lhs.exact().val(),        \
00064                                               rhs.exact());             \
00065     return lhs.exact();                                                 \
00066   }                                                                     \
00067                                                                         \
00068   template <class T1, class T2> inline                                  \
00069   static T1&                                                            \
00070   Name##_equal_impl(ntg::any_class<T1> lhs,                             \
00071                     const ntg::real_value<T2>& rhs)                     \
00072   {                                                                     \
00073     typedef typename typetraits<T1>::behavior_type behavior_type;       \
00074     lhs.exact() = behavior_type::check_##Name(lhs.exact(),              \
00075                                               rhs.exact().val());       \
00076     return lhs.exact();                                                 \
00077   }
00078 
00079 # define ARITH_SCALAR_OPERATOR(Name)                                    \
00080   template <class T1, class T2> inline                                  \
00081   static ntg_return_type(Name, T1, T2)                                  \
00082   Name(const T1& lhs, const T2& rhs)                                    \
00083   {                                                                     \
00084     ntg_is_a(T1, ntg::real)::ensure();                                  \
00085     ntg_is_a(T2, ntg::real)::ensure();                                  \
00086                                                                         \
00087     return Name##_impl<T1,T2>(lhs, rhs);                                \
00088   }                                                                     \
00089                                                                         \
00090   template <class T1, class T2> inline                                  \
00091   static ntg_return_type(Name, T1, T2)                                  \
00092   Name##_impl(const ntg::real_value<T1>& lhs,                           \
00093               const ntg::real_value<T2>& rhs)                           \
00094   {                                                                     \
00095     typedef ntg_return_type(Name, T1, T2) return_type;                  \
00096     typedef typename                                                    \
00097       typetraits<E>::abstract_behavior_type::get<return_type>   \
00098         behavior_type;                                                  \
00099     return_type tmp;                                                    \
00100     tmp = behavior_type::check_##Name(lhs.exact().val(),                \
00101                                       rhs.exact().val());               \
00102     return tmp;                                                         \
00103   }                                                                     \
00104                                                                         \
00105   template <class T1, class T2> inline                                  \
00106   static ntg_return_type(Name, T1, T2)                                  \
00107   Name##_impl(const ntg::real_value<T1>& lhs,                           \
00108               const ntg::any_const_class<T2>& rhs)                      \
00109   {                                                                     \
00110     typedef ntg_return_type(Name, T1, T2) return_type;                  \
00111     typedef typename                                                    \
00112       typetraits<E>::abstract_behavior_type::get<return_type>   \
00113         behavior_type;                                                  \
00114     return_type tmp;                                                    \
00115     tmp = behavior_type::check_##Name(lhs.exact().val(),                \
00116                                       rhs.exact());                     \
00117     return tmp;                                                         \
00118   }                                                                     \
00119                                                                         \
00120   template <class T1, class T2> inline                                  \
00121   static ntg_return_type(Name, T1, T2)                                  \
00122   Name##_impl(const ntg::any_const_class<T1>& lhs,                      \
00123               const ntg::real_value<T2>& rhs)                           \
00124   {                                                                     \
00125     typedef ntg_return_type(Name, T1, T2) return_type;                  \
00126     typedef typename                                                    \
00127       typetraits<E>::abstract_behavior_type::get<return_type>   \
00128         behavior_type;                                                  \
00129     return_type tmp;                                                    \
00130     tmp = behavior_type::check_##Name(lhs.exact(),                      \
00131                                       rhs.exact().val());               \
00132     return tmp;                                                         \
00133   }
00134 
00135 # define CMP_SCALAR_OPERATOR(Name, Op)                          \
00136   template <class T1, class T2> inline                          \
00137   static bool Name (const T1& lhs, const T2& rhs)               \
00138   {                                                             \
00139     ntg_is_a(T1, ntg::real)::ensure();                          \
00140     ntg_is_a(T2, ntg::real)::ensure();                          \
00141                                                                 \
00142     typedef ntg_return_type(cmp, T1, T2) tmp_type;              \
00143                                                                 \
00144     return Name##_impl<tmp_type>(static_cast<tmp_type>(lhs),    \
00145                                  static_cast<tmp_type>(rhs));   \
00146   }                                                             \
00147                                                                 \
00148   template <class T> inline                                     \
00149   static bool                                                   \
00150   Name##_impl(const ntg::real_value<T>& lhs,                    \
00151               const ntg::real_value<T>& rhs)                    \
00152   { return lhs.exact().val() Op rhs.exact().val(); }            \
00153                                                                 \
00154   template <class T> inline                                     \
00155   static bool                                                   \
00156   Name##_impl(const ntg::any_const_class<T> lhs,                \
00157               const ntg::any_const_class<T> rhs)                \
00158   { return lhs.exact() Op rhs.exact(); }
00159 
00160 
00161 //
00162 //  Macros for optraits_int
00163 //
00165 
00166 # define ASSIGN_INT_OPERATOR(Name, Op)                                  \
00167   template <class T1, class T2> inline                                  \
00168   static T1& Name(T1& lhs, const T2& rhs)                               \
00169   {                                                                     \
00170     ntg_is_a(T1, ntg::integer)::ensure();                               \
00171     ntg_is_a(T2, ntg::integer)::ensure();                               \
00172                                                                         \
00173     return Name##_impl<T1,T2>(lhs, rhs);                                \
00174   }                                                                     \
00175                                                                         \
00176   template <class T1, class T2> inline                                  \
00177   static T1& Name##_impl(int_value<T1>& lhs, const int_value<T2>& rhs)  \
00178   {                                                                     \
00179     lhs.exact() = lhs.exact().val() Op rhs.exact().val();               \
00180     return lhs.exact();                                                 \
00181   }                                                                     \
00182                                                                         \
00183   template <class T1, class T2> inline                                  \
00184   static T1& Name##_impl(int_value<T1>& lhs,                            \
00185                          const ntg::any_const_class<T2>& rhs)           \
00186   {                                                                     \
00187     lhs.exact() = lhs.exact().val() Op rhs.exact();                     \
00188     return lhs.exact();                                                 \
00189   }                                                                     \
00190                                                                         \
00191   template <class T1, class T2> inline                                  \
00192   static T1& Name##_impl(ntg::any_class<T1>& lhs,                       \
00193                          const int_value<T2>& rhs)                      \
00194   {                                                                     \
00195     lhs.exact() = lhs.exact() Op rhs.exact().val();                     \
00196     return lhs.exact();                                                 \
00197   }    
00198 
00199 # define ARITH_INT_OPERATOR(Name, Op)                   \
00200   template <class T1, class T2> inline                  \
00201   static ntg_return_type(Name, T1, T2)                  \
00202   Name(const T1& lhs, const T2& rhs)                    \
00203   {                                                     \
00204     ntg_is_a(T1, integer)::ensure();                    \
00205     ntg_is_a(T2, integer)::ensure();                    \
00206                                                         \
00207     typedef ntg_return_type(Name, T1, T2) return_type;  \
00208     return_type result(lhs);                            \
00209     result Op rhs;                                      \
00210     return result;                                      \
00211   }
00212 
00213 #endif // ndef NTG_OPTRAITS_REAL_DEFS_HH

Generated on Thu Apr 15 20:13:13 2004 for Olena by doxygen 1.3.6-20040222