git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56583
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
- wxStreamBuffer(wxStreamBase& stream, BufMode mode);
+ wxStreamBuffer(wxStreamBase& stream, BufMode mode)
+ {
+ InitWithStream(stream, mode);
+ }
+
+ wxStreamBuffer(wxInputStream& stream, size_t bufsize)
+ {
+ InitWithStream(stream, read);
+ SetBufferIO(bufsize);
+ }
+
+ wxStreamBuffer(wxOutputStream& stream, size_t bufsize)
+ {
+ InitWithStream(stream, write);
+ SetBufferIO(bufsize);
+ }
+
wxStreamBuffer(const wxStreamBuffer& buf);
virtual ~wxStreamBuffer();
wxStreamBuffer(const wxStreamBuffer& buf);
virtual ~wxStreamBuffer();
// common part of several ctors
void Init();
// 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();
// init buffer variables to be empty
void InitBuffer();
-private:
-// Cannot use
-// DECLARE_NO_COPY_CLASS(wxStreamBuffer)
-// because copy constructor is explicitly declared above;
-// but no copy assignment operator is defined, so declare
-// it private to prevent the compiler from defining it:
- wxStreamBuffer& operator=(const wxStreamBuffer&);
+
+ DECLARE_NO_ASSIGN_CLASS(wxStreamBuffer)
};
// ---------------------------------------------------------------------------
};
// ---------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxBufferedInputStream : public wxFilterInputStream
{
public:
class WXDLLIMPEXP_BASE wxBufferedInputStream : public wxFilterInputStream
{
public:
- // if a non NULL buffer is given to the stream, it will be deleted by it
+ // create a buffered stream on top of the specified low-level stream
+ //
+ // if a non NULL buffer is given to the stream, it will be deleted by it,
+ // otherwise a default 1KB buffer will be used
wxBufferedInputStream(wxInputStream& stream,
wxStreamBuffer *buffer = NULL);
wxBufferedInputStream(wxInputStream& stream,
wxStreamBuffer *buffer = NULL);
+
+ // ctor allowing to specify the buffer size, it's just a more convenient
+ // alternative to creating wxStreamBuffer, calling its SetBufferIO(bufsize)
+ // and using the ctor above
+ wxBufferedInputStream(wxInputStream& stream, size_t bufsize);
+
+
virtual ~wxBufferedInputStream();
char Peek();
virtual ~wxBufferedInputStream();
char Peek();
class WXDLLIMPEXP_BASE wxBufferedOutputStream : public wxFilterOutputStream
{
public:
class WXDLLIMPEXP_BASE wxBufferedOutputStream : public wxFilterOutputStream
{
public:
- // if a non NULL buffer is given to the stream, it will be deleted by it
+ // create a buffered stream on top of the specified low-level stream
+ //
+ // if a non NULL buffer is given to the stream, it will be deleted by it,
+ // otherwise a default 1KB buffer will be used
wxBufferedOutputStream(wxOutputStream& stream,
wxStreamBuffer *buffer = NULL);
wxBufferedOutputStream(wxOutputStream& stream,
wxStreamBuffer *buffer = NULL);
+
+ // ctor allowing to specify the buffer size, it's just a more convenient
+ // alternative to creating wxStreamBuffer, calling its SetBufferIO(bufsize)
+ // and using the ctor above
+ wxBufferedOutputStream(wxOutputStream& stream, size_t bufsize);
+
virtual ~wxBufferedOutputStream();
wxOutputStream& Write(const void *buffer, size_t size);
virtual ~wxBufferedOutputStream();
wxOutputStream& Write(const void *buffer, size_t size);
- Constructor.
- If a non @NULL buffer is given to the stream, it will be deleted by it.
+ Constructor using the provided buffer or default.
+
+ @param stream
+ The associated low-level stream.
+ @param buffer
+ The buffer to use if non-@NULL. Notice that the ownership of this
+ buffer is taken by the stream, i.e. it will delete it. If this
+ parameter is @NULL a default 1KB buffer is used.
*/
wxBufferedInputStream(wxInputStream& stream,
wxStreamBuffer *buffer = NULL);
*/
wxBufferedInputStream(wxInputStream& stream,
wxStreamBuffer *buffer = NULL);
+ /**
+ Constructor allowing to specify the size of the buffer.
+
+ This is just a more convenient alternative to creating a wxStreamBuffer
+ of the given size and using the other overloaded constructor of this
+ class.
+
+ @param stream
+ The associated low-level stream.
+ @param bufsize
+ The size of the buffer, in bytes.
+
+ @since 2.9.0
+ */
+ wxBufferedInputStream(wxInputStream& stream, size_t bufsize);
+
*/
wxStreamBuffer(wxStreamBase& stream, BufMode mode);
*/
wxStreamBuffer(wxStreamBase& stream, BufMode mode);
+ /**
+ Constructor for an input buffer of the specified size.
+
+ Using it is equivalent to using the constructor above with read mode
+ and calling SetBufferIO() but is more convenient.
+
+ @since 2.9.0
+ */
+ wxStreamBuffer(wxInputStream& stream, size_t bufsize);
+
+ /**
+ Constructor for an output buffer of the specified size.
+
+ Using it is equivalent to using the constructor above with write mode
+ and calling SetBufferIO() but is more convenient.
+
+ @since 2.9.0
+ */
+ wxStreamBuffer(wxOutputStream& stream, size_t bufsize);
+
/**
Constructor; creates a new empty stream buffer which won't flush any data
to a stream. mode specifies the type of the buffer (read, write, read_write).
/**
Constructor; creates a new empty stream buffer which won't flush any data
to a stream. mode specifies the type of the buffer (read, write, read_write).
wxStreamBuffer(BufMode mode);
/**
wxStreamBuffer(BufMode mode);
/**
This method initializes the stream buffer with the data of the specified
stream buffer. The new stream buffer has the same attributes, size, position
This method initializes the stream buffer with the data of the specified
stream buffer. The new stream buffer has the same attributes, size, position
- @todo WRITE DESCRIPTION
+ Constructor using the provided buffer or default.
+
+ @param stream
+ The associated low-level stream.
+ @param buffer
+ The buffer to use if non-@NULL. Notice that the ownership of this
+ buffer is taken by the stream, i.e. it will delete it. If this
+ parameter is @NULL a default 1KB buffer is used.
*/
wxBufferedOutputStream(wxOutputStream& stream,
wxStreamBuffer *buffer = NULL);
*/
wxBufferedOutputStream(wxOutputStream& stream,
wxStreamBuffer *buffer = NULL);
+
+ /**
+ Constructor allowing to specify the size of the buffer.
+
+ This is just a more convenient alternative to creating a wxStreamBuffer
+ of the given size and using the other overloaded constructor of this
+ class.
+
+ @param stream
+ The associated low-level stream.
+ @param bufsize
+ The size of the buffer, in bytes.
+
+ @since 2.9.0
+ */
+ wxBufferedOutputStream(wxOutputStream& stream, size_t bufsize);
+
/**
Destructor. Calls Sync() and destroys the internal buffer.
*/
/**
Destructor. Calls Sync() and destroys the internal buffer.
*/
-wxStreamBuffer::wxStreamBuffer(BufMode mode)
+void wxStreamBuffer::InitWithStream(wxStreamBase& stream, BufMode mode)
-wxStreamBuffer::wxStreamBuffer(wxStreamBase& stream, BufMode mode)
+wxStreamBuffer::wxStreamBuffer(BufMode mode)
}
wxStreamBuffer::wxStreamBuffer(const wxStreamBuffer& buffer)
}
wxStreamBuffer::wxStreamBuffer(const wxStreamBuffer& buffer)
// wxBufferedInputStream
// ----------------------------------------------------------------------------
// wxBufferedInputStream
// ----------------------------------------------------------------------------
-wxBufferedInputStream::wxBufferedInputStream(wxInputStream& s,
+namespace
+{
+
+// helper function used for initializing the buffer used by
+// wxBufferedInput/OutputStream: it simply returns the provided buffer if it's
+// not NULL or creates a buffer of the given size otherwise
+template <typename T>
+wxStreamBuffer *
+CreateBufferIfNeeded(T& stream, wxStreamBuffer *buffer, size_t bufsize = 1024)
+{
+ return buffer ? buffer : new wxStreamBuffer(stream, bufsize);
+}
+
+} // anonymous namespace
+
+wxBufferedInputStream::wxBufferedInputStream(wxInputStream& stream,
- : wxFilterInputStream(s)
+ : wxFilterInputStream(stream)
- if ( buffer )
- {
- // use the buffer provided by the user
- m_i_streambuf = buffer;
- }
- else // create a default buffer
- {
- m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
+ m_i_streambuf = CreateBufferIfNeeded(*this, buffer);
+}
- m_i_streambuf->SetBufferIO(1024);
- }
+wxBufferedInputStream::wxBufferedInputStream(wxInputStream& stream,
+ size_t bufsize)
+ : wxFilterInputStream(stream)
+{
+ m_i_streambuf = CreateBufferIfNeeded(*this, NULL, bufsize);
}
wxBufferedInputStream::~wxBufferedInputStream()
}
wxBufferedInputStream::~wxBufferedInputStream()
// wxBufferedOutputStream
// ----------------------------------------------------------------------------
// wxBufferedOutputStream
// ----------------------------------------------------------------------------
-wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& s,
+wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& stream,
- : wxFilterOutputStream(s)
+ : wxFilterOutputStream(stream)
- if ( buffer )
- {
- m_o_streambuf = buffer;
- }
- else // create a default one
- {
- m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
+ m_o_streambuf = CreateBufferIfNeeded(*this, buffer);
+}
- m_o_streambuf->SetBufferIO(1024);
- }
+wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& stream,
+ size_t bufsize)
+ : wxFilterOutputStream(stream)
+{
+ m_o_streambuf = CreateBufferIfNeeded(*this, NULL, bufsize);
}
wxBufferedOutputStream::~wxBufferedOutputStream()
}
wxBufferedOutputStream::~wxBufferedOutputStream()