os/ossrv/genericopenlibs/cppstdlib/stl/src/uint64.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/src/uint64.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,240 @@
     1.4 +//  uint64.h
     1.5 +//  minimal double precision unsigned int arithmetics for numeric_facets support.
     1.6 +//  Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000
     1.7 +#ifndef _UINT64_H
     1.8 +#define _UINT64_H
     1.9 +
    1.10 +template <class _Tp>
    1.11 +class _compound_int : public _Tp {
    1.12 +public:
    1.13 +  typedef _compound_int<_Tp> _Self;
    1.14 +
    1.15 +  // Constructors, destructor, assignment operator.
    1.16 +  _compound_int();                    // platform specific
    1.17 +  _compound_int(unsigned long);              // platform specific
    1.18 +  _compound_int(unsigned long hi, unsigned long lo);  // platform specific
    1.19 +  _compound_int(const _Tp& rhs) : _Tp(rhs) {}
    1.20 +
    1.21 +  // Arithmetic op= operations involving two _compound_int.
    1.22 +  _Self& operator+= (const _Self&);            // platform specific
    1.23 +  _Self& operator-= (const _Self&);            // platform specific
    1.24 +  _Self& operator*= (const _Self&);            // platform specific
    1.25 +  _Self& operator/= (const _Self&);            // platform specific
    1.26 +  _Self& operator%= (const _Self&);            // platform specific
    1.27 +  _Self& operator&= (const _Self&);            // platform specific
    1.28 +  _Self& operator|= (const _Self&);            // platform specific
    1.29 +  _Self& operator^= (const _Self&);            // platform specific
    1.30 +
    1.31 +  // Arithmetic op= operations involving built-in integer.
    1.32 +  _Self& operator<<= (unsigned int);          // platform specific
    1.33 +  _Self& operator>>= (unsigned int);          // platform specific
    1.34 +
    1.35 +  _Self& operator=  (unsigned long rhs) { return *this =  _Self(rhs); }
    1.36 +  _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); }
    1.37 +  _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); }
    1.38 +  _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); }
    1.39 +  _Self& operator/= (unsigned long rhs) { return *this /= _Self(rhs); }
    1.40 +  _Self& operator%= (unsigned long rhs) { return *this %= _Self(rhs); }
    1.41 +  _Self& operator&= (unsigned long rhs) { return *this &= _Self(rhs); }
    1.42 +  _Self& operator|= (unsigned long rhs) { return *this |= _Self(rhs); }
    1.43 +  _Self& operator^= (unsigned long rhs) { return *this ^= _Self(rhs); }
    1.44 +
    1.45 +  // Increment and decrement
    1.46 +  _Self& operator++() { return (*this) += 1; }
    1.47 +  _Self& operator--() { return (*this) -= 1; }
    1.48 +  _Self operator++(int) { _Self temp(*this); ++(*this); return temp; }
    1.49 +  _Self operator--(int) { _Self temp(*this); --(*this); return temp; }
    1.50 +};
    1.51 +
    1.52 +// Comparison operators.
    1.53 +template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&);  // platform specific
    1.54 +template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&);  // platform specific
    1.55 +
    1.56 +template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); }
    1.57 +template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; }
    1.58 +
    1.59 +template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); }
    1.60 +template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; }
    1.61 +
    1.62 +template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); }
    1.63 +template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); }
    1.64 +
    1.65 +template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; }
    1.66 +template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; }
    1.67 +
    1.68 +template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); }
    1.69 +template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); }
    1.70 +
    1.71 +template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); }
    1.72 +template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); }
    1.73 +
    1.74 +// Unary non-member arithmetic operators.
    1.75 +template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&);      // platform specific
    1.76 +template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&);  // platform specific
    1.77 +
    1.78 +template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;}
    1.79 +template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;}
    1.80 +template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;}
    1.81 +
    1.82 +// Non-member arithmetic operations involving two _compound_int arguments
    1.83 +template <class _Tp>
    1.84 +inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
    1.85 +{ _compound_int<_Tp> temp(lhs); return temp += rhs; }
    1.86 +template <class _Tp>
    1.87 +inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
    1.88 +{ _compound_int<_Tp> temp(lhs); return temp -= rhs; }
    1.89 +template <class _Tp>
    1.90 +inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
    1.91 +{ _compound_int<_Tp> temp(lhs); return temp *= rhs; }
    1.92 +template <class _Tp>
    1.93 +inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
    1.94 +{ _compound_int<_Tp> temp(lhs); return temp /= rhs; }
    1.95 +template <class _Tp>
    1.96 +inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
    1.97 +{ _compound_int<_Tp> temp(lhs); return temp %= rhs; }
    1.98 +template <class _Tp>
    1.99 +inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
   1.100 +{ _compound_int<_Tp> temp(lhs); return temp &= rhs; }
   1.101 +template <class _Tp>
   1.102 +inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
   1.103 +{ _compound_int<_Tp> temp(lhs); return temp |= rhs; }
   1.104 +template <class _Tp>
   1.105 +inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
   1.106 +{ _compound_int<_Tp> temp(lhs); return temp ^= rhs; }
   1.107 +
   1.108 +// Non-member arithmetic operations involving one built-in integer argument.
   1.109 +template <class _Tp>
   1.110 +inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); }
   1.111 +template <class _Tp>
   1.112 +inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; }
   1.113 +
   1.114 +template <class _Tp>
   1.115 +inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); }
   1.116 +template <class _Tp>
   1.117 +inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; }
   1.118 +
   1.119 +template <class _Tp>
   1.120 +inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); }
   1.121 +template <class _Tp>
   1.122 +inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; }
   1.123 +
   1.124 +template <class _Tp>
   1.125 +inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); }
   1.126 +template <class _Tp>
   1.127 +inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; }
   1.128 +
   1.129 +template <class _Tp>
   1.130 +inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); }
   1.131 +template <class _Tp>
   1.132 +inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; }
   1.133 +
   1.134 +template <class _Tp>
   1.135 +inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); }
   1.136 +template <class _Tp>
   1.137 +inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; }
   1.138 +
   1.139 +template <class _Tp>
   1.140 +inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); }
   1.141 +template <class _Tp>
   1.142 +inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; }
   1.143 +
   1.144 +template <class _Tp>
   1.145 +inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); }
   1.146 +template <class _Tp>
   1.147 +inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; }
   1.148 +
   1.149 +template <class _Tp>
   1.150 +inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; }
   1.151 +template <class _Tp>
   1.152 +inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; }
   1.153 +
   1.154 +// platform specific specializations
   1.155 +#if defined (__MRC__) || defined (__SC__)
   1.156 +
   1.157 +_STLP_END_NAMESPACE
   1.158 +#  include <Math64.h>
   1.159 +#  include <utility>
   1.160 +#  undef modff    //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition
   1.161 +#  include <fp.h>
   1.162 +
   1.163 +_STLP_BEGIN_NAMESPACE
   1.164 +
   1.165 +#  if TYPE_LONGLONG
   1.166 +typedef UInt64 uint64;
   1.167 +#    define ULL(x) (U64SetU(x))
   1.168 +
   1.169 +#  else
   1.170 +//  Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type.
   1.171 +//  Instead, it comes with external support library and struct data type representing 64bit int:
   1.172 +//
   1.173 +//    struct UnsignedWide {
   1.174 +//      UInt32   hi;
   1.175 +//      UInt32   lo;
   1.176 +//    };
   1.177 +
   1.178 +typedef _compound_int<UnsignedWide> uint64;
   1.179 +#    define ULL(x) uint64(x)
   1.180 +#    define ULL2(hi,lo) {hi,lo}
   1.181 +
   1.182 +// Constructors, destructor, assignment operator.
   1.183 +_STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; }
   1.184 +_STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; }
   1.185 +_STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; }
   1.186 +
   1.187 +// Arithmetic op= operations involving two _compound_int.
   1.188 +_STLP_TEMPLATE_NULL
   1.189 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs)
   1.190 +{ *this = U64Add( *this, rhs ); return *this; }
   1.191 +_STLP_TEMPLATE_NULL
   1.192 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs)
   1.193 +{ *this = U64Subtract( *this, rhs ); return *this; }
   1.194 +_STLP_TEMPLATE_NULL
   1.195 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs)
   1.196 +{ *this = U64Multiply( *this, rhs ); return *this; }
   1.197 +_STLP_TEMPLATE_NULL
   1.198 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs)
   1.199 +{ *this = U64Divide( *this, rhs, NULL ); return *this; }
   1.200 +_STLP_TEMPLATE_NULL
   1.201 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs)
   1.202 +{ U64Divide( *this, rhs, this ); return *this; }
   1.203 +_STLP_TEMPLATE_NULL
   1.204 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs)
   1.205 +{ *this = U64BitwiseAnd( *this, rhs ); return *this; }
   1.206 +_STLP_TEMPLATE_NULL
   1.207 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs)
   1.208 +{ *this = U64BitwiseOr( *this, rhs ); return *this; }
   1.209 +_STLP_TEMPLATE_NULL
   1.210 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs)
   1.211 +{ *this = U64BitwiseEor( *this, rhs ); return *this; }
   1.212 +
   1.213 +// Arithmetic op= operations involving built-in integer.
   1.214 +_STLP_TEMPLATE_NULL
   1.215 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs)
   1.216 +{ *this = U64ShiftLeft( *this, rhs ); return *this; }
   1.217 +_STLP_TEMPLATE_NULL
   1.218 +inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs)
   1.219 +{ *this = U64ShiftRight( *this, rhs ); return *this; }
   1.220 +
   1.221 +// Comparison operators.
   1.222 +_STLP_TEMPLATE_NULL
   1.223 +inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
   1.224 +{ return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); }
   1.225 +_STLP_TEMPLATE_NULL
   1.226 +inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
   1.227 +{ return U64Compare( lhs, rhs ) < 0; }
   1.228 +_STLP_TEMPLATE_NULL
   1.229 +inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs)
   1.230 +{ return (lhs.hi == 0) && (lhs.lo == rhs); }
   1.231 +
   1.232 +// Unary non-member arithmetic operators.
   1.233 +_STLP_TEMPLATE_NULL
   1.234 +inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; }
   1.235 +_STLP_TEMPLATE_NULL
   1.236 +inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); }
   1.237 +_STLP_TEMPLATE_NULL
   1.238 +inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); }
   1.239 +
   1.240 +#  endif // TYPE_LONGLONG
   1.241 +#endif // __MRC__
   1.242 +
   1.243 +#endif // _UINT64_H