/home/ntakagi/work/STLport-5.1.5/src/uint64.h

Go to the documentation of this file.
00001 //  uint64.h
00002 //  minimal double precision unsigned int arithmetics for numeric_facets support.
00003 //  Written by Tsutomu Yoshida, Minokamo, Japan. 03/25/2000
00004 #ifndef _UINT64_H
00005 #define _UINT64_H
00006 
00007 template <class _Tp>
00008 class _compound_int : public _Tp {
00009 public:
00010   typedef _compound_int<_Tp> _Self;
00011 
00012   // Constructors, destructor, assignment operator.
00013   _compound_int();                    // platform specific
00014   _compound_int(unsigned long);              // platform specific
00015   _compound_int(unsigned long hi, unsigned long lo);  // platform specific
00016   _compound_int(const _Tp& rhs) : _Tp(rhs) {}
00017 
00018   // Arithmetic op= operations involving two _compound_int.
00019   _Self& operator+= (const _Self&);            // platform specific
00020   _Self& operator-= (const _Self&);            // platform specific
00021   _Self& operator*= (const _Self&);            // platform specific
00022   _Self& operator/= (const _Self&);            // platform specific
00023   _Self& operator%= (const _Self&);            // platform specific
00024   _Self& operator&= (const _Self&);            // platform specific
00025   _Self& operator|= (const _Self&);            // platform specific
00026   _Self& operator^= (const _Self&);            // platform specific
00027 
00028   // Arithmetic op= operations involving built-in integer.
00029   _Self& operator<<= (unsigned int);          // platform specific
00030   _Self& operator>>= (unsigned int);          // platform specific
00031 
00032   _Self& operator=  (unsigned long rhs) { return *this =  _Self(rhs); }
00033   _Self& operator+= (unsigned long rhs) { return *this += _Self(rhs); }
00034   _Self& operator-= (unsigned long rhs) { return *this -= _Self(rhs); }
00035   _Self& operator*= (unsigned long rhs) { return *this *= _Self(rhs); }
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 
00042   // Increment and decrement
00043   _Self& operator++() { return (*this) += 1; }
00044   _Self& operator--() { return (*this) -= 1; }
00045   _Self operator++(int) { _Self temp(*this); ++(*this); return temp; }
00046   _Self operator--(int) { _Self temp(*this); --(*this); return temp; }
00047 };
00048 
00049 // Comparison operators.
00050 template <class _Tp> bool operator==(const _compound_int<_Tp>&, const _compound_int<_Tp>&);  // platform specific
00051 template <class _Tp> bool operator<(const _compound_int<_Tp>&, const _compound_int<_Tp>&);  // platform specific
00052 
00053 template <class _Tp> inline bool operator==(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs == _compound_int<_Tp>(rhs); }
00054 template <class _Tp> inline bool operator==(unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs == lhs; }
00055 
00056 template <class _Tp> inline bool operator< (const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs < _compound_int<_Tp>(rhs); }
00057 template <class _Tp> inline bool operator< (unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) < rhs; }
00058 
00059 template <class _Tp> inline bool operator!=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs == rhs); }
00060 template <class _Tp> inline bool operator!=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs == rhs); }
00061 
00062 template <class _Tp> inline bool operator> (const _compound_int<_Tp>& lhs, unsigned long rhs) { return rhs < lhs; }
00063 template <class _Tp> inline bool operator> (unsigned long lhs, const _compound_int<_Tp>& rhs) { return rhs < lhs; }
00064 
00065 template <class _Tp> inline bool operator<=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs > rhs); }
00066 template <class _Tp> inline bool operator<=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs > rhs); }
00067 
00068 template <class _Tp> inline bool operator>=(const _compound_int<_Tp>& lhs, unsigned long rhs) { return !(lhs < rhs); }
00069 template <class _Tp> inline bool operator>=(unsigned long lhs, const _compound_int<_Tp>& rhs) { return !(lhs < rhs); }
00070 
00071 // Unary non-member arithmetic operators.
00072 template <class _Tp> unsigned long to_ulong(const _compound_int<_Tp>&);      // platform specific
00073 template <class _Tp> _compound_int<_Tp> operator~(const _compound_int<_Tp>&);  // platform specific
00074 
00075 template <class _Tp> inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& val) {return val;}
00076 template <class _Tp> inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& val) {return 0 - val;}
00077 template <class _Tp> inline bool operator!(const _compound_int<_Tp>& val) {return val==0;}
00078 
00079 // Non-member arithmetic operations involving two _compound_int arguments
00080 template <class _Tp>
00081 inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00082 { _compound_int<_Tp> temp(lhs); return temp += rhs; }
00083 template <class _Tp>
00084 inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00085 { _compound_int<_Tp> temp(lhs); return temp -= rhs; }
00086 template <class _Tp>
00087 inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00088 { _compound_int<_Tp> temp(lhs); return temp *= rhs; }
00089 template <class _Tp>
00090 inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00091 { _compound_int<_Tp> temp(lhs); return temp /= rhs; }
00092 template <class _Tp>
00093 inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00094 { _compound_int<_Tp> temp(lhs); return temp %= rhs; }
00095 template <class _Tp>
00096 inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00097 { _compound_int<_Tp> temp(lhs); return temp &= rhs; }
00098 template <class _Tp>
00099 inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00100 { _compound_int<_Tp> temp(lhs); return temp |= rhs; }
00101 template <class _Tp>
00102 inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, const _compound_int<_Tp>& rhs)
00103 { _compound_int<_Tp> temp(lhs); return temp ^= rhs; }
00104 
00105 // Non-member arithmetic operations involving one built-in integer argument.
00106 template <class _Tp>
00107 inline _compound_int<_Tp> operator+(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs + _compound_int<_Tp>(rhs); }
00108 template <class _Tp>
00109 inline _compound_int<_Tp> operator+(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) + rhs; }
00110 
00111 template <class _Tp>
00112 inline _compound_int<_Tp> operator-(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs - _compound_int<_Tp>(rhs); }
00113 template <class _Tp>
00114 inline _compound_int<_Tp> operator-(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) - rhs; }
00115 
00116 template <class _Tp>
00117 inline _compound_int<_Tp> operator*(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs * _compound_int<_Tp>(rhs); }
00118 template <class _Tp>
00119 inline _compound_int<_Tp> operator*(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) * rhs; }
00120 
00121 template <class _Tp>
00122 inline _compound_int<_Tp> operator/(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs / _compound_int<_Tp>(rhs); }
00123 template <class _Tp>
00124 inline _compound_int<_Tp> operator/(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) / rhs; }
00125 
00126 template <class _Tp>
00127 inline _compound_int<_Tp> operator%(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs % _compound_int<_Tp>(rhs); }
00128 template <class _Tp>
00129 inline _compound_int<_Tp> operator%(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) % rhs; }
00130 
00131 template <class _Tp>
00132 inline _compound_int<_Tp> operator&(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs & _compound_int<_Tp>(rhs); }
00133 template <class _Tp>
00134 inline _compound_int<_Tp> operator&(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) & rhs; }
00135 
00136 template <class _Tp>
00137 inline _compound_int<_Tp> operator|(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs | _compound_int<_Tp>(rhs); }
00138 template <class _Tp>
00139 inline _compound_int<_Tp> operator|(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) | rhs; }
00140 
00141 template <class _Tp>
00142 inline _compound_int<_Tp> operator^(const _compound_int<_Tp>& lhs, unsigned long rhs) { return lhs ^ _compound_int<_Tp>(rhs); }
00143 template <class _Tp>
00144 inline _compound_int<_Tp> operator^(unsigned long lhs, const _compound_int<_Tp>& rhs) { return _compound_int<_Tp>(lhs) ^ rhs; }
00145 
00146 template <class _Tp>
00147 inline _compound_int<_Tp> operator<<(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp <<= rhs; }
00148 template <class _Tp>
00149 inline _compound_int<_Tp> operator>>(const _compound_int<_Tp>& lhs, unsigned int rhs) { _compound_int<_Tp> temp(lhs); return temp >>= rhs; }
00150 
00151 // platform specific specializations
00152 #if defined (__MRC__) || defined (__SC__)
00153 
00154 _STLP_END_NAMESPACE
00155 #  include <Math64.h>
00156 #  include <utility>
00157 #  undef modff    //*TY 04/06/2000 - defined in <math.h> which conflicts with <fp.h> definition
00158 #  include <fp.h>
00159 
00160 _STLP_BEGIN_NAMESPACE
00161 
00162 #  if TYPE_LONGLONG
00163 typedef UInt64 uint64;
00164 #    define ULL(x) (U64SetU(x))
00165 
00166 #  else
00167 //  Apple's mpw sc compiler for 68k macintosh does not support native 64bit integer type.
00168 //  Instead, it comes with external support library and struct data type representing 64bit int:
00169 //
00170 //    struct UnsignedWide {
00171 //      UInt32   hi;
00172 //      UInt32   lo;
00173 //    };
00174 
00175 typedef _compound_int<UnsignedWide> uint64;
00176 #    define ULL(x) uint64(x)
00177 #    define ULL2(hi,lo) {hi,lo}
00178 
00179 // Constructors, destructor, assignment operator.
00180 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int() { hi = 0; lo = 0; }
00181 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long val) { hi = 0; lo = val; }
00182 _STLP_TEMPLATE_NULL inline _compound_int<UnsignedWide>::_compound_int(unsigned long h, unsigned long l) { hi = h; lo = l; }
00183 
00184 // Arithmetic op= operations involving two _compound_int.
00185 _STLP_TEMPLATE_NULL
00186 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator+= (const _compound_int<UnsignedWide>& rhs)
00187 { *this = U64Add( *this, rhs ); return *this; }
00188 _STLP_TEMPLATE_NULL
00189 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator-= (const _compound_int<UnsignedWide>& rhs)
00190 { *this = U64Subtract( *this, rhs ); return *this; }
00191 _STLP_TEMPLATE_NULL
00192 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator*= (const _compound_int<UnsignedWide>& rhs)
00193 { *this = U64Multiply( *this, rhs ); return *this; }
00194 _STLP_TEMPLATE_NULL
00195 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator/= (const _compound_int<UnsignedWide>& rhs)
00196 { *this = U64Divide( *this, rhs, NULL ); return *this; }
00197 _STLP_TEMPLATE_NULL
00198 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator%= (const _compound_int<UnsignedWide>& rhs)
00199 { U64Divide( *this, rhs, this ); return *this; }
00200 _STLP_TEMPLATE_NULL
00201 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator&= (const _compound_int<UnsignedWide>& rhs)
00202 { *this = U64BitwiseAnd( *this, rhs ); return *this; }
00203 _STLP_TEMPLATE_NULL
00204 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator|= (const _compound_int<UnsignedWide>& rhs)
00205 { *this = U64BitwiseOr( *this, rhs ); return *this; }
00206 _STLP_TEMPLATE_NULL
00207 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator^= (const _compound_int<UnsignedWide>& rhs)
00208 { *this = U64BitwiseEor( *this, rhs ); return *this; }
00209 
00210 // Arithmetic op= operations involving built-in integer.
00211 _STLP_TEMPLATE_NULL
00212 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator<<= (unsigned int rhs)
00213 { *this = U64ShiftLeft( *this, rhs ); return *this; }
00214 _STLP_TEMPLATE_NULL
00215 inline _compound_int<UnsignedWide>& _compound_int<UnsignedWide>::operator>>= (unsigned int rhs)
00216 { *this = U64ShiftRight( *this, rhs ); return *this; }
00217 
00218 // Comparison operators.
00219 _STLP_TEMPLATE_NULL
00220 inline bool operator==(const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
00221 { return (lhs.hi == rhs.hi) && (lhs.lo == rhs.lo); }
00222 _STLP_TEMPLATE_NULL
00223 inline bool operator< (const _compound_int<UnsignedWide>& lhs, const _compound_int<UnsignedWide>& rhs)
00224 { return U64Compare( lhs, rhs ) < 0; }
00225 _STLP_TEMPLATE_NULL
00226 inline bool operator==(const _compound_int<UnsignedWide>& lhs, unsigned long rhs)
00227 { return (lhs.hi == 0) && (lhs.lo == rhs); }
00228 
00229 // Unary non-member arithmetic operators.
00230 _STLP_TEMPLATE_NULL
00231 inline unsigned long to_ulong(const _compound_int<UnsignedWide>& val) { return val.lo; }
00232 _STLP_TEMPLATE_NULL
00233 inline _compound_int<UnsignedWide> operator~(const _compound_int<UnsignedWide>& val) { return U64BitwiseNot( val ); }
00234 _STLP_TEMPLATE_NULL
00235 inline bool operator!(const _compound_int<UnsignedWide>& val) { return !((val.hi == 0) && (val.lo == 0)); }
00236 
00237 #  endif // TYPE_LONGLONG
00238 #endif // __MRC__
00239 
00240 #endif // _UINT64_H



Generated on Mon Mar 10 15:32:17 2008 by  doxygen 1.5.1