added support for 64 bit ints in wx stream classes (patch 1203970)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37497 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-02-11 16:51:34 +00:00
parent 87152bb53d
commit 216a72f3b9
10 changed files with 883 additions and 52 deletions

View File

@@ -25,6 +25,10 @@
#include "wx/longlong.h"
#include "wx/math.h" // for fabs()
#if wxUSE_STREAMS
#include "wx/txtstrm.h"
#endif
#if defined(__MWERKS__) && defined(__WXMSW__)
#include <string.h> // for memset()
#else
@@ -92,6 +96,41 @@ wxLongLongNative& wxLongLongNative::operator=(wxLongLongWx ll)
m_ll |= ll.GetLo();
return *this;
}
wxLongLongNative& wxLongLongNative::operator=(const class wxULongLongWx &ll)
{
// assign first to avoid precision loss!
m_ll = ll.GetHi();
m_ll <<= 32;
m_ll |= ll.GetLo();
return *this;
}
wxULongLongNative::wxULongLongNative(const class wxULongLongWx &ll)
{
// assign first to avoid precision loss!
m_ll = ll.GetHi();
m_ll <<= 32;
m_ll |= ((unsigned long) ll.GetLo());
}
wxULongLongNative& wxULongLongNative::operator=(wxLongLongWx ll)
{
// assign first to avoid precision loss!
m_ll = ll.GetHi();
m_ll <<= 32;
m_ll |= ((unsigned long) ll.GetLo());
return *this;
}
wxULongLongNative& wxULongLongNative::operator=(const class wxULongLongWx &ll)
{
// assign first to avoid precision loss!
m_ll = ll.GetHi();
m_ll <<= 32;
m_ll |= ((unsigned long) ll.GetLo());
return *this;
}
#endif
#endif // wxUSE_LONGLONG_NATIVE
@@ -102,6 +141,14 @@ wxLongLongNative& wxLongLongNative::operator=(wxLongLongWx ll)
#if wxUSE_LONGLONG_WX
// Set value from unsigned wxULongLongWx
wxLongLongWx &wxLongLongWx::operator=(const class wxULongLongWx &ll)
{
m_hi = (unsigned long) ll.GetHi();
m_lo = ll.GetLo();
return *this;
}
// assignment
wxLongLongWx& wxLongLongWx::Assign(double d)
{
@@ -1191,4 +1238,113 @@ WXDLLIMPEXP_BASE wxString& operator<< (wxString& s, const wxULongLong& ll)
return s << ll.ToString();
}
#if wxUSE_STREAMS
WXDLLIMPEXP_BASE wxTextOutputStream& operator<< (wxTextOutputStream& o, const wxULongLong& ll)
{
return o << ll.ToString();
}
WXDLLIMPEXP_BASE wxTextOutputStream& operator<< (wxTextOutputStream& o, const wxLongLong& ll)
{
return o << ll.ToString();
}
#define READ_STRING_CHAR(s, idx, len) ((wxChar) ((idx!=len) ? s[idx++] : 0))
WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &o, wxULongLong &ll)
{
wxString s = o.ReadWord();
ll = wxULongLong(0l, 0l);
size_t length = s.Length();
size_t idx = 0;
wxChar ch = READ_STRING_CHAR(s, idx, length);
// Skip WS
while (ch==wxT(' ') || ch==wxT('\t'))
ch = READ_STRING_CHAR(s, idx, length);
// Read number
wxULongLong multiplier(0l, 10l);
while (ch>=wxT('0') && ch<=wxT('9')) {
long lValue = (unsigned) (ch - wxT('0'));
ll = ll * multiplier + wxULongLong(0l, lValue);
ch = READ_STRING_CHAR(s, idx, length);
}
return o;
}
WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &o, wxLongLong &ll)
{
wxString s = o.ReadWord();
ll = wxLongLong(0l, 0l);
size_t length = s.Length();
size_t idx = 0;
wxChar ch = READ_STRING_CHAR(s, idx, length);
// Skip WS
while (ch==wxT(' ') || ch==wxT('\t'))
ch = READ_STRING_CHAR(s, idx, length);
// Ask for sign
int iSign = 1;
if (ch==wxT('-') || ch==wxT('+')) {
iSign = ((ch==wxT('-')) ? -1 : 1);
ch = READ_STRING_CHAR(s, idx, length);
}
// Read number
wxLongLong multiplier(0l, 10l);
while (ch>=wxT('0') && ch<=wxT('9')) {
long lValue = (unsigned) (ch - wxT('0'));
ll = ll * multiplier + wxLongLong(0l, lValue);
ch = READ_STRING_CHAR(s, idx, length);
}
#if wxUSE_LONGLONG_NATIVE
ll = ll * wxLongLong((wxLongLong_t) iSign);
#else
ll = ll * wxLongLong((long) iSign);
#endif
return o;
}
#if wxUSE_LONGLONG_NATIVE
WXDLLIMPEXP_BASE class wxTextOutputStream &operator<<(class wxTextOutputStream &o, wxULongLong_t value)
{
return o << wxULongLong(value).ToString();
}
WXDLLIMPEXP_BASE class wxTextOutputStream &operator<<(class wxTextOutputStream &o, wxLongLong_t value)
{
return o << wxLongLong(value).ToString();
}
WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &o, wxULongLong_t &value)
{
wxULongLong ll;
o >> ll;
value = ll.GetValue();
return o;
}
WXDLLIMPEXP_BASE class wxTextInputStream &operator>>(class wxTextInputStream &o, wxLongLong_t &value)
{
wxLongLong ll;
o >> ll;
value = ll.GetValue();
return o;
}
#endif // wxUSE_LONGLONG_NATIVE
#endif // wxUSE_STREAMS
#endif // wxUSE_LONGLONG