X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bbe0af5b15f8b8e95ed45abc2140fb3a1fac3c87..1e3698e55d7ee45267b69fa8ed5f94886ad47be9:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index b7f8f3931d..cc38a5022b 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -15,15 +15,22 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/defs.h" +#endif + +#if wxUSE_STREAMS + #include #include #include #include -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - #define BUF_TEMP_SIZE 10000 // ---------------------------------------------------------------------------- @@ -82,6 +89,9 @@ size_t wxStreamBuffer::WriteBack(const char *buf, size_t bufsize) { char *ptrback; + if (m_mode != read) + return 0; + ptrback = AllocSpaceWBack(bufsize); if (!ptrback) return 0; @@ -137,6 +147,7 @@ void wxStreamBuffer::SetBufferIO(size_t bufsize) void wxStreamBuffer::ResetBuffer() { m_stream->m_lasterror = wxStream_NOERROR; + m_stream->m_lastcount = 0; if (m_mode == read) m_buffer_pos = m_buffer_end; else @@ -158,8 +169,6 @@ char *wxStreamBuffer::AllocSpaceWBack(size_t needed_size) return NULL; m_wback = temp_b; - /* printf("Buffer(0x%x)->Write: 0x%x, %d\n", this, m_wback, m_wbacksize); */ - return (char *)(m_wback+(m_wbacksize-needed_size)); } @@ -167,8 +176,6 @@ size_t wxStreamBuffer::GetWBack(char *buf, size_t bsize) { size_t s_toget = m_wbacksize-m_wbackcur; - /* printf("Buffer(0x%x): 0x%x, %d\n", this, m_wback, m_wbacksize); */ - if (bsize < s_toget) s_toget = bsize; @@ -251,8 +258,8 @@ void wxStreamBuffer::PutChar(char c) return; } - if (!GetDataLeft() && !FlushBuffer()) { - CHECK_ERROR(wxStream_READ_ERR); + if (GetDataLeft() == 0 && !FlushBuffer()) { + CHECK_ERROR(wxStream_WRITE_ERR); return; } @@ -285,6 +292,9 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size) { wxASSERT(m_stream != NULL); + if (m_mode == write) + return 0; + // ------------------ // Buffering disabled // ------------------ @@ -334,7 +344,10 @@ size_t wxStreamBuffer::Read(wxStreamBuffer *s_buf) char buf[BUF_TEMP_SIZE]; size_t s = 0, bytes_read = BUF_TEMP_SIZE; - while (bytes_read == BUF_TEMP_SIZE) { + if (m_mode == write) + return 0; + + while (bytes_read != 0) { bytes_read = Read(buf, bytes_read); bytes_read = s_buf->Write(buf, bytes_read); s += bytes_read; @@ -346,6 +359,9 @@ size_t wxStreamBuffer::Write(const void *buffer, size_t size) { wxASSERT(m_stream != NULL); + if (m_mode == read) + return 0; + // ------------------ // Buffering disabled // ------------------ @@ -392,6 +408,9 @@ size_t wxStreamBuffer::Write(wxStreamBuffer *sbuf) char buf[BUF_TEMP_SIZE]; size_t s = 0, bytes_count = BUF_TEMP_SIZE, b_count2; + if (m_mode == read) + return 0; + while (bytes_count == BUF_TEMP_SIZE) { b_count2 = sbuf->Read(buf, bytes_count); bytes_count = Write(buf, b_count2); @@ -740,7 +759,12 @@ wxOutputStream& wxOutputStream::operator<<(const char *string) wxOutputStream& wxOutputStream::operator<<(wxString& string) { +#if wxUSE_UNICODE + const wxWX2MBbuf buf = string.mb_str(); + return *this << buf; +#else return Write(string, string.Len()); +#endif } wxOutputStream& wxOutputStream::operator<<(char c) @@ -752,32 +776,32 @@ wxOutputStream& wxOutputStream::operator<<(short i) { wxString strint; - strint.Printf("%i", i); - return Write(strint, strint.Len()); + strint.Printf(_T("%i"), i); + return *this << strint; } wxOutputStream& wxOutputStream::operator<<(int i) { wxString strint; - strint.Printf("%i", i); - return Write(strint, strint.Len()); + strint.Printf(_T("%i"), i); + return *this << strint; } wxOutputStream& wxOutputStream::operator<<(long i) { wxString strlong; - strlong.Printf("%i", i); - return Write((const char *)strlong, strlong.Len()); + strlong.Printf(_T("%i"), i); + return *this << strlong; } wxOutputStream& wxOutputStream::operator<<(double f) { wxString strfloat; - strfloat.Printf("%f", f); - return Write(strfloat, strfloat.Len()); + strfloat.Printf(_T("%f"), f); + return *this << strfloat; } #if wxUSE_SERIAL @@ -838,3 +862,6 @@ wxOutputStream& wxEndL(wxOutputStream& stream) return stream.Write("\n", 1); #endif } + +#endif + // wxUSE_STREAMS