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
00027
00028 #ifndef NTG_CORE_INTERNAL_GLOBAL_OPS_HH
00029 # define NTG_CORE_INTERNAL_GLOBAL_OPS_HH
00030
00031
00032
00033
00034
00035
00036
00037
00038 # include <mlc/contract.hh>
00039 # include <mlc/is_a.hh>
00040
00041 # include <ntg/real/builtin_float.hh>
00042 # include <ntg/real/optraits_builtin_int.hh>
00043 # include <ntg/core/internal/global_ops_traits.hh>
00044 # include <ntg/core/macros.hh>
00045 # include <ntg/core/value.hh>
00046 # include <ntg/utils/debug.hh>
00047
00048
00049 # include <ntg/core/internal/global_ops_defs.hh>
00050
00051
00052 # include <algorithm>
00053
00054 namespace ntg
00055 {
00056
00057
00058
00059
00060
00061
00062
00063 namespace internal
00064 {
00065
00066
00067
00068
00069
00070 GLOBAL_ASSIGN_OP(operator+=, plus_equal)
00071 GLOBAL_ASSIGN_OP_BUILTIN_INT(operator+=, plus_equal)
00072 GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator+=, plus_equal)
00073
00074 GLOBAL_ASSIGN_OP(operator-=, minus_equal)
00075 GLOBAL_ASSIGN_OP_BUILTIN_INT(operator-=, minus_equal)
00076 GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator-=, minus_equal)
00077
00078 GLOBAL_ASSIGN_OP(operator*=, times_equal)
00079 GLOBAL_ASSIGN_OP_BUILTIN_INT(operator*=, times_equal)
00080 GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator*=, times_equal)
00081
00082 GLOBAL_ASSIGN_OP(operator/=, div_equal)
00083 GLOBAL_ASSIGN_OP_BUILTIN_INT(operator/=, div_equal)
00084 GLOBAL_ASSIGN_OP_BUILTIN_FLOAT(operator/=, div_equal)
00085
00086 GLOBAL_ASSIGN_OP(operator%=, mod_equal)
00087 GLOBAL_ASSIGN_OP_BUILTIN_INT(operator%=, mod_equal)
00088
00089
00090
00091
00092
00093
00094
00095 GLOBAL_ASSIGN_OP(operator|=, logical_or_equal)
00096
00097
00098 GLOBAL_ASSIGN_OP(operator&=, logical_and_equal)
00099
00100
00101 GLOBAL_ASSIGN_OP(operator^=, logical_xor_equal)
00102
00103
00104
00105
00106
00107
00108 GLOBAL_ARITH_OP(operator+, plus)
00109 GLOBAL_ARITH_OP(operator-, minus)
00110 GLOBAL_ARITH_OP(operator*, times)
00111 GLOBAL_ARITH_OP(operator/, div)
00112 GLOBAL_ARITH_OP(operator%, mod)
00113
00114
00115
00116
00117
00118 GLOBAL_LOGICAL_OP(operator|, logical_or)
00119 GLOBAL_LOGICAL_OP(operator&, logical_and)
00120 GLOBAL_LOGICAL_OP(operator^, logical_xor)
00121
00122
00123
00124
00125
00126 GLOBAL_CMP_OP(operator==, cmp_eq)
00127
00128 template <class T1, class T2> inline
00129 bool
00130 operator!=(const T1& lhs, const T2& rhs)
00131 { return !(lhs == rhs); }
00132
00133
00134
00135
00136 GLOBAL_CMP_OP(operator<, cmp_lt)
00137
00138 template <class T1, class T2> inline
00139 bool
00140 operator>(const T1& lhs, const T2& rhs)
00141 { return rhs < lhs; }
00142
00143 template <class T1, class T2> inline
00144 bool
00145 operator>=(const T1& lhs, const T2& rhs)
00146 { return !(lhs < rhs); }
00147
00148 template <class T1, class T2> inline
00149 bool
00150 operator<=(const T1& lhs, const T2& rhs)
00151 { return !(rhs < lhs); }
00152
00153
00154
00155
00156
00157
00158
00159 template <class T> inline
00160 const T&
00161 operator+(const T& val)
00162 {
00163 return val;
00164 }
00165
00166 template<class T> inline
00167 const T&
00168 operator++(T& val)
00169 {
00170 val += ntg_unit_val(T);
00171 return val;
00172 }
00173
00174 template<class T> inline
00175 T
00176 operator++(T& val, int)
00177 {
00178 T tmp(val);
00179 val += ntg_unit_val(T);
00180 return tmp;
00181 }
00182
00183
00184
00185 template <class T> inline
00186 const ntg_signed_type(T)
00187 operator-(const T& val)
00188 {
00189 typedef ntg_signed_type(T) signed_type;
00190 return static_cast<signed_type>(ntg_zero_val(T)) - val;
00191 }
00192
00193 template<class T> inline
00194 const T& operator--(T& val)
00195 {
00196 val -= ntg_unit_val(T);
00197 return val;
00198 }
00199
00200 template<class T> inline
00201 T operator--(T& val, int)
00202 {
00203 T tmp(val);
00204 val -= ntg_unit_val(T);
00205 return tmp;
00206 }
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 template <class T1, class T2> inline
00218 ntg_return_type(min, T1, T2)
00219 min (const T1& lhs, const T2& rhs)
00220 {
00221 typedef ntg_return_type(max, T1, T2) result_type;
00222 return (lhs < rhs) ? result_type(lhs) : result_type(rhs);
00223 }
00224
00225 template <class T1, class T2> inline
00226 ntg_return_type(max, T1, T2)
00227 max (const T1& lhs, const T2& rhs)
00228 {
00229 typedef ntg_return_type(max, T1, T2) result_type;
00230 return (lhs > rhs) ? result_type(lhs) : result_type(rhs);
00231 }
00232
00233 }
00234
00235
00236
00237
00238 using internal::min;
00239 using internal::max;
00240
00241 }
00242
00243 #endif // ndef NTG_CORE_INTERNAL_GLOBAL_OPS_HH