2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: mstream.h
|
2009-01-10 12:23:06 -05:00
|
|
|
// Purpose: interface of wxMemoryOutputStream, wxMemoryInputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxMemoryOutputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-10 12:23:06 -05:00
|
|
|
This class allows to use all methods taking a wxOutputStream reference to write
|
|
|
|
to in-memory data.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
@code
|
|
|
|
wxMemoryOutputStream stream;
|
|
|
|
if (!my_wxImage.SaveFile(stream))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// now we can access the saved image bytes:
|
|
|
|
wxStreamBuffer* theBuffer = stream.GetOutputStreamBuffer();
|
|
|
|
unsigned char byte;
|
|
|
|
if (theBuffer->Read(byte, 1) != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// ... do something with 'byte'...
|
|
|
|
|
|
|
|
// remember that ~wxMemoryOutputStream will destroy the internal
|
|
|
|
// buffer since we didn't provide our own when constructing it
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxStreamBuffer
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxMemoryOutputStream : public wxOutputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
If @a data is @NULL, then it will initialize a new empty buffer which will
|
2008-03-08 08:52:38 -05:00
|
|
|
grow if required.
|
2008-10-11 09:10:48 -04:00
|
|
|
|
|
|
|
@warning
|
2009-01-10 12:23:06 -05:00
|
|
|
If the buffer is created by wxMemoryOutputStream, it will be destroyed
|
|
|
|
at the destruction of the stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-13 09:46:42 -04:00
|
|
|
wxMemoryOutputStream(void* data = NULL, size_t length = 0);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
2009-01-10 12:23:06 -05:00
|
|
|
|
|
|
|
If the buffer wasn't provided by the user, it will be deleted here.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxMemoryOutputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-11 09:10:48 -04:00
|
|
|
Allows you to transfer data from the internal buffer of wxMemoryOutputStream
|
|
|
|
to an external buffer. @a len specifies the size of the buffer.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-29 11:34:31 -04:00
|
|
|
size_t CopyTo(void* buffer, size_t len) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the pointer to the stream object used as an internal buffer
|
2009-01-10 12:23:06 -05:00
|
|
|
for this stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxStreamBuffer* GetOutputStreamBuffer() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxMemoryInputStream
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2009-01-10 12:23:06 -05:00
|
|
|
This class allows to use all methods taking a wxInputStream reference to read
|
|
|
|
in-memory data.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
@code
|
|
|
|
// we've got a block of memory containing a BMP image and we want
|
|
|
|
// to use wxImage to load it:
|
|
|
|
wxMemoryInputStream stream(my_memory_block, size);
|
|
|
|
|
|
|
|
wxImage theBitmap;
|
|
|
|
if (!theBitmap.LoadFile(stream, wxBITMAP_TYPE_BMP))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we can now safely delete the original memory buffer as the data
|
|
|
|
// has been decoded by wxImage:
|
|
|
|
delete [] my_memory_block;
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{streams}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxStreamBuffer, wxMemoryOutputStream
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxMemoryInputStream : public wxInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-10-11 09:10:48 -04:00
|
|
|
Initializes a new read-only memory stream which will use the specified
|
|
|
|
buffer data of length len. The stream does not take ownership of the buffer,
|
|
|
|
i.e. the buffer will not be deleted in its destructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-10 16:33:25 -05:00
|
|
|
wxMemoryInputStream(const void* data, size_t len);
|
2008-10-11 09:10:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a new read-only memory stream, initializing it with the data from
|
|
|
|
the given output stream @a stream.
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxMemoryInputStream(const wxMemoryOutputStream& stream);
|
2008-10-11 09:10:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Creates a new read-only memory stream, initializing it with the
|
|
|
|
data from the given input stream @a stream.
|
|
|
|
|
|
|
|
The @a len argument specifies the amount of data to read from the
|
2009-01-13 12:29:34 -05:00
|
|
|
@a stream. Setting it to ::wxInvalidOffset means that the @a stream
|
2008-10-11 09:10:48 -04:00
|
|
|
is to be read entirely (i.e. till the EOF is reached).
|
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxMemoryInputStream(wxInputStream& stream,
|
|
|
|
wxFileOffset len = wxInvalidOffset);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2009-01-10 12:23:06 -05:00
|
|
|
Destructor. Does NOT free the buffer provided in the ctor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxMemoryInputStream();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the pointer to the stream object used as an internal buffer
|
|
|
|
for that stream.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxStreamBuffer* GetInputStreamBuffer() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|