{\it long long} type if it exists and {\it long}.
You would usually use this type in exactly the same manner as any other
-(built-in) arithmetic type. Note that wxLongLong is a signed type.
+(built-in) arithmetic type. Note that wxLongLong is a signed type, if you
+want unsigned values use wxULongLong.
If a native (i.e. supported directly by the compiler) 64 bit integer type was
found a typedef {\it wxLongLong\_t} will be defined to correspond it.
\func{wxLongLong\&}{Abs}{\void}
Returns an absolute value of wxLongLong - either making a copy (const version)
-or modifying it in place (the second one).
+or modifying it in place (the second one). Not in wxULongLong.
\membersection{wxLongLong::Assign}\label{wxlonglongassign}
This allows to convert a double value to wxLongLong type. Such conversion is
not always possible in which case the result will be silently truncated in a
-platform-dependent way.
+platform-dependent way. Not in wxULongLong.
\membersection{wxLongLong::GetHi}\label{wxlonglonggethi}
\constfunc{wxLongLong}{operator$-$}{\void}
-Returns the value of this wxLongLong with opposite sign.
+Returns the value of this wxLongLong with opposite sign. Not in wxULongLong.
\membersection{wxLongLong::operator$-$}\label{wxlonglongoperatorminus}
#define wxUint64 long long unsigned
#else // FIXME: what else can we do here aside from implementing wxULongLong
#define wxInt64 wxLongLong
-#define wxUint64 wxLongLong
+#define wxUint64 wxULongLong
#endif
#define wxByte wxUint8
#endif
// machine specific byte swapping
+#if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8)
+#define wxUINT64_SWAP_ALWAYS(val) \
+ ((wxUint64) ( \
+ (((wxUint64) (val) & (wxUint64) 0x00000000000000ffUL) << 56) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000000000ff00UL) << 40) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000000000ff0000UL) << 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00000000ff000000UL) << 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000ff00000000UL) >> 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000ff0000000000UL) >> 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00ff000000000000UL) >> 40) | \
+ (((wxUint64) (val) & (wxUint64) 0xff00000000000000UL) >> 56)))
+
+#define wxINT64_SWAP_ALWAYS(val) \
+ ((wxInt64) ( \
+ (((wxUint64) (val) & (wxUint64) 0x00000000000000ffUL) << 56) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000000000ff00UL) << 40) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000000000ff0000UL) << 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00000000ff000000UL) << 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000ff00000000UL) >> 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000ff0000000000UL) >> 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00ff000000000000UL) >> 40) | \
+ (((wxUint64) (val) & (wxUint64) 0xff00000000000000UL) >> 56)))
+
+#elif defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG_LONG == 8)
+#define wxUINT64_SWAP_ALWAYS(val) \
+ ((wxUint64) ( \
+ (((wxUint64) (val) & (wxUint64) 0x00000000000000ffULL) << 56) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000000000ff00ULL) << 40) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000000000ff0000ULL) << 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00000000ff000000ULL) << 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000ff00000000ULL) >> 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000ff0000000000ULL) >> 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00ff000000000000ULL) >> 40) | \
+ (((wxUint64) (val) & (wxUint64) 0xff00000000000000ULL) >> 56)))
+
+#define wxINT64_SWAP_ALWAYS(val) \
+ ((wxInt64) ( \
+ (((wxUint64) (val) & (wxUint64) 0x00000000000000ffULL) << 56) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000000000ff00ULL) << 40) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000000000ff0000ULL) << 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00000000ff000000ULL) << 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x000000ff00000000ULL) >> 8) | \
+ (((wxUint64) (val) & (wxUint64) 0x0000ff0000000000ULL) >> 24) | \
+ (((wxUint64) (val) & (wxUint64) 0x00ff000000000000ULL) >> 40) | \
+ (((wxUint64) (val) & (wxUint64) 0xff00000000000000ULL) >> 56)))
+
+#else
#define wxUINT64_SWAP_ALWAYS(val) \
((wxUint64) ( \
((wxLongLong(val) & wxLongLong(0L, 0x000000ffU)) << 56) | \
((wxLongLong(val) & wxLongLong(0x000000ffL, 0U)) >> 8) | \
((wxLongLong(val) & wxLongLong(0x0000ff00L, 0U)) >> 24) | \
((wxLongLong(val) & wxLongLong(0x00ff0000L, 0U)) >> 40) | \
- ((wxLongLong(val) & wxLongLong(0xff000000L, 0U)) >> 56)).GetValue())
+ ((wxLongLong(val) & wxLongLong(0xff000000L, 0U)) >> 56)))
#define wxINT64_SWAP_ALWAYS(val) \
((wxInt64) ( \
((wxLongLong(val) & wxLongLong(0x000000ffL, 0U)) >> 8) | \
((wxLongLong(val) & wxLongLong(0x0000ff00L, 0U)) >> 24) | \
((wxLongLong(val) & wxLongLong(0x00ff0000L, 0U)) >> 40) | \
- ((wxLongLong(val) & wxLongLong(0xff000000L, 0U)) >> 56)).GetValue())
-
+ ((wxLongLong(val) & wxLongLong(0xff000000L, 0U)) >> 56)))
+#endif
#ifdef WORDS_BIGENDIAN
#define wxUINT16_SWAP_ON_BE(val) wxUINT16_SWAP_ALWAYS(val)
class WXDLLEXPORT wxLongLongWx;
#if defined(__VISUALC__) && !defined(__WIN32__)
#define wxLongLong wxLongLongWx
+ #define wxULongLong wxULongLongWx
#else
typedef wxLongLongWx wxLongLong;
+ typedef wxULongLongWx wxULongLong;
#endif
#else
#ifndef wxUSE_LONGLONG_WX
#define wxUSE_LONGLONG_WX 0
class WXDLLEXPORT wxLongLongNative;
+ class WXDLLEXPORT wxULongLongNative;
typedef wxLongLongNative wxLongLong;
+ typedef wxULongLongNative wxULongLong;
#endif
// NB: if both wxUSE_LONGLONG_WX and NATIVE are defined, the user code should
// convert to native long long
wxLongLong_t GetValue() const { return m_ll; }
+ // implicit conversion for times when we want a native type
+ // or wxLongLong, NOT wxLongLongNative and without having
+ // to ifdef user code for each use.
+ operator wxLongLong_t() const { return m_ll; }
+
// convert to long with range checking in the debug mode (only!)
long ToLong() const
{
wxLongLong_t m_ll;
};
+
+class WXDLLEXPORT wxULongLongNative
+{
+public:
+ // ctors
+ // default ctor initializes to 0
+ wxULongLongNative() { m_ll = 0; }
+ // from long long
+ wxULongLongNative(unsigned wxLongLong_t ll) { m_ll = ll; }
+ // from 2 longs
+ wxULongLongNative(unsigned long hi, unsigned long lo)
+ {
+ // assign first to avoid precision loss!
+ m_ll = ((unsigned wxLongLong_t) hi) << 32;
+ m_ll |= (unsigned wxLongLong_t) lo;
+ }
+
+ // default copy ctor is ok
+
+ // no dtor
+
+ // assignment operators
+ // from native 64 bit integer
+ wxULongLongNative& operator=(unsigned wxLongLong_t ll)
+ { m_ll = ll; return *this; }
+
+ // assignment operators from wxULongLongNative is ok
+
+ // accessors
+ // get high part
+ unsigned long GetHi() const
+ { return (unsigned long)(m_ll >> 32); }
+ // get low part
+ unsigned long GetLo() const
+ { return (unsigned long)m_ll; }
+
+ // convert to native ulong long
+ unsigned wxLongLong_t GetValue() const { return m_ll; }
+
+ // convert to ulong with range checking in the debug mode (only!)
+ unsigned long ToULong() const
+ {
+ wxASSERT_MSG( (m_ll >= LONG_MIN) && (m_ll <= LONG_MAX),
+ _T("wxULongLong to long conversion loss of precision") );
+
+ return (unsigned long)m_ll;
+ }
+
+ // don't provide implicit conversion to unsigned wxLongLong_t or we
+ // will have an ambiguity for all arithmetic operations
+ //operator wxULongLong_t() const { return m_ll; }
+
+ // operations
+ // addition
+ wxULongLongNative operator+(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll + ll.m_ll); }
+ wxULongLongNative& operator+=(const wxULongLongNative& ll)
+ { m_ll += ll.m_ll; return *this; }
+
+ wxULongLongNative operator+(const unsigned wxLongLong_t ll) const
+ { return wxULongLongNative(m_ll + ll); }
+ wxULongLongNative& operator+=(const unsigned wxLongLong_t ll)
+ { m_ll += ll; return *this; }
+
+ // pre increment
+ wxULongLongNative& operator++()
+ { m_ll++; return *this; }
+
+ // post increment
+ wxULongLongNative& operator++(int)
+ { m_ll++; return *this; }
+
+ // subtraction
+ wxULongLongNative operator-(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll - ll.m_ll); }
+ wxULongLongNative& operator-=(const wxULongLongNative& ll)
+ { m_ll -= ll.m_ll; return *this; }
+
+ wxULongLongNative operator-(const unsigned wxLongLong_t ll) const
+ { return wxULongLongNative(m_ll - ll); }
+ wxULongLongNative& operator-=(const unsigned wxLongLong_t ll)
+ { m_ll -= ll; return *this; }
+
+ // pre decrement
+ wxULongLongNative& operator--()
+ { m_ll--; return *this; }
+
+ // post decrement
+ wxULongLongNative& operator--(int)
+ { m_ll--; return *this; }
+
+ // shifts
+ // left shift
+ wxULongLongNative operator<<(int shift) const
+ { return wxULongLongNative(m_ll << shift);; }
+ wxULongLongNative& operator<<=(int shift)
+ { m_ll <<= shift; return *this; }
+
+ // right shift
+ wxULongLongNative operator>>(int shift) const
+ { return wxULongLongNative(m_ll >> shift);; }
+ wxULongLongNative& operator>>=(int shift)
+ { m_ll >>= shift; return *this; }
+
+ // bitwise operators
+ wxULongLongNative operator&(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll & ll.m_ll); }
+ wxULongLongNative& operator&=(const wxULongLongNative& ll)
+ { m_ll &= ll.m_ll; return *this; }
+
+ wxULongLongNative operator|(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll | ll.m_ll); }
+ wxULongLongNative& operator|=(const wxULongLongNative& ll)
+ { m_ll |= ll.m_ll; return *this; }
+
+ wxULongLongNative operator^(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll ^ ll.m_ll); }
+ wxULongLongNative& operator^=(const wxULongLongNative& ll)
+ { m_ll ^= ll.m_ll; return *this; }
+
+ // multiplication/division
+ wxULongLongNative operator*(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll * ll.m_ll); }
+ wxULongLongNative operator*(unsigned long l) const
+ { return wxULongLongNative(m_ll * l); }
+ wxULongLongNative& operator*=(const wxULongLongNative& ll)
+ { m_ll *= ll.m_ll; return *this; }
+ wxULongLongNative& operator*=(unsigned long l)
+ { m_ll *= l; return *this; }
+
+ wxULongLongNative operator/(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll / ll.m_ll); }
+ wxULongLongNative operator/(unsigned long l) const
+ { return wxULongLongNative(m_ll / l); }
+ wxULongLongNative& operator/=(const wxULongLongNative& ll)
+ { m_ll /= ll.m_ll; return *this; }
+ wxULongLongNative& operator/=(unsigned long l)
+ { m_ll /= l; return *this; }
+
+ wxULongLongNative operator%(const wxULongLongNative& ll) const
+ { return wxULongLongNative(m_ll % ll.m_ll); }
+ wxULongLongNative operator%(unsigned long l) const
+ { return wxULongLongNative(m_ll % l); }
+
+ // comparison
+ bool operator==(const wxULongLongNative& ll) const
+ { return m_ll == ll.m_ll; }
+ bool operator==(unsigned long l) const
+ { return m_ll == l; }
+ bool operator!=(const wxULongLongNative& ll) const
+ { return m_ll != ll.m_ll; }
+ bool operator!=(unsigned long l) const
+ { return m_ll != l; }
+ bool operator<(const wxULongLongNative& ll) const
+ { return m_ll < ll.m_ll; }
+ bool operator<(unsigned long l) const
+ { return m_ll < l; }
+ bool operator>(const wxULongLongNative& ll) const
+ { return m_ll > ll.m_ll; }
+ bool operator>(unsigned long l) const
+ { return m_ll > l; }
+ bool operator<=(const wxULongLongNative& ll) const
+ { return m_ll <= ll.m_ll; }
+ bool operator<=(unsigned long l) const
+ { return m_ll <= l; }
+ bool operator>=(const wxULongLongNative& ll) const
+ { return m_ll >= ll.m_ll; }
+ bool operator>=(unsigned long l) const
+ { return m_ll >= l; }
+
+ // miscellaneous
+
+ // return the string representation of this number
+ wxString ToString() const;
+
+ // conversion to byte array: returns a pointer to static buffer!
+ void *asArray() const;
+
+#if wxUSE_STD_IOSTREAM
+ // input/output
+ friend wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongNative&);
+#endif
+
+private:
+ unsigned wxLongLong_t m_ll;
+};
+
#endif // wxUSE_LONGLONG_NATIVE
#if wxUSE_LONGLONG_WX
#endif // wxLONGLONG_TEST_MODE
};
+
+class WXDLLEXPORT wxULongLongWx
+{
+public:
+ // ctors
+ // default ctor initializes to 0
+ wxULongLongWx()
+ {
+ m_lo = m_hi = 0;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll = 0;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+ }
+ // from ulong
+ wxULongLongWx(unsigned long l) { *this = l; }
+ // from 2 ulongs
+ wxULongLongWx(unsigned long hi, unsigned long lo)
+ {
+ m_hi = hi;
+ m_lo = lo;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll = hi;
+ m_ll <<= 32;
+ m_ll |= lo;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+ }
+
+ // default copy ctor is ok in both cases
+
+ // no dtor
+
+ // assignment operators
+ // from long
+ wxULongLongWx& operator=(unsigned long l)
+ {
+ m_lo = l;
+ m_hi = 0;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll = l;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+ }
+
+ // can't have assignment operator from 2 longs
+
+ // accessors
+ // get high part
+ unsigned long GetHi() const { return m_hi; }
+ // get low part
+ unsigned long GetLo() const { return m_lo; }
+
+ // convert to long with range checking in the debug mode (only!)
+ unsigned long ToULong() const
+ {
+ wxASSERT_MSG( (m_hi == 0l),
+ _T("wxULongLong to long conversion loss of precision") );
+
+ return (unsigned long)m_lo;
+ }
+
+ // operations
+ // addition
+ wxULongLongWx operator+(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator+=(const wxULongLongWx& ll);
+ wxULongLongWx operator+(unsigned long l) const;
+ wxULongLongWx& operator+=(unsigned long l);
+
+ // pre increment operator
+ wxULongLongWx& operator++();
+
+ // post increment operator
+ wxULongLongWx& operator++(int) { return ++(*this); }
+
+ // subraction
+ wxULongLongWx operator-(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator-=(const wxULongLongWx& ll);
+
+ // pre decrement operator
+ wxULongLongWx& operator--();
+
+ // post decrement operator
+ wxULongLongWx& operator--(int) { return --(*this); }
+
+ // shifts
+ // left shift
+ wxULongLongWx operator<<(int shift) const;
+ wxULongLongWx& operator<<=(int shift);
+
+ // right shift
+ wxULongLongWx operator>>(int shift) const;
+ wxULongLongWx& operator>>=(int shift);
+
+ // bitwise operators
+ wxULongLongWx operator&(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator&=(const wxULongLongWx& ll);
+ wxULongLongWx operator|(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator|=(const wxULongLongWx& ll);
+ wxULongLongWx operator^(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator^=(const wxULongLongWx& ll);
+ wxULongLongWx operator~() const;
+
+ // comparison
+ bool operator==(const wxULongLongWx& ll) const
+ { return m_lo == ll.m_lo && m_hi == ll.m_hi; }
+ bool operator!=(const wxULongLongWx& ll) const
+ { return !(*this == ll); }
+ bool operator<(const wxULongLongWx& ll) const;
+ bool operator>(const wxULongLongWx& ll) const;
+ bool operator<=(const wxULongLongWx& ll) const
+ { return *this < ll || *this == ll; }
+ bool operator>=(const wxULongLongWx& ll) const
+ { return *this > ll || *this == ll; }
+
+ bool operator<(unsigned long l) const { return *this < wxULongLongWx(l); }
+ bool operator>(unsigned long l) const { return *this > wxULongLongWx(l); }
+ bool operator==(unsigned long l) const
+ {
+ return (m_hi == 0 && m_lo == (unsigned long)l);
+ }
+
+ bool operator<=(unsigned long l) const { return *this < l || *this == l; }
+ bool operator>=(unsigned long l) const { return *this > l || *this == l; }
+
+ // multiplication
+ wxULongLongWx operator*(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator*=(const wxULongLongWx& ll);
+
+ // division
+ wxULongLongWx operator/(const wxULongLongWx& ll) const;
+ wxULongLongWx& operator/=(const wxULongLongWx& ll);
+
+ wxULongLongWx operator%(const wxULongLongWx& ll) const;
+
+ void Divide(const wxULongLongWx& divisor,
+ wxULongLongWx& quotient,
+ wxULongLongWx& remainder) const;
+
+ // input/output
+
+ // return the string representation of this number
+ wxString ToString() const;
+
+ void *asArray() const;
+
+#if wxUSE_STD_IOSTREAM
+ friend wxSTD ostream& operator<<(wxSTD ostream&, const wxULongLongWx&);
+#endif // wxUSE_STD_IOSTREAM
+
+private:
+ // long is at least 32 bits, so represent our 64bit number as 2 longs
+
+ unsigned long m_hi
+ unsigned long m_lo;
+
+#ifdef wxLONGLONG_TEST_MODE
+ void Check()
+ {
+ wxASSERT( (m_ll >> 32) == m_hi && (unsigned long)m_ll == m_lo );
+ }
+
+ unsigned wxLongLong_t m_ll;
+#endif // wxLONGLONG_TEST_MODE
+};
+
#endif // wxUSE_LONGLONG_WX
// ----------------------------------------------------------------------------
inline wxLongLong operator+(long l, const wxLongLong& ll) { return ll + l; }
inline wxLongLong operator-(long l, const wxLongLong& ll) { return ll - l; }
+inline bool operator<(unsigned long l, const wxULongLong& ll) { return ll > l; }
+inline bool operator>(unsigned long l, const wxULongLong& ll) { return ll > l; }
+inline bool operator<=(unsigned long l, const wxULongLong& ll) { return ll > l; }
+inline bool operator>=(unsigned long l, const wxULongLong& ll) { return ll > l; }
+inline bool operator==(unsigned long l, const wxULongLong& ll) { return ll > l; }
+inline bool operator!=(unsigned long l, const wxULongLong& ll) { return ll > l; }
+
+inline wxULongLong operator+(unsigned long l, const wxULongLong& ll) { return ll + l; }
+inline wxULongLong operator-(unsigned long l, const wxULongLong& ll) { return ll - l; }
+
#endif // _WX_LONGLONG_H
return temp;
}
+void *wxULongLongNative::asArray() const
+{
+ static unsigned char temp[8];
+
+ temp[0] = (m_ll >> 56) & 0xFF;
+ temp[1] = (m_ll >> 48) & 0xFF;
+ temp[2] = (m_ll >> 40) & 0xFF;
+ temp[3] = (m_ll >> 32) & 0xFF;
+ temp[4] = (m_ll >> 24) & 0xFF;
+ temp[5] = (m_ll >> 16) & 0xFF;
+ temp[6] = (m_ll >> 8) & 0xFF;
+ temp[7] = (m_ll >> 0) & 0xFF;
+
+ return temp;
+}
+
#endif // wxUSE_LONGLONG_NATIVE
// ============================================================================
return ll;
}
+wxULongLongWx wxULongLongWx::operator<<(int shift) const
+{
+ wxULongLongWx ll(*this);
+ ll <<= shift;
+
+ return ll;
+}
+
wxLongLongWx& wxLongLongWx::operator<<=(int shift)
{
if (shift != 0)
return *this;
}
+wxULongLongWx& wxULongLongWx::operator<<=(int shift)
+{
+ if (shift != 0)
+ {
+ if (shift < 32)
+ {
+ m_hi <<= shift;
+ m_hi |= m_lo >> (32 - shift);
+ m_lo <<= shift;
+ }
+ else
+ {
+ m_hi = m_lo << (shift - 32);
+ m_lo = 0;
+ }
+ }
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll <<= shift;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
wxLongLongWx wxLongLongWx::operator>>(int shift) const
{
wxLongLongWx ll(*this);
return ll;
}
+wxULongLongWx wxULongLongWx::operator>>(int shift) const
+{
+ wxULongLongWx ll(*this);
+ ll >>= shift;
+
+ return ll;
+}
+
wxLongLongWx& wxLongLongWx::operator>>=(int shift)
{
if (shift != 0)
return *this;
}
+wxULongLongWx& wxULongLongWx::operator>>=(int shift)
+{
+ if (shift != 0)
+ {
+ if (shift < 32)
+ {
+ m_lo >>= shift;
+ m_lo |= m_hi << (32 - shift);
+ m_hi >>= shift;
+ }
+ else
+ {
+ m_lo = m_hi >> (shift - 32);
+ m_hi = 0;
+ }
+ }
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll >>= shift;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
wxLongLongWx wxLongLongWx::operator+(const wxLongLongWx& ll) const
{
wxLongLongWx res(*this);
return res;
}
+wxULongLongWx wxULongLongWx::operator+(const wxULongLongWx& ll) const
+{
+ wxULongLongWx res(*this);
+ res += ll;
+
+ return res;
+}
+
wxLongLongWx wxLongLongWx::operator+(long l) const
{
wxLongLongWx res(*this);
return res;
}
+wxULongLongWx wxULongLongWx::operator+(unsigned long l) const
+{
+ wxULongLongWx res(*this);
+ res += l;
+
+ return res;
+}
+
wxLongLongWx& wxLongLongWx::operator+=(const wxLongLongWx& ll)
{
unsigned long previous = m_lo;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator+=(const wxULongLongWx& ll)
+{
+ unsigned long previous = m_lo;
+
+ m_lo += ll.m_lo;
+ m_hi += ll.m_hi;
+
+ if ((m_lo < previous) || (m_lo < ll.m_lo))
+ m_hi++;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll += ll.m_ll;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
wxLongLongWx& wxLongLongWx::operator+=(long l)
{
unsigned long previous = m_lo;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator+=(unsigned long l)
+{
+ unsigned long previous = m_lo;
+
+ m_lo += l;
+
+ if ((m_lo < previous) || (m_lo < l))
+ m_hi++;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll += l;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
// pre increment
wxLongLongWx& wxLongLongWx::operator++()
{
return *this;
}
+wxULongLongWx& wxULongLongWx::operator++()
+{
+ m_lo++;
+ if (m_lo == 0)
+ m_hi++;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll++;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
// negation
wxLongLongWx wxLongLongWx::operator-() const
{
return res;
}
+wxULongLongWx wxULongLongWx::operator-(const wxULongLongWx& ll) const
+{
+ wxULongLongWx res(*this);
+ res -= ll;
+
+ return res;
+}
+
wxLongLongWx& wxLongLongWx::operator-=(const wxLongLongWx& ll)
{
unsigned long previous = m_lo;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator-=(const wxULongLongWx& ll)
+{
+ unsigned long previous = m_lo;
+
+ m_lo -= ll.m_lo;
+ m_hi -= ll.m_hi;
+
+ if (previous < ll.m_lo)
+ m_hi--;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll -= ll.m_ll;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
// pre decrement
wxLongLongWx& wxLongLongWx::operator--()
{
return *this;
}
+wxULongLongWx& wxULongLongWx::operator--()
+{
+ m_lo--;
+ if (m_lo == 0xFFFFFFFF)
+ m_hi--;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll--;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
// comparison operators
bool wxLongLongWx::operator<(const wxLongLongWx& ll) const
return FALSE;
}
+bool wxULongLongWx::operator<(const wxULongLongWx& ll) const
+{
+ if ( m_hi < ll.m_hi )
+ return TRUE;
+ else if ( m_hi == ll.m_hi )
+ return m_lo < ll.m_lo;
+ else
+ return FALSE;
+}
+
bool wxLongLongWx::operator>(const wxLongLongWx& ll) const
{
if ( m_hi > ll.m_hi )
return FALSE;
}
+bool wxULongLongWx::operator>(const wxULongLongWx& ll) const
+{
+ if ( m_hi > ll.m_hi )
+ return TRUE;
+ else if ( m_hi == ll.m_hi )
+ return m_lo > ll.m_lo;
+ else
+ return FALSE;
+}
+
// bitwise operators
wxLongLongWx wxLongLongWx::operator&(const wxLongLongWx& ll) const
return wxLongLongWx(m_hi & ll.m_hi, m_lo & ll.m_lo);
}
+wxULongLongWx wxULongLongWx::operator&(const wxULongLongWx& ll) const
+{
+ return wxULongLongWx(m_hi & ll.m_hi, m_lo & ll.m_lo);
+}
+
wxLongLongWx wxLongLongWx::operator|(const wxLongLongWx& ll) const
{
return wxLongLongWx(m_hi | ll.m_hi, m_lo | ll.m_lo);
}
+wxULongLongWx wxULongLongWx::operator|(const wxULongLongWx& ll) const
+{
+ return wxULongLongWx(m_hi | ll.m_hi, m_lo | ll.m_lo);
+}
+
wxLongLongWx wxLongLongWx::operator^(const wxLongLongWx& ll) const
{
return wxLongLongWx(m_hi ^ ll.m_hi, m_lo ^ ll.m_lo);
}
+wxULongLongWx wxULongLongWx::operator^(const wxULongLongWx& ll) const
+{
+ return wxULongLongWx(m_hi ^ ll.m_hi, m_lo ^ ll.m_lo);
+}
+
wxLongLongWx& wxLongLongWx::operator&=(const wxLongLongWx& ll)
{
m_lo &= ll.m_lo;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator&=(const wxULongLongWx& ll)
+{
+ m_lo &= ll.m_lo;
+ m_hi &= ll.m_hi;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll &= ll.m_ll;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
wxLongLongWx& wxLongLongWx::operator|=(const wxLongLongWx& ll)
{
m_lo |= ll.m_lo;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator|=(const wxULongLongWx& ll)
+{
+ m_lo |= ll.m_lo;
+ m_hi |= ll.m_hi;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll |= ll.m_ll;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
wxLongLongWx& wxLongLongWx::operator^=(const wxLongLongWx& ll)
{
m_lo ^= ll.m_lo;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator^=(const wxULongLongWx& ll)
+{
+ m_lo ^= ll.m_lo;
+ m_hi ^= ll.m_hi;
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll ^= ll.m_ll;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
wxLongLongWx wxLongLongWx::operator~() const
{
return wxLongLongWx(~m_hi, ~m_lo);
}
+wxULongLongWx wxULongLongWx::operator~() const
+{
+ return wxULongLongWx(~m_hi, ~m_lo);
+}
+
// multiplication
wxLongLongWx wxLongLongWx::operator*(const wxLongLongWx& ll) const
return res;
}
+wxULongLongWx wxULongLongWx::operator*(const wxULongLongWx& ll) const
+{
+ wxULongLongWx res(*this);
+ res *= ll;
+
+ return res;
+}
+
wxLongLongWx& wxLongLongWx::operator*=(const wxLongLongWx& ll)
{
wxLongLongWx t(m_hi, m_lo);
return *this;
}
+wxULongLongWx& wxULongLongWx::operator*=(const wxULongLongWx& ll)
+{
+ wxULongLongWx t(m_hi, m_lo);
+ wxULongLongWx q(ll.m_hi, ll.m_lo);
+
+ m_hi = m_lo = 0;
+
+#ifdef wxLONGLONG_TEST_MODE
+ unsigned wxLongLong_t llOld = m_ll;
+ m_ll = 0;
+#endif // wxLONGLONG_TEST_MODE
+
+ int counter = 0;
+ do
+ {
+ if ((q.m_lo & 1) != 0)
+ *this += t;
+ q >>= 1;
+ t <<= 1;
+ counter++;
+ }
+ while ((counter < 64) && ((q.m_hi != 0) || (q.m_lo != 0)));
+
+#ifdef wxLONGLONG_TEST_MODE
+ m_ll = llOld * ll.m_ll;
+
+ Check();
+#endif // wxLONGLONG_TEST_MODE
+
+ return *this;
+}
+
// division
void wxLongLongWx::Divide(const wxLongLongWx& divisorIn,
}
}
+void wxULongLongWx::Divide(const wxULongLongWx& divisorIn,
+ wxULongLongWx& quotient,
+ wxULongLongWx& remainder) const
+{
+ if ((divisorIn.m_lo == 0) && (divisorIn.m_hi == 0))
+ {
+ // provoke division by zero error and silence the compilers warnings
+ // about an expression without effect and unused variable
+ unsigned long dummy = divisorIn.m_lo/divisorIn.m_hi;
+ dummy += 0;
+ }
+
+ // VZ: I'm writing this in a hurry and it's surely not the fastest way to
+ // do this - any improvements are more than welcome
+ //
+ // code inspired by the snippet at
+ // http://www.bearcave.com/software/divide.htm
+ //
+ // Copyright notice:
+ //
+ // Use of this program, for any purpose, is granted the author, Ian
+ // Kaplan, as long as this copyright notice is included in the source
+ // code or any source code derived from this program. The user assumes
+ // all responsibility for using this code.
+
+ // init everything
+ wxULongLongWx dividend = *this,
+ divisor = divisorIn;
+
+ quotient = 0l;
+ remainder = 0l;
+
+ // check for some particular cases
+ if ( divisor > dividend )
+ {
+ remainder = dividend;
+ }
+ else if ( divisor == dividend )
+ {
+ quotient = 1l;
+ }
+ else
+ {
+ // here: dividend > divisor
+ size_t nBits = 64u;
+ wxULongLongWx d;
+
+ #define IS_MSB_SET(ll) ((ll.m_hi) & (1 << (8*sizeof(long) - 1)))
+
+ while ( remainder < divisor )
+ {
+ remainder <<= 1;
+ if ( IS_MSB_SET(dividend) )
+ {
+ remainder |= 1;
+ }
+
+ d = dividend;
+ dividend <<= 1;
+
+ nBits--;
+ }
+
+ // undo the last loop iteration
+ dividend = d;
+ remainder >>= 1;
+ nBits++;
+
+ for ( size_t i = 0; i < nBits; i++ )
+ {
+ remainder <<= 1;
+ if ( IS_MSB_SET(dividend) )
+ {
+ remainder |= 1;
+ }
+
+ wxULongLongWx t = remainder - divisor;
+ dividend <<= 1;
+ quotient <<= 1;
+ if ( !IS_MSB_SET(t) )
+ {
+ quotient |= 1;
+
+ remainder = t;
+ }
+ }
+ }
+}
+
wxLongLongWx wxLongLongWx::operator/(const wxLongLongWx& ll) const
{
wxLongLongWx quotient, remainder;
return quotient;
}
+wxULongLongWx wxULongLongWx::operator/(const wxULongLongWx& ll) const
+{
+ wxULongLongWx quotient, remainder;
+
+ Divide(ll, quotient, remainder);
+
+ return quotient;
+}
+
wxLongLongWx& wxLongLongWx::operator/=(const wxLongLongWx& ll)
{
wxLongLongWx quotient, remainder;
return *this;
}
+wxULongLongWx& wxULongLongWx::operator/=(const wxULongLongWx& ll)
+{
+ wxLongLongWx quotient, remainder;
+
+ Divide(ll, quotient, remainder);
+
+ *this = quotient;
+
+ return *this;
+}
+
wxLongLongWx wxLongLongWx::operator%(const wxLongLongWx& ll) const
{
wxLongLongWx quotient, remainder;
return remainder;
}
+wxULongLongWx wxULongLongWx::operator%(const wxULongLongWx& ll) const
+{
+ wxULongLongWx quotient, remainder;
+
+ Divide(ll, quotient, remainder);
+
+ return remainder;
+}
+
// ----------------------------------------------------------------------------
// misc
// ----------------------------------------------------------------------------
return temp;
}
+void *wxULongLongWx::asArray(void) const
+{
+ static unsigned char temp[8];
+
+ temp[0] = (char)((m_hi >> 24) & 0xFF);
+ temp[1] = (char)((m_hi >> 16) & 0xFF);
+ temp[2] = (char)((m_hi >> 8) & 0xFF);
+ temp[3] = (char)((m_hi >> 0) & 0xFF);
+ temp[4] = (char)((m_lo >> 24) & 0xFF);
+ temp[5] = (char)((m_lo >> 16) & 0xFF);
+ temp[6] = (char)((m_lo >> 8) & 0xFF);
+ temp[7] = (char)((m_lo >> 0) & 0xFF);
+
+ return temp;
+}
+
#endif // wxUSE_LONGLONG_WX
wxString
return result;
}
+wxString
+#if wxUSE_LONGLONG_NATIVE
+wxULongLongNative::ToString() const
+#else
+wxULongLongWx::ToString() const
+#endif
+{
+ // TODO: this is awfully inefficient, anything better?
+ wxString result;
+
+ wxULongLong ll = *this;
+
+ while ( ll != 0 )
+ {
+ result.Prepend((wxChar)(_T('0') + (ll % 10).ToLong()));
+ ll /= 10;
+ }
+
+ if ( result.empty() )
+ result = _T('0');
+
+ return result;
+}
+
#if wxUSE_STD_IOSTREAM
// input/output
return o << ll.ToString();
}
+wxSTD ostream& operator<< (wxSTD ostream& o, const wxULongLong& ll)
+{
+ return o << ll.ToString();
+}
+
#endif // wxUSE_STD_IOSTREAM
#endif // wxUSE_LONGLONG