X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fae05df5a988883e9c6683ccded766dfb7b84b1b..5b4f8dd5c0fe1bf44fb7971c669b036d4ad6eebe:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 9b83250f1c..fdfc912333 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -371,7 +371,9 @@ off_t wxStreamBuffer::Seek(off_t pos, wxSeekMode mode) diff = pos + GetIntPosition(); if ( (diff > last_access) || (diff < 0) ) { - ret_off = m_stream->OnSysSeek(pos, wxFromCurrent); + // We must take into account the fact that we have read something + // previously. + ret_off = m_stream->OnSysSeek(diff-last_access, wxFromCurrent); ResetBuffer(); return ret_off; } else { @@ -480,6 +482,9 @@ size_t wxInputStream::GetWBack(char *buf, size_t bsize) { size_t s_toget = m_wbacksize-m_wbackcur; + if (!m_wback) + return 0; + if (bsize < s_toget) s_toget = bsize; @@ -496,7 +501,7 @@ size_t wxInputStream::GetWBack(char *buf, size_t bsize) return s_toget; } -size_t wxInputStream::Ungetch(void *buf, size_t bufsize) +size_t wxInputStream::Ungetch(const void *buf, size_t bufsize) { char *ptrback; @@ -571,12 +576,12 @@ wxInputStream& wxInputStream::Read(wxOutputStream& stream_out) off_t wxInputStream::SeekI(off_t pos, wxSeekMode mode) { - return wxInvalidOffset; + return OnSysSeek(pos, mode); } off_t wxInputStream::TellI() const { - return wxInvalidOffset; + return OnSysTell(); } // -------------------- @@ -619,12 +624,12 @@ wxOutputStream& wxOutputStream::Write(wxInputStream& stream_in) off_t wxOutputStream::TellO() const { - return wxInvalidOffset; + return OnSysTell(); } off_t wxOutputStream::SeekO(off_t pos, wxSeekMode mode) { - return wxInvalidOffset; + return OnSysSeek(pos, mode); } void wxOutputStream::Sync() @@ -640,9 +645,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 *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() { @@ -697,8 +749,8 @@ wxInputStream& wxBufferedInputStream::Read(void *buffer, size_t size) char *buf = (char *)buffer; retsize = GetWBack(buf, size); + m_lastcount = retsize; if (retsize == size) { - m_lastcount = size; m_lasterror = wxStream_NOERROR; return *this; } @@ -753,6 +805,7 @@ wxBufferedOutputStream::~wxBufferedOutputStream() wxOutputStream& wxBufferedOutputStream::Write(const void *buffer, size_t size) { + m_lastcount = 0; m_o_streambuf->Write(buffer, size); return *this; }