2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: buffer.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxMemoryBuffer
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxMemoryBuffer
|
|
|
|
@wxheader{buffer.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A @b wxMemoryBuffer is a useful data structure for storing arbitrary sized
|
2008-03-16 20:47:38 -04:00
|
|
|
blocks of memory. wxMemoryBuffer guarantees deletion of the memory block when
|
|
|
|
the object is destroyed.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-03-16 20:47:38 -04:00
|
|
|
@category{data}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
class wxMemoryBuffer
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
2008-03-16 20:47:38 -04:00
|
|
|
/**
|
|
|
|
Copy constructor, refcounting is used for performance, but wxMemoryBuffer
|
|
|
|
is not a copy-on-write structure so changes made to one buffer effect all
|
|
|
|
copies made from it.
|
|
|
|
|
|
|
|
@see @ref overview_refcount
|
|
|
|
*/
|
|
|
|
wxMemoryBuffer(const wxMemoryBuffer& src);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Create a new buffer.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param size
|
2008-03-16 20:47:38 -04:00
|
|
|
size of the new buffer.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxMemoryBuffer(size_t size);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Append a single byte to the buffer.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param data
|
2008-03-09 08:33:59 -04:00
|
|
|
New byte to append to the buffer.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void AppendByte(char data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ensure that the buffer is big enough and return a pointer to the start
|
2008-03-08 09:43:31 -05:00
|
|
|
of the empty space in the buffer. This pointer can be used to directly
|
2008-03-16 20:47:38 -04:00
|
|
|
write data into the buffer, this new data will be appended to the
|
|
|
|
existing data.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param sizeNeeded
|
2008-03-09 08:33:59 -04:00
|
|
|
Amount of extra space required in the buffer for
|
|
|
|
the append operation
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void* GetAppendBuf(size_t sizeNeeded);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the size of the buffer.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
size_t GetBufSize() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return a pointer to the data in the buffer.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
void* GetData() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the valid data in the buffer.
|
|
|
|
*/
|
2008-03-24 18:17:25 -04:00
|
|
|
size_t GetDataLen() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Ensure the buffer is big enough and return a pointer to the
|
|
|
|
buffer which can be used to directly write into the buffer
|
2008-03-09 08:33:59 -04:00
|
|
|
up to @a sizeNeeded bytes.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void* GetWriteBuf(size_t sizeNeeded);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Ensures the buffer has at least @a size bytes available.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetBufSize(size_t size);
|
|
|
|
|
|
|
|
/**
|
2008-03-16 20:47:38 -04:00
|
|
|
Sets the length of the data stored in the buffer.
|
|
|
|
Mainly useful for truncating existing data.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param size
|
2008-03-09 08:33:59 -04:00
|
|
|
New length of the valid data in the buffer. This is
|
|
|
|
distinct from the allocated size
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetDataLen(size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the length after completing a direct append, which
|
|
|
|
you must have used GetAppendBuf() to initialise.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param sizeUsed
|
2008-03-09 08:33:59 -04:00
|
|
|
This is the amount of new data that has been
|
|
|
|
appended.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void UngetAppendBuf(size_t sizeUsed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the buffer after completing a direct write, which
|
|
|
|
you must have used GetWriteBuf() to initialise.
|
2008-03-16 20:47:38 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param sizeUsed
|
2008-03-09 08:33:59 -04:00
|
|
|
The amount of data written in to buffer
|
|
|
|
by the direct write
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void UngetWriteBuf(size_t sizeUsed);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|