+class WXDLLEXPORT wxFilterOutputStream : public wxOutputStream
+{
+public:
+ wxFilterOutputStream();
+ wxFilterOutputStream(wxOutputStream& stream);
+ virtual ~wxFilterOutputStream();
+
+ size_t GetSize() const { return m_parent_o_stream->GetSize(); }
+
+ wxOutputStream *GetFilterOutputStream() const { return m_parent_o_stream; }
+
+protected:
+ wxOutputStream *m_parent_o_stream;
+};
+
+// ---------------------------------------------------------------------------
+// Stream buffer: this class can be derived from and passed to
+// wxBufferedStreams to implement custom buffering
+// ---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxStreamBuffer
+{
+public:
+ enum BufMode
+ {
+ read,
+ write,
+ read_write
+ };
+
+ wxStreamBuffer(wxStreamBase& stream, BufMode mode);
+ wxStreamBuffer(BufMode mode);
+ wxStreamBuffer(const wxStreamBuffer& buf);
+ virtual ~wxStreamBuffer();
+
+ // Filtered IO
+ virtual size_t Read(void *buffer, size_t size);
+ size_t Read(wxStreamBuffer *buf);
+ virtual size_t Write(const void *buffer, size_t size);
+ size_t Write(wxStreamBuffer *buf);
+
+ virtual char Peek();
+ virtual char GetChar();
+ virtual void PutChar(char c);
+ virtual off_t Tell() const;
+ virtual off_t Seek(off_t pos, wxSeekMode mode);
+
+ // Buffer control
+ void ResetBuffer();
+
+ // NB: the buffer must always be allocated with malloc() if takeOwn is
+ // TRUE as it will be deallocated by free()
+ void SetBufferIO(void *start, void *end, bool takeOwnership = FALSE);
+ void SetBufferIO(void *start, size_t len, bool takeOwnership = FALSE);
+ void SetBufferIO(size_t bufsize);
+ void *GetBufferStart() const { return m_buffer_start; }
+ void *GetBufferEnd() const { return m_buffer_end; }
+ void *GetBufferPos() const { return m_buffer_pos; }
+ size_t GetBufferSize() const { return m_buffer_size; }
+ size_t GetIntPosition() const { return m_buffer_pos - m_buffer_start; }
+ void SetIntPosition(size_t pos) { m_buffer_pos = m_buffer_start + pos; }
+ size_t GetLastAccess() const { return m_buffer_end - m_buffer_start; }
+ size_t GetBytesLeft() const { return m_buffer_end - m_buffer_pos; }
+
+ void Fixed(bool fixed) { m_fixed = fixed; }
+ void Flushable(bool f) { m_flushable = f; }
+
+ bool FlushBuffer();
+ bool FillBuffer();
+ size_t GetDataLeft();
+
+ // misc accessors
+ wxStreamBase *GetStream() const { return m_stream; }
+ bool HasBuffer() const { return m_buffer_size != 0; }
+
+ bool IsFixed() const { return m_fixed; }
+ bool IsFlushable() const { return m_flushable; }
+
+ // only for input/output buffers respectively, returns NULL otherwise
+ wxInputStream *GetInputStream() const;
+ wxOutputStream *GetOutputStream() const;
+
+ // deprecated, for compatibility only
+ wxStreamBase *Stream() { return m_stream; }
+
+protected:
+ void GetFromBuffer(void *buffer, size_t size);
+ void PutToBuffer(const void *buffer, size_t size);
+
+ // set the last error to the specified value if we didn't have it before
+ void SetError(wxStreamError err);
+
+ // common part of several ctors
+ void Init();
+
+ // init buffer variables to be empty
+ void InitBuffer();
+
+ // free the buffer (always safe to call)
+ void FreeBuffer();
+
+ // the buffer itself: the pointers to its start and end and the current
+ // position in the buffer
+ char *m_buffer_start,
+ *m_buffer_end,
+ *m_buffer_pos;
+
+ // the buffer size
+ // FIXME: isn't it the same as m_buffer_end - m_buffer_start? (VZ)
+ size_t m_buffer_size;
+
+ // the stream we're associated with
+ wxStreamBase *m_stream;
+
+ // its mode
+ BufMode m_mode;
+
+ // flags
+ bool m_destroybuf, // deallocate buffer?
+ m_destroystream, // delete associated stream?
+ m_fixed,
+ m_flushable;
+};
+
+// ---------------------------------------------------------------------------
+// wxBufferedStreams
+// ---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxBufferedInputStream : public wxFilterInputStream
+{
+public:
+ // if a non NULL buffer is given to the stream, it will be deleted by it
+ wxBufferedInputStream(wxInputStream& stream,
+ wxStreamBuffer *buffer = NULL);
+ virtual ~wxBufferedInputStream();
+
+ char Peek();
+ wxInputStream& Read(void *buffer, size_t size);
+
+ // Position functions
+ off_t SeekI(off_t pos, wxSeekMode mode = wxFromStart);
+ off_t TellI() const;