00001
00002
00003
00004
00005 #ifndef _UINT64_H
00006 #define _UINT64_H
00007
00008
00009
00010 template <class _Tp>
00011 class _compound_int : public _Tp
00012 {
00013 public:
00014 typedef _compound_int<_Tp> _Self;
00015
00016
00017 _compound_int();
00018 _compound_int(unsigned long);
00019 _compound_int(unsigned long hi, unsigned long lo);
00020 _compound_int(const _Tp& rhs) : _Tp(rhs) {}
00021
00022
00023 _Self& operator+= (const _Self&);
00024 _Self& operator-= (const _Self&);
00025 _Self& operator*= (const _Self&);
00026 _Self& operator/= (const _Self&);
00027 _Self& operator%= (const _Self&);
00028 _Self& operator&= (const _Self&);
00029 _Self& operator|= (const _Self&);
00030 _Self& operator^= (const _Self&);
00031
00032
00033 _Self& operator<<= (unsigned int);
00034 _Self& operator>>= (unsigned int);
00035
00036 _Self& operator= (unsigned long rhs) { return *this = _Self(rhs); }
00037 _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); }
00038 _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); }
00039 _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); }
00040 _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); }
00041 _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); }
00042 _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); }
00043 _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); }
00044 _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); }
00045
00046
00047 _Self& operator++() { return (*this) += 1; }
00048 _Self& operator--() { return (*this) -= 1; }
00049 _Self operator++(int) { _Self temp(*this); ++(*this); return temp; }
00050 _Self operator--(int) { _Self temp(*this); --(*this); return temp; }
00051 };
00052
00053
00054 template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&);
00055 template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&);
00056
00057 template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); }
00058 template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; }
00059
00060 template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); }
00061 template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; }
00062
00063 template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); }
00064 template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); }
00065
00066 template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; }
00067 template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; }
00068
00069 template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); }
00070 template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); }
00071
00072 template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); }
00073 template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); }
00074
00075
00076 template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&);
00077 template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&);
00078
00079 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;}
00080 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;}
00081 template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;}
00082
00083
00084 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp += rhs; }
00085 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp -= rhs; }
00086 template <class _Tp> inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp *= rhs; }
00087 template <class _Tp> inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp /= rhs; }
00088 template <class _Tp> inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp %= rhs; }
00089 template <class _Tp> inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp &= rhs; }
00090 template <class _Tp> inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp |= rhs; }
00091 template <class _Tp> inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp ^= rhs; }
00092
00093
00094 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); }
00095 template <class _Tp> inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; }
00096
00097 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); }
00098 template <class _Tp> inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; }
00099
00100 template <class _Tp> inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); }
00101 template <class _Tp> inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; }
00102
00103 template <class _Tp> inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); }
00104 template <class _Tp> inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; }
00105
00106 template <class _Tp> inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); }
00107 template <class _Tp> inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; }
00108
00109 template <class _Tp> inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); }
00110 template <class _Tp> inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; }
00111
00112 template <class _Tp> inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); }
00113 template <class _Tp> inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; }
00114
00115 template <class _Tp> inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); }
00116 template <class _Tp> inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; }
00117
00118 template <class _Tp> inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; }
00119 template <class _Tp> inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; }
00120
00121
00122
00123
00124
00125
00126 #if defined(__MRC__)||defined(__SC__)
00127
00128 _STLP_END_NAMESPACE
00129 # include <Math64.h>
00130 # include <utility>
00131 # undef modff //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition
00132 # include <fp.h>
00133
00134 _STLP_BEGIN_NAMESPACE
00135
00136 # if TYPE_LONGLONG
00137 typedef UInt64 uint64;
00138 # define ULL(x) (U64SetU(x))
00139
00140 # else
00141
00142
00143
00144
00145
00146
00147
00148
00149 typedef _compound_int<UnsignedWide> uint64;
00150 # define ULL(x) uint64(x)
00151 # define ULL2(hi,lo) {hi,lo}
00152
00153
00154 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; }
00155 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; }
00156 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; }
00157
00158
00159 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs) { *this = U64Add( *this, rhs ); return *this; }
00160 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs) { *this = U64Subtract( *this, rhs ); return *this; }
00161 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs) { *this = U64Multiply( *this, rhs ); return *this; }
00162 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs) { *this = U64Divide( *this, rhs, NULL ); return *this; }
00163 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs) { U64Divide( *this, rhs, this ); return *this; }
00164 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs) { *this = U64BitwiseAnd( *this, rhs ); return *this; }
00165 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs) { *this = U64BitwiseOr( *this, rhs ); return *this; }
00166 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs) { *this = U64BitwiseEor( *this, rhs ); return *this; }
00167
00168
00169 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs) { *this = U64ShiftLeft( *this, rhs ); return *this; }
00170 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs) { *this = U64ShiftRight( *this, rhs ); return *this; }
00171
00172
00173 _STLP_TEMPLATE_NULL inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs) { return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); }
00174 _STLP_TEMPLATE_NULL inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs) { return U64Compare( lhs, rhs ) < 0; }
00175 _STLP_TEMPLATE_NULL inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs) { return (lhs.hi == 0) && (lhs.lo == rhs); }
00176
00177
00178 _STLP_TEMPLATE_NULL inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; }
00179 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); }
00180 _STLP_TEMPLATE_NULL inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); }
00181
00182 # endif // TYPE_LONGLONG
00183 #endif // __MRC__
00184 #endif // _UINT64_H