X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c81b7d7d536f55d8d0b6d53c6e581f6c047e2d2a..77c8efc8c37da6d6a5e2e8022d21d1cd7d76371d:/src/common/stream.cpp diff --git a/src/common/stream.cpp b/src/common/stream.cpp index 1a03caa346..f7cd2ea2c5 100644 --- a/src/common/stream.cpp +++ b/src/common/stream.cpp @@ -36,6 +36,7 @@ #include #include "wx/datstrm.h" #include "wx/textfile.h" +#include "wx/scopeguard.h" // ---------------------------------------------------------------------------- // constants @@ -954,7 +955,7 @@ wxFileOffset wxInputStream::SeekI(wxFileOffset pos, wxSeekMode mode) wxASSERT(bytes_read == (size_t)pos); - // we should now have seeked to the right position... + // we should now have sought to the right position... return TellI(); } @@ -1446,6 +1447,93 @@ void wxBufferedOutputStream::SetOutputStreamBuffer(wxStreamBuffer *buffer) m_o_streambuf = buffer; } +// --------------------------------------------------------------------------- +// wxWrapperInputStream implementation +// --------------------------------------------------------------------------- + +wxWrapperInputStream::wxWrapperInputStream() +{ + m_lasterror = wxSTREAM_READ_ERROR; +} + +wxWrapperInputStream::wxWrapperInputStream(wxInputStream& stream) + : wxFilterInputStream(stream) +{ + SynchronizeLastError(); +} + +wxWrapperInputStream::wxWrapperInputStream(wxInputStream *stream) + : wxFilterInputStream(stream) +{ + if ( m_parent_i_stream ) + SynchronizeLastError(); + else + m_lasterror = wxSTREAM_READ_ERROR; +} + +void wxWrapperInputStream::InitParentStream(wxInputStream& stream) +{ + wxCHECK_RET( !m_parent_i_stream, "Can't init parent stream twice" ); + + m_parent_i_stream = &stream; + + SynchronizeLastError(); +} + +void wxWrapperInputStream::InitParentStream(wxInputStream* stream) +{ + wxCHECK_RET( !m_parent_i_stream, "Can't init parent stream twice" ); + + m_parent_i_stream = stream; + + if ( m_parent_i_stream ) + { + m_owns = true; + + SynchronizeLastError(); + } +} + +wxFileOffset wxWrapperInputStream::GetLength() const +{ + wxCHECK_MSG(m_parent_i_stream, wxInvalidOffset, "Stream not valid"); + + wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError); + return m_parent_i_stream->GetLength(); +} + +bool wxWrapperInputStream::IsSeekable() const +{ + wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid"); + return m_parent_i_stream->IsSeekable(); +} + +size_t wxWrapperInputStream::OnSysRead(void *buffer, size_t size) +{ + wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid"); + + wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError); + + m_parent_i_stream->Read(buffer, size); + return m_parent_i_stream->LastRead(); +} + +wxFileOffset wxWrapperInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode) +{ + wxCHECK_MSG(IsSeekable(), false, "Stream not seekable"); + + wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError); + return m_parent_i_stream->SeekI (pos, mode); +} + +wxFileOffset wxWrapperInputStream::OnSysTell() const +{ + wxCHECK_MSG(m_parent_i_stream, false, "Stream not valid"); + + wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError); + return m_parent_i_stream->TellI(); +} + // ---------------------------------------------------------------------------- // Some IOManip function // ----------------------------------------------------------------------------