X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f1f5976f1f3d75a8a86595d9bf8dbaa0940abf50..f7a11f8c8e665992e2d1956b2b89d2f562c92669:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 76a0b3fdbf..162dcf19cb 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -195,6 +195,23 @@ void wxStreamBuffer::PutChar(char c) m_stream->m_lastcount = 1; } +char wxStreamBuffer::Peek() +{ + char c; + + wxASSERT(m_stream != NULL && m_buffer_size != 0); + + if (!GetDataLeft()) { + CHECK_ERROR(wxStream_READ_ERR); + return 0; + } + + GetFromBuffer(&c, 1); + m_buffer_pos--; + + return c; +} + char wxStreamBuffer::GetChar() { char c; @@ -248,7 +265,7 @@ size_t wxStreamBuffer::Read(void *buffer, size_t size) buffer = (char *)buffer + buf_left; // ANSI C++ violation. if (!FillBuffer()) { - CHECK_ERROR(wxStream_READ_ERR); + CHECK_ERROR(wxStream_EOF); return (m_stream->m_lastcount = orig_size-size); } } else { @@ -576,6 +593,10 @@ wxInputStream& wxInputStream::Read(wxOutputStream& stream_out) off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode) { + //should be check and improve, just to remove a slight bug ! + // I don't know whether it should be put as well in wxFileInputStream::OnSysSeek ? + if (m_lasterror==wxSTREAM_EOF) m_lasterror=wxSTREAM_NOERROR; + return OnSysSeek(pos, mode); } @@ -645,9 +666,56 @@ wxOutputStream& wxOutputStream::operator<<(wxObject& obj) } #endif +// ---------------------------------------------------------------------------- +// wxCountingOutputStream +// ---------------------------------------------------------------------------- + +wxCountingOutputStream::wxCountingOutputStream () + : wxOutputStream() +{ + m_currentPos = 0; +} + +size_t wxCountingOutputStream::GetSize() const +{ + return m_lastcount; +} + +size_t wxCountingOutputStream::OnSysWrite(const void *WXUNUSED(buffer), size_t size) +{ + m_currentPos += size; + if (m_currentPos > m_lastcount) m_lastcount = m_currentPos; + return m_currentPos; +} + +off_t wxCountingOutputStream::OnSysSeek(off_t pos, wxSeekMode mode) +{ + if (mode == wxFromStart) + { + m_currentPos = pos; + } + if (mode == wxFromEnd) + { + m_currentPos = m_lastcount + pos; + } + else + { + m_currentPos += pos; + } + if (m_currentPos > m_lastcount) m_lastcount = m_currentPos; + + return m_currentPos; // ? +} + +off_t wxCountingOutputStream::OnSysTell() const +{ + return m_currentPos; // ? +} + // ---------------------------------------------------------------------------- // wxFilterInputStream // ---------------------------------------------------------------------------- + wxFilterInputStream::wxFilterInputStream() : wxInputStream() { @@ -696,6 +764,11 @@ wxBufferedInputStream::~wxBufferedInputStream() delete m_i_streambuf; } +char wxBufferedInputStream::Peek() +{ + return m_i_streambuf->Peek(); +} + wxInputStream& wxBufferedInputStream::Read(void *buffer, size_t size) { size_t retsize;