global_ops_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_CORE_INTERNAL_GLOBAL_OPS_DEFS_HH
00029 # define NTG_CORE_INTERNAL_GLOBAL_OPS_DEFS_HH
00030 
00031 /*
00032   Global operators macros, used to factorize global operators
00033   definitions.
00034 */
00035 
00036 /*
00037   For every operator, we need a specialization for every builtin type
00038   to avoid overloading problems. So here are the defined operators: 
00039 
00040   operatorX(ntg_type, T2) (1)
00041   operatorX(builtin1, T2) (2)
00042   operatorX(builtin2, T2)
00043   ...
00044   
00045   This handles all cases without ambiguity: 
00046   
00047   ntg_type X ntg_type ==> (1)
00048   ntg_type X builtin  ==> (1)
00049   builtin1 X ntg_type ==> (2)
00050 */
00051 
00052 /*-------------.
00053 | ASSIGNEMENTS |
00054 `-------------*/
00055 
00056 /*---------------------------------.
00057 | Global assignements for builtins |
00058 `---------------------------------*/
00059 
00060 # define GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, Builtin)    \
00061 template <class T2> inline                              \
00062 Builtin&                                                \
00063 Op(Builtin& lhs, const value<T2>& rhs)                  \
00064 { return optraits<Builtin>::Name(lhs, rhs.exact()); }
00065 
00066 /*-----------------------------------------------.
00067 | Global assignements for ntg_types and builtins |
00068 `------------------------------------------------*/
00069 
00070 # define GLOBAL_ASSIGN_OP_BUILTIN_INT(Op, Name)         \
00071 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed   long)       \
00072 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned long)       \
00073 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed   int)        \
00074 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned int)        \
00075 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed   short)      \
00076 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned short)      \
00077 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, char)                \
00078 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, signed   char)       \
00079 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, unsigned char)
00080 
00081 # define GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(Op, Name)       \
00082 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, float)               \
00083 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, double)
00084 
00085 # define GLOBAL_ASSIGN_OP_BUILTIN_BOOL(Op, Name)        \
00086 GLOBAL_ASSIGN_OP_BUILTIN(Op, Name, bool)
00087 
00088 # define GLOBAL_ASSIGN_OP(Op, Name)             \
00089 template <class T1, class T2> inline            \
00090 T1&                                             \
00091 Op(value<T1>& lhs, const T2& rhs)               \
00092 { return optraits<T1>::Name(lhs.exact(), rhs); }
00093 
00094 /*---------------------.
00095 | ARITHMETIC OPERATORS |
00096 `---------------------*/
00097 
00098 /*-----------------------------------------.
00099 | Global arithmetic operators for builtins |
00100 `-----------------------------------------*/
00101 
00102 # define GLOBAL_ARITH_OP_BUILTIN(Op, Name, Builtin)                     \
00103 template <class T2> inline                                              \
00104 ntg_return_type(Name, Builtin, T2)                                      \
00105 Op(Builtin lhs, const value<T2>& rhs)                                   \
00106 {                                                                       \
00107   typedef ntg_deduced_traits_type(Name, Builtin, T2) deduced_type;      \
00108                                                                         \
00109   typedef typename deduced_type::impl impl;                             \
00110   typedef typename deduced_type::lhs_type lhs_type;                     \
00111   typedef typename deduced_type::rhs_type rhs_type;                     \
00112                                                                         \
00113   return optraits<impl>::Name(static_cast<lhs_type>(lhs),               \
00114                               static_cast<rhs_type>(rhs.exact()));      \
00115 }
00116 
00117 /*------------------------------------------------------------.
00118 | Global arithmetic operators for both ntg_types and builtins |
00119 `------------------------------------------------------------*/
00120 
00121 # define GLOBAL_ARITH_OP(Op, Name)                                      \
00122 template <class T1, class T2> inline                                    \
00123 ntg_return_type(Name, T1, T2)                                           \
00124 Op(const value<T1>& lhs, const T2& rhs)                                 \
00125 {                                                                       \
00126  /*                                                                     \
00127    This code is an example of debugging information, disabled until     \
00128    a good way to handle debug is found.                                 \
00129   */                                                                    \
00130                                                                         \
00131  /*                                                                     \
00132  if (ntg_is_debug_active)                                               \
00133  {                                                                      \
00134      std::ostringstream s;                                              \
00135      s << typename_of<ntg_return_type(Name, T1, T2)>() << " "           \
00136                << #Op << "(" << typename_of<T1>() << " lhs, "           \
00137             << typename_of<T2>() << " rhs)"  << std::endl               \
00138      << "\twith lhs = " << lhs.exact() << " and rhs = " << rhs;         \
00139      ntg_debug_context_set(s.str());                                    \
00140  }                                                                      \
00141  */                                                                     \
00142                                                                         \
00143   typedef ntg_deduced_traits_type(Name, T1, T2) deduced_type;           \
00144                                                                         \
00145   typedef typename deduced_type::impl impl;                             \
00146   typedef typename deduced_type::lhs_type lhs_type;                     \
00147   typedef typename deduced_type::rhs_type rhs_type;                     \
00148                                                                         \
00149   return optraits<impl>::Name(static_cast<lhs_type>(lhs.exact()),       \
00150                               static_cast<rhs_type>(rhs));              \
00151 }                                                                       \
00152                                                                         \
00153 GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed   long)                        \
00154 GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned long)                        \
00155 GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed   int)                 \
00156 GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned int)                 \
00157 GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed   short)                       \
00158 GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned short)                       \
00159 GLOBAL_ARITH_OP_BUILTIN(Op, Name, signed   char)                        \
00160 GLOBAL_ARITH_OP_BUILTIN(Op, Name, unsigned char)                        \
00161 GLOBAL_ARITH_OP_BUILTIN(Op, Name, char)                         \
00162 GLOBAL_ARITH_OP_BUILTIN(Op, Name, float)                                \
00163 GLOBAL_ARITH_OP_BUILTIN(Op, Name, double)                               \
00164 GLOBAL_ARITH_OP_BUILTIN(Op, Name, bool)
00165 
00166 /*------------------.
00167 | LOGICAL OPERATORS |
00168 `------------------*/
00169 
00170 /*--------------------------------------.
00171 | Global logical operators for builtins |
00172 `--------------------------------------*/
00173 
00174 # define GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, Builtin)                   \
00175 template <class T2> inline                                              \
00176 ntg_return_type(logical, Builtin, T2)                                   \
00177 Op(const Builtin& lhs, const value<T2>& rhs)                            \
00178 {                                                                       \
00179   typedef ntg_deduced_traits_type(logical, Builtin, T2) deduced_type;   \
00180                                                                         \
00181   typedef typename deduced_type::impl impl;                             \
00182   typedef typename deduced_type::lhs_type lhs_type;                     \
00183   typedef typename deduced_type::rhs_type rhs_type;                     \
00184                                                                         \
00185   return optraits<impl>::Name(static_cast<lhs_type>(lhs),               \
00186                               static_cast<rhs_type>(rhs.exact()));      \
00187 }
00188 
00189 /*----------------------------------------------------.
00190 | Global logical operators for ntg_types and builtins |
00191 `----------------------------------------------------*/
00192 
00193 # define GLOBAL_LOGICAL_OP(Op, Name)                                    \
00194 template <class T1, class T2> inline                                    \
00195 ntg_return_type(logical, T1, T2)                                        \
00196 Op(const value<T1>& lhs, const T2& rhs)                                 \
00197 {                                                                       \
00198   typedef ntg_deduced_traits_type(logical, T1, T2) deduced_type;        \
00199                                                                         \
00200   typedef typename deduced_type::impl impl;                             \
00201   typedef typename deduced_type::lhs_type lhs_type;                     \
00202   typedef typename deduced_type::rhs_type rhs_type;                     \
00203                                                                         \
00204   return optraits<impl>::Name(static_cast<lhs_type>(lhs.exact()),       \
00205                               static_cast<rhs_type>(rhs));              \
00206 }                                                                       \
00207                                                                         \
00208 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed   long)                      \
00209 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned long)                      \
00210 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed   int)                       \
00211 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned int)                       \
00212 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed   short)                     \
00213 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned short)                     \
00214 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, signed   char)                      \
00215 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, unsigned char)                      \
00216 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, float)                              \
00217 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, double)                             \
00218 GLOBAL_LOGICAL_OP_BUILTIN(Op, Name, bool)
00219 
00220 /*---------------------.
00221 | COMPARISON OPERATORS |
00222 `---------------------*/
00223 
00224 /*-----------------------------------------.
00225 | Global comparison operators for builtins |
00226 `-----------------------------------------*/
00227 
00228 # define GLOBAL_CMP_OP_BUILTIN(Op, Name, Builtin)                       \
00229 template <class T2> inline                                              \
00230 bool                                                                    \
00231 Op(const Builtin& lhs, const value<T2>& rhs)                            \
00232 {                                                                       \
00233   typedef ntg_deduced_traits_type(cmp, Builtin, T2) deduced_type;       \
00234                                                                         \
00235   typedef typename deduced_type::impl impl;                             \
00236   typedef typename deduced_type::lhs_type lhs_type;                     \
00237   typedef typename deduced_type::rhs_type rhs_type;                     \
00238                                                                         \
00239   return optraits<impl>::Name(static_cast<lhs_type>(lhs),               \
00240                               static_cast<rhs_type>(rhs.exact()));      \
00241 }
00242 
00243 /*------------------------------------------------------------.
00244 | Global comparison operators for both ntg_types and builtins |
00245 `------------------------------------------------------------*/
00246 
00247 # define GLOBAL_CMP_OP(Op, Name)                                \
00248 template <class T1, class T2> inline                            \
00249 bool                                                            \
00250 Op(const value<T1>& lhs, const T2& rhs)                         \
00251 {                                                               \
00252   typedef ntg_deduced_traits_type(cmp, T1, T2) deduced_type;    \
00253                                                                 \
00254   typedef typename deduced_type::impl impl;                     \
00255   typedef typename deduced_type::lhs_type lhs_type;             \
00256   typedef typename deduced_type::rhs_type rhs_type;             \
00257                                                                 \
00258  return optraits<impl>::Name(static_cast<lhs_type>(lhs.exact()),        \
00259                               static_cast<rhs_type>(rhs));      \
00260 }                                                               \
00261                                                                 \
00262 GLOBAL_CMP_OP_BUILTIN(Op, Name, signed   long)                  \
00263 GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned long)                  \
00264 GLOBAL_CMP_OP_BUILTIN(Op, Name, signed   int)                   \
00265 GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned int)                   \
00266 GLOBAL_CMP_OP_BUILTIN(Op, Name, signed   short)                 \
00267 GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned short)                 \
00268 GLOBAL_CMP_OP_BUILTIN(Op, Name, signed   char)                  \
00269 GLOBAL_CMP_OP_BUILTIN(Op, Name, unsigned char)                  \
00270 GLOBAL_CMP_OP_BUILTIN(Op, Name, float)                          \
00271 GLOBAL_CMP_OP_BUILTIN(Op, Name, double)                         \
00272 GLOBAL_CMP_OP_BUILTIN(Op, Name, bool)
00273 
00274 #endif // !NTG_CORE_INTERNAL_GLOBAL_OPS_DEFS_HH

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