X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40319aa0ce7d201ae25554bb7a6ea3257e41a904..b53aea81d2e102224b452ef5bf7aee1132f37c6f:/src/common/datstrm.cpp diff --git a/src/common/datstrm.cpp b/src/common/datstrm.cpp index a1961c3f02..8a97eca767 100644 --- a/src/common/datstrm.cpp +++ b/src/common/datstrm.cpp @@ -19,15 +19,18 @@ #if wxUSE_STREAMS #include "wx/datstrm.h" -#include "wx/math.h" + +#ifndef WX_PRECOMP + #include "wx/math.h" +#endif //WX_PRECOMP // --------------------------------------------------------------------------- // wxDataInputStream // --------------------------------------------------------------------------- #if wxUSE_UNICODE -wxDataInputStream::wxDataInputStream(wxInputStream& s, wxMBConv& conv) - : m_input(&s), m_be_order(false), m_conv(conv) +wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv) + : m_input(&s), m_be_order(false), m_conv(conv.Clone()) #else wxDataInputStream::wxDataInputStream(wxInputStream& s) : m_input(&s), m_be_order(false) @@ -35,6 +38,21 @@ wxDataInputStream::wxDataInputStream(wxInputStream& s) { } +wxDataInputStream::~wxDataInputStream() +{ +#if wxUSE_UNICODE + delete m_conv; +#endif // wxUSE_UNICODE +} + +#if wxUSE_UNICODE +void wxDataInputStream::SetConv( const wxMBConv &conv ) +{ + delete m_conv; + m_conv = conv.Clone(); +} +#endif + #if wxHAS_INT64 wxUint64 wxDataInputStream::Read64() { @@ -82,7 +100,7 @@ double wxDataInputStream::ReadDouble() char buf[10]; m_input->Read(buf, 10); - return ConvertFromIeeeExtended((const wxInt8 *)buf); + return wxConvertFromIeeeExtended((const wxInt8 *)buf); #else return 0.0; #endif @@ -90,25 +108,27 @@ double wxDataInputStream::ReadDouble() wxString wxDataInputStream::ReadString() { - size_t len; - - len = Read32(); + wxString ret; - if (len > 0) - { + const size_t len = Read32(); + if ( len > 0 ) + { #if wxUSE_UNICODE - wxCharBuffer tmp(len + 1); - m_input->Read(tmp.data(), len); - tmp.data()[len] = '\0'; - wxString ret(m_conv.cMB2WX(tmp.data())); + wxCharBuffer tmp(len + 1); + if ( tmp ) + { + m_input->Read(tmp.data(), len); + tmp.data()[len] = '\0'; + ret = m_conv->cMB2WX(tmp.data()); + } #else - wxString ret; - m_input->Read( wxStringBuffer(ret, len), len); + wxStringBuffer buf(ret, len); + if ( buf ) + m_input->Read(buf, len); #endif + } + return ret; - } - else - return wxEmptyString; } #if wxUSE_LONGLONG @@ -445,8 +465,8 @@ wxDataInputStream& wxDataInputStream::operator>>(float& f) // --------------------------------------------------------------------------- #if wxUSE_UNICODE -wxDataOutputStream::wxDataOutputStream(wxOutputStream& s, wxMBConv& conv) - : m_output(&s), m_be_order(false), m_conv(conv) +wxDataOutputStream::wxDataOutputStream(wxOutputStream& s, const wxMBConv& conv) + : m_output(&s), m_be_order(false), m_conv(conv.Clone()) #else wxDataOutputStream::wxDataOutputStream(wxOutputStream& s) : m_output(&s), m_be_order(false) @@ -454,6 +474,21 @@ wxDataOutputStream::wxDataOutputStream(wxOutputStream& s) { } +wxDataOutputStream::~wxDataOutputStream() +{ +#if wxUSE_UNICODE + delete m_conv; +#endif // wxUSE_UNICODE +} + +#if wxUSE_UNICODE +void wxDataOutputStream::SetConv( const wxMBConv &conv ) +{ + delete m_conv; + m_conv = conv.Clone(); +} +#endif + #if wxHAS_INT64 void wxDataOutputStream::Write64(wxUint64 i) { @@ -497,7 +532,7 @@ void wxDataOutputStream::Write8(wxUint8 i) void wxDataOutputStream::WriteString(const wxString& string) { #if wxUSE_UNICODE - const wxWX2MBbuf buf = string.mb_str(m_conv); + const wxWX2MBbuf buf = string.mb_str(*m_conv); #else const wxWX2MBbuf buf = string.mb_str(); #endif @@ -512,7 +547,7 @@ void wxDataOutputStream::WriteDouble(double d) char buf[10]; #if wxUSE_APPLE_IEEE - ConvertToIeeeExtended(d, (wxInt8 *)buf); + wxConvertToIeeeExtended(d, (wxInt8 *)buf); #else #if !defined(__VMS__) && !defined(__GNUG__) # pragma warning "wxDataOutputStream::WriteDouble() not using IeeeExtended - will not work!" @@ -633,13 +668,6 @@ void wxDataOutputStream::WriteDouble(const double *buffer, size_t size) } } -wxDataOutputStream& wxDataOutputStream::operator<<(const wxChar *string) -{ - Write32(wxStrlen(string)); - m_output->Write((const char *)string, wxStrlen(string)*sizeof(wxChar)); - return *this; -} - wxDataOutputStream& wxDataOutputStream::operator<<(const wxString& string) { WriteString(string);