-class WXDLLEXPORT wxStreamBuffer {
- public:
- typedef enum {
- read = 0, write, read_write
- } BufMode;
-
- // -----------
- // ctor & dtor
- // -----------
- wxStreamBuffer(wxStreamBase& stream, BufMode mode);
- wxStreamBuffer(BufMode mode);
- wxStreamBuffer(const wxStreamBuffer& buf);
- ~wxStreamBuffer();
-
- // -----------
- // Filtered IO
- // -----------
- size_t Read(void *buffer, size_t size);
- size_t Read(wxStreamBuffer *buf);
- size_t Write(const void *buffer, size_t size);
- size_t Write(wxStreamBuffer *buf);
-
- char Peek();
- char GetChar();
- void PutChar(char c);
- off_t Tell() const;
- off_t Seek(off_t pos, wxSeekMode mode);
-
- // --------------
- // Buffer control
- // --------------
- void ResetBuffer();
- void SetBufferIO(char *buffer_start, char *buffer_end);
- void SetBufferIO(size_t bufsize);
- char *GetBufferStart() const { return m_buffer_start; }
- char *GetBufferEnd() const { return m_buffer_end; }
- char *GetBufferPos() const { return m_buffer_pos; }
- off_t GetIntPosition() const { return m_buffer_pos-m_buffer_start; }
- void SetIntPosition(off_t pos) { m_buffer_pos = m_buffer_start+pos; }
- size_t GetLastAccess() const { return m_buffer_end-m_buffer_start; }
-
- void Fixed(bool fixed) { m_fixed = fixed; }
- void Flushable(bool f) { m_flushable = f; }
-
- bool FlushBuffer();
- bool FillBuffer();
- size_t GetDataLeft();
-
- // --------------
- // Administration
- // --------------
- wxStreamBase *Stream() { return m_stream; }
-
- protected:
- void GetFromBuffer(void *buffer, size_t size);
- void PutToBuffer(const void *buffer, size_t size);
-
- protected:
- char *m_buffer_start, *m_buffer_end, *m_buffer_pos;
- size_t m_buffer_size;
-
- char *m_wback;
- size_t m_wbacksize, m_wbackcur;
-
- bool m_fixed, m_flushable;
-
- wxStreamBase *m_stream;
- BufMode m_mode;
- bool m_destroybuf, m_destroystream;
+class WXDLLIMPEXP_BASE wxStreamBuffer
+{
+public:
+ enum BufMode
+ {
+ read,
+ write,
+ read_write
+ };
+
+ wxStreamBuffer(wxStreamBase& stream, BufMode mode)
+ {
+ InitWithStream(stream, mode);
+ }
+
+ wxStreamBuffer(size_t bufsize, wxInputStream& stream)
+ {
+ InitWithStream(stream, read);
+ SetBufferIO(bufsize);
+ }
+
+ wxStreamBuffer(size_t bufsize, wxOutputStream& stream)
+ {
+ InitWithStream(stream, write);
+ SetBufferIO(bufsize);
+ }
+
+ 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 wxFileOffset Tell() const;
+ virtual wxFileOffset Seek(wxFileOffset pos, wxSeekMode mode);
+
+ // Buffer control
+ void ResetBuffer();
+ void Truncate();
+
+ // 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_end - m_buffer_start; }
+ 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_start != m_buffer_end; }
+
+ 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;
+
+#if WXWIN_COMPATIBILITY_2_6
+ // deprecated, for compatibility only
+ wxDEPRECATED( wxStreamBase *Stream() );
+#endif // WXWIN_COMPATIBILITY_2_6
+
+ // this constructs a dummy wxStreamBuffer, used by (and exists for)
+ // wxMemoryStreams only, don't use!
+ wxStreamBuffer(BufMode mode);
+
+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();
+
+ // common part of ctors taking wxStreamBase parameter
+ void InitWithStream(wxStreamBase& stream, BufMode mode);
+
+ // 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 stream we're associated with
+ wxStreamBase *m_stream;
+
+ // its mode
+ BufMode m_mode;
+
+ // flags
+ bool m_destroybuf, // deallocate buffer?
+ m_fixed,
+ m_flushable;
+
+
+ wxDECLARE_NO_ASSIGN_CLASS(wxStreamBuffer);