2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: buffer.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxMemoryBuffer
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-12-01 22:09:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
wxCharTypeBuffer<T> is a template class for storing characters.
|
|
|
|
|
|
|
|
@todo provide better docs for this class
|
|
|
|
|
|
|
|
@nolibrary
|
|
|
|
@category{misc}
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
class wxCharTypeBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef T CharType;
|
|
|
|
|
|
|
|
wxCharTypeBuffer(const CharType *str = NULL);
|
|
|
|
wxCharTypeBuffer(size_t len);
|
|
|
|
wxCharTypeBuffer(const wxCharTypeBuffer& src);
|
|
|
|
~wxCharTypeBuffer();
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
wxCharTypeBuffer& operator=(const CharType *str);
|
|
|
|
wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src);
|
|
|
|
|
|
|
|
bool extend(size_t len);
|
|
|
|
|
|
|
|
CharType *data();
|
|
|
|
const CharType *data() const;
|
|
|
|
operator const CharType *() const;
|
|
|
|
CharType operator[](size_t n) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a specialization of wxCharTypeBuffer<T> for @c char type.
|
|
|
|
|
|
|
|
@todo provide better docs for this class
|
|
|
|
|
|
|
|
@nolibrary
|
|
|
|
@category{misc}
|
|
|
|
*/
|
|
|
|
class wxCharBuffer : public wxCharTypeBuffer<char>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
|
|
|
|
|
|
|
|
wxCharBuffer(const wxCharTypeBufferBase& buf);
|
|
|
|
wxCharBuffer(const CharType *str = NULL);
|
|
|
|
wxCharBuffer(size_t len);
|
|
|
|
wxCharBuffer(const wxCStrData& cstr);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is a specialization of wxCharTypeBuffer<T> for @c wchar_t type.
|
|
|
|
This class is available only when <tt>wxUSE_WCHAR_T==1</tt>
|
|
|
|
|
|
|
|
@nolibrary
|
|
|
|
@category{misc}
|
|
|
|
*/
|
|
|
|
class wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
|
|
|
|
|
|
|
|
wxWCharBuffer(const wxCharTypeBufferBase& buf);
|
|
|
|
wxWCharBuffer(const CharType *str = NULL);
|
|
|
|
wxWCharBuffer(size_t len);
|
|
|
|
wxWCharBuffer(const wxCStrData& cstr);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxMemoryBuffer
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
A @b wxMemoryBuffer is a useful data structure for storing arbitrary sized
|
2008-03-17 00:47:38 +00:00
|
|
|
blocks of memory. wxMemoryBuffer guarantees deletion of the memory block when
|
|
|
|
the object is destroyed.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
2008-03-17 00:47:38 +00:00
|
|
|
@category{data}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxMemoryBuffer
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2008-03-17 00:47:38 +00: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 13:52:38 +00:00
|
|
|
/**
|
|
|
|
Create a new buffer.
|
2008-03-17 00:47:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param size
|
2008-03-17 00:47:38 +00:00
|
|
|
size of the new buffer.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-11-10 21:33:25 +00:00
|
|
|
wxMemoryBuffer(size_t size = DefBufSize);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Append a single byte to the buffer.
|
2008-03-17 00:47:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param data
|
2008-03-09 12:33:59 +00:00
|
|
|
New byte to append to the buffer.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void AppendByte(char data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Ensure that the buffer is big enough and return a pointer to the start
|
2008-03-08 14:43:31 +00:00
|
|
|
of the empty space in the buffer. This pointer can be used to directly
|
2008-03-17 00:47:38 +00:00
|
|
|
write data into the buffer, this new data will be appended to the
|
|
|
|
existing data.
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param sizeNeeded
|
2008-03-09 12:33:59 +00:00
|
|
|
Amount of extra space required in the buffer for
|
|
|
|
the append operation
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void* GetAppendBuf(size_t sizeNeeded);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the size of the buffer.
|
|
|
|
*/
|
2008-03-24 22:17:25 +00:00
|
|
|
size_t GetBufSize() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return a pointer to the data in the buffer.
|
|
|
|
*/
|
2008-03-24 22:17:25 +00:00
|
|
|
void* GetData() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the length of the valid data in the buffer.
|
|
|
|
*/
|
2008-03-24 22:17:25 +00:00
|
|
|
size_t GetDataLen() const;
|
2008-03-08 13:52:38 +00: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 12:33:59 +00:00
|
|
|
up to @a sizeNeeded bytes.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
void* GetWriteBuf(size_t sizeNeeded);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-09 12:33:59 +00:00
|
|
|
Ensures the buffer has at least @a size bytes available.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void SetBufSize(size_t size);
|
|
|
|
|
|
|
|
/**
|
2008-03-17 00:47:38 +00:00
|
|
|
Sets the length of the data stored in the buffer.
|
|
|
|
Mainly useful for truncating existing data.
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param size
|
2008-03-09 12:33:59 +00:00
|
|
|
New length of the valid data in the buffer. This is
|
|
|
|
distinct from the allocated size
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void SetDataLen(size_t size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the length after completing a direct append, which
|
|
|
|
you must have used GetAppendBuf() to initialise.
|
2008-03-17 00:47:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param sizeUsed
|
2008-03-09 12:33:59 +00:00
|
|
|
This is the amount of new data that has been
|
|
|
|
appended.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void UngetAppendBuf(size_t sizeUsed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the buffer after completing a direct write, which
|
|
|
|
you must have used GetWriteBuf() to initialise.
|
2008-03-17 00:47:38 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param sizeUsed
|
2008-03-09 12:33:59 +00:00
|
|
|
The amount of data written in to buffer
|
|
|
|
by the direct write
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
void UngetWriteBuf(size_t sizeUsed);
|
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|