X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b76b015ed9231ffe128ddba9fb35e37b4be9764d..c51deffc32ff80f4ed13a1095bbf2ff44de89505:/include/wx/longlong.h?ds=sidebyside diff --git a/include/wx/longlong.h b/include/wx/longlong.h index cedac4f92b..1e5ee03100 100644 --- a/include/wx/longlong.h +++ b/include/wx/longlong.h @@ -19,16 +19,23 @@ #pragma interface "longlong.h" #endif +#include "wx/defs.h" +#include "wx/wxchar.h" +#include "wx/debug.h" + +#include // for LONG_MAX + // ---------------------------------------------------------------------------- // decide upon which class we will use // ---------------------------------------------------------------------------- // 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 @@ -98,7 +105,7 @@ public: m_ll |= (wxLongLong_t) lo; } - // default copy ctor is ok in both cases + // default copy ctor is ok // no dtor @@ -112,10 +119,10 @@ public: // accessors // get high part long GetHi() const - { return (long)((m_ll & 0xFFFFFFFF00000000l) >> 32); } + { return (long)(m_ll >> 32); } // get low part unsigned long GetLo() const - { return (unsigned long) (m_ll & 0x00000000FFFFFFFFl); } + { return (unsigned long)m_ll; } // get absolute value wxLongLongNative& Abs() { if ( m_ll < 0 ) m_ll = -m_ll; return *this; } @@ -123,6 +130,17 @@ public: // convert to native long long wxLongLong_t GetValue() const { return m_ll; } + // convert to long with range checking in the debug mode (only!) + long ToLong() const + { + wxASSERT_MSG( (m_ll >= LONG_MIN) && (m_ll <= LONG_MAX), + _T("wxLongLong to long conversion loss of precision") ); + + return (long)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 @@ -200,8 +218,12 @@ public: // 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); } @@ -209,6 +231,8 @@ public: { 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); } @@ -245,8 +269,10 @@ public: // conversion to byte array: returns a pointer to static buffer! void *asArray() const; +#if wxUSE_STD_IOSTREAM // input/output friend ostream& operator<<(ostream&, const wxLongLongNative&); +#endif private: wxLongLong_t m_ll; @@ -347,8 +373,10 @@ public: wxLongLongWx& quotient, wxLongLongWx& remainder) const; +#if wxUSE_STD_IOSTREAM // input/output friend ostream& operator<<(ostream&, const wxLongLongWx&); +#endif // wxUSE_STD_IOSTREAM private: // long is at least 32 bits, so represent our 64bit number as 2 longs