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