X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8b81872f2efe2948592096f155729ec4ba5640a2..955be36cf87ac32dd0d5d98b447a3189c1573c19:/include/wx/longlong.h diff --git a/include/wx/longlong.h b/include/wx/longlong.h index 5f0b712947..c9b582b7a3 100644 --- a/include/wx/longlong.h +++ b/include/wx/longlong.h @@ -24,11 +24,12 @@ // ---------------------------------------------------------------------------- // to avoid compilation problems on 64bit machines with ambiguous method calls -// we will need this +// we will need to define this #undef wxLongLongIsLong // NB: we #define and not typedef wxLongLong_t because we want to be able to -// use 'unsigned wxLongLong_t' as well +// use 'unsigned wxLongLong_t' as well and because we use "#ifdef +// wxLongLong_t" below #if defined(SIZEOF_LONG) && (SIZEOF_LONG == 8) #define wxLongLong_t long #define wxLongLongIsLong @@ -57,6 +58,11 @@ #define wxUSE_LONGLONG_NATIVE 0 class WXDLLEXPORT wxLongLongWx; typedef wxLongLongWx wxLongLong; +#else + // if nothing is defined, use native implementation by default, of course + #ifndef wxUSE_LONGLONG_NATIVE + #define wxUSE_LONGLONG_NATIVE 1 + #endif #endif #ifndef wxUSE_LONGLONG_WX @@ -93,7 +99,7 @@ public: m_ll |= (wxLongLong_t) lo; } - // default copy ctor is ok in both cases + // default copy ctor is ok // no dtor @@ -107,15 +113,20 @@ public: // accessors // get high part long GetHi() const - { return (long)((m_ll & 0xFFFFFFFF00000000ll) >> 32); } + { return (long)(m_ll >> 32); } // get low part unsigned long GetLo() const - { return (unsigned long) (m_ll & 0x00000000FFFFFFFFll); } + { return (unsigned long)m_ll; } + + // get absolute value + wxLongLongNative& Abs() { if ( m_ll < 0 ) m_ll = -m_ll; return *this; } // convert to native long long wxLongLong_t GetValue() const { return m_ll; } - operator wxLongLong_t() const { return m_ll; } + // don't provide implicit conversion to wxLongLong_t or we will have an + // ambiguity for all arithmetic operations + //operator wxLongLong_t() const { return m_ll; } // operations // addition @@ -189,40 +200,62 @@ public: wxLongLongNative& operator^=(const wxLongLongNative& ll) { m_ll ^= ll.m_ll; return *this; } - // multiplication/division TODO + // multiplication/division wxLongLongNative operator*(const wxLongLongNative& ll) const { return wxLongLongNative(m_ll * ll.m_ll); } + wxLongLongNative operator*(long l) const + { return wxLongLongNative(m_ll * l); } wxLongLongNative& operator*=(const wxLongLongNative& ll) { m_ll *= ll.m_ll; return *this; } + wxLongLongNative& operator*=(long l) + { m_ll *= l; return *this; } wxLongLongNative operator/(const wxLongLongNative& ll) const { return wxLongLongNative(m_ll / ll.m_ll); } + wxLongLongNative operator/(long l) const + { return wxLongLongNative(m_ll / l); } wxLongLongNative& operator/=(const wxLongLongNative& ll) { m_ll /= ll.m_ll; return *this; } + wxLongLongNative& operator/=(long l) + { m_ll /= l; return *this; } wxLongLongNative operator%(const wxLongLongNative& ll) const { return wxLongLongNative(m_ll % ll.m_ll); } + wxLongLongNative operator%(long l) const + { return wxLongLongNative(m_ll % l); } // comparison bool operator==(const wxLongLongNative& ll) const { return m_ll == ll.m_ll; } + bool operator==(long l) const + { return m_ll == l; } bool operator!=(const wxLongLongNative& ll) const { return m_ll != ll.m_ll; } + bool operator!=(long l) const + { return m_ll != l; } bool operator<(const wxLongLongNative& ll) const { return m_ll < ll.m_ll; } + bool operator<(long l) const + { return m_ll < l; } bool operator>(const wxLongLongNative& ll) const { return m_ll > ll.m_ll; } + bool operator>(long l) const + { return m_ll > l; } bool operator<=(const wxLongLongNative& ll) const { return m_ll <= ll.m_ll; } + bool operator<=(long l) const + { return m_ll <= l; } bool operator>=(const wxLongLongNative& ll) const { return m_ll >= ll.m_ll; } + bool operator>=(long l) const + { return m_ll >= l; } // miscellaneous // conversion to byte array: returns a pointer to static buffer! void *asArray() const; // input/output - friend std::ostream& operator<<(ostream&, const wxLongLongNative&); + friend ostream& operator<<(ostream&, const wxLongLongNative&); private: wxLongLong_t m_ll; @@ -324,7 +357,7 @@ public: wxLongLongWx& remainder) const; // input/output - friend ostream& operator<<(std::ostream&, const wxLongLongWx&); + friend ostream& operator<<(ostream&, const wxLongLongWx&); private: // long is at least 32 bits, so represent our 64bit number as 2 longs