sl@0: // uint64.h sl@0: // minimal double precision unsigned int arithmetics for numeric_facets support. sl@0: // Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000 sl@0: sl@0: #ifndef _UINT64_H sl@0: #define _UINT64_H sl@0: sl@0: sl@0: sl@0: template sl@0: class _compound_int : public _Tp sl@0: { sl@0: public: sl@0: typedef _compound_int<_Tp> _Self; sl@0: sl@0: // Constructors, destructor, assignment operator. sl@0: _compound_int(); // platform specific sl@0: _compound_int(unsigned long); // platform specific sl@0: _compound_int(unsigned long hi, unsigned long lo); // platform specific sl@0: _compound_int(const _Tp& rhs) : _Tp(rhs) {} sl@0: sl@0: // Arithmetic op= operations involving two _compound_int. sl@0: _Self& operator+= (const _Self&); // platform specific sl@0: _Self& operator-= (const _Self&); // platform specific sl@0: _Self& operator*= (const _Self&); // platform specific sl@0: _Self& operator/= (const _Self&); // platform specific sl@0: _Self& operator%= (const _Self&); // platform specific sl@0: _Self& operator&= (const _Self&); // platform specific sl@0: _Self& operator|= (const _Self&); // platform specific sl@0: _Self& operator^= (const _Self&); // platform specific sl@0: sl@0: // Arithmetic op= operations involving built-in integer. sl@0: _Self& operator<<= (unsigned int); // platform specific sl@0: _Self& operator>>= (unsigned int); // platform specific sl@0: sl@0: _Self& operator= (unsigned long rhs) { return *this = _Self(rhs); } sl@0: _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); } sl@0: _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); } sl@0: _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); } sl@0: _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); } sl@0: _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); } sl@0: _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); } sl@0: _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); } sl@0: _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); } sl@0: sl@0: // Increment and decrement sl@0: _Self& operator++() { return (*this) += 1; } sl@0: _Self& operator--() { return (*this) -= 1; } sl@0: _Self operator++(int) { _Self temp(*this); ++(*this); return temp; } sl@0: _Self operator--(int) { _Self temp(*this); --(*this); return temp; } sl@0: }; sl@0: sl@0: // Comparison operators. sl@0: template bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&); // platform specific sl@0: template bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&); // platform specific sl@0: sl@0: template inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); } sl@0: template inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; } sl@0: sl@0: template inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); } sl@0: template inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; } sl@0: sl@0: template inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); } sl@0: template inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); } sl@0: sl@0: template inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; } sl@0: template inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; } sl@0: sl@0: template inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); } sl@0: template inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); } sl@0: sl@0: template inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); } sl@0: template inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); } sl@0: sl@0: // Unary non-member arithmetic operators. sl@0: template unsigned long to_ulong(const _compound_int<_Tp>&); // platform specific sl@0: template _compound_int<_Tp> operator~(const _compound_int<_Tp>&); // platform specific sl@0: sl@0: template inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;} sl@0: template inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;} sl@0: template inline bool operator!(const _compound_int<_Tp>& val) {return val==0;} sl@0: sl@0: // Non-member arithmetic operations involving two _compound_int arguments sl@0: template inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp += rhs; } sl@0: template inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp -= rhs; } sl@0: template inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp *= rhs; } sl@0: template inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp /= rhs; } sl@0: template inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp %= rhs; } sl@0: template inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp &= rhs; } sl@0: template inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp |= rhs; } sl@0: template inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs) { _compound_int<_Tp> temp(lhs); return temp ^= rhs; } sl@0: sl@0: // Non-member arithmetic operations involving one built-in integer argument. sl@0: template inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); } sl@0: template inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; } sl@0: sl@0: template inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; } sl@0: template inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; } sl@0: sl@0: sl@0: sl@0: sl@0: // platform specific specializations sl@0: sl@0: #if defined(__MRC__)||defined(__SC__) sl@0: sl@0: _STLP_END_NAMESPACE // ugly! sl@0: # include sl@0: # include sl@0: # undef modff //*TY 04/06/2000 - defined in which conflicts with definition sl@0: # include sl@0: sl@0: _STLP_BEGIN_NAMESPACE sl@0: sl@0: # if TYPE_LONGLONG sl@0: typedef UInt64 uint64; sl@0: # define ULL(x) (U64SetU(x)) sl@0: sl@0: # else sl@0: // Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type. sl@0: // Instead, it comes with external support library and struct data type representing 64bit int: sl@0: // sl@0: // struct UnsignedWide { sl@0: // UInt32 hi; sl@0: // UInt32 lo; sl@0: // }; sl@0: sl@0: typedef _compound_int uint64; sl@0: # define ULL(x) uint64(x) sl@0: # define ULL2(hi,lo) {hi,lo} sl@0: sl@0: // Constructors, destructor, assignment operator. sl@0: _STLP_TEMPLATE_NULL inline _compound_int::_compound_int() { hi = 0; lo = 0; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int::_compound_int(unsigned long val) { hi = 0; lo = val; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; } sl@0: sl@0: // Arithmetic op= operations involving two _compound_int. sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator+= (const _compound_int& rhs) { *this = U64Add( *this, rhs ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator-= (const _compound_int& rhs) { *this = U64Subtract( *this, rhs ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator*= (const _compound_int& rhs) { *this = U64Multiply( *this, rhs ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator/= (const _compound_int& rhs) { *this = U64Divide( *this, rhs, NULL ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator%= (const _compound_int& rhs) { U64Divide( *this, rhs, this ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator&= (const _compound_int& rhs) { *this = U64BitwiseAnd( *this, rhs ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator|= (const _compound_int& rhs) { *this = U64BitwiseOr( *this, rhs ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator^= (const _compound_int& rhs) { *this = U64BitwiseEor( *this, rhs ); return *this; } sl@0: sl@0: // Arithmetic op= operations involving built-in integer. sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator<<= (unsigned int rhs) { *this = U64ShiftLeft( *this, rhs ); return *this; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int& _compound_int::operator>>= (unsigned int rhs) { *this = U64ShiftRight( *this, rhs ); return *this; } sl@0: sl@0: // Comparison operators. sl@0: _STLP_TEMPLATE_NULL inline bool operator==(const _compound_int& lhs, const _compound_int& rhs) { return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); } sl@0: _STLP_TEMPLATE_NULL inline bool operator< (const _compound_int& lhs, const _compound_int& rhs) { return U64Compare( lhs, rhs ) < 0; } sl@0: _STLP_TEMPLATE_NULL inline bool operator==(const _compound_int& lhs, unsigned long rhs) { return (lhs.hi == 0) && (lhs.lo == rhs); } sl@0: sl@0: // Unary non-member arithmetic operators. sl@0: _STLP_TEMPLATE_NULL inline unsigned long to_ulong(const _compound_int& val) { return val.lo; } sl@0: _STLP_TEMPLATE_NULL inline _compound_int operator~(const _compound_int& val) { return U64BitwiseNot( val ); } sl@0: _STLP_TEMPLATE_NULL inline bool operator!(const _compound_int& val) { return !((val.hi == 0) && (val.lo == 0)); } sl@0: sl@0: # endif // TYPE_LONGLONG sl@0: #endif // __MRC__ sl@0: #endif // _UINT64_H