-#if wxUSE_UNICODE
-#define wxMB2WXbuf wxWCharBuffer
-#define wxWX2MBbuf wxCharBuffer
-#define wxWC2WXbuf wxChar*
-#define wxWX2WCbuf wxChar*
-#else
-#define wxMB2WXbuf wxChar*
-#define wxWX2MBbuf wxChar*
-#define wxWC2WXbuf wxCharBuffer
-#define wxWX2WCbuf wxWCharBuffer
-#endif
+
+class wxMemoryBuffer
+{
+public:
+ // ctor and dtor
+ wxMemoryBuffer(size_t size = wxMemoryBufferData::DefBufSize)
+ {
+ m_bufdata = new wxMemoryBufferData(size);
+ m_bufdata->IncRef();
+ }
+
+ ~wxMemoryBuffer() { m_bufdata->DecRef(); }
+
+
+ // copy and assignment
+ wxMemoryBuffer(const wxMemoryBuffer& src)
+ : m_bufdata(src.m_bufdata)
+ {
+ m_bufdata->IncRef();
+ }
+
+ wxMemoryBuffer& operator=(const wxMemoryBuffer& src)
+ {
+ m_bufdata->DecRef();
+ m_bufdata = src.m_bufdata;
+ m_bufdata->IncRef();
+ return *this;
+ }
+
+
+ // Accessors
+ void *GetData() const { return m_bufdata->m_data; }
+ size_t GetBufSize() const { return m_bufdata->m_size; }
+ size_t GetDataLen() const { return m_bufdata->m_len; }
+
+ void SetBufSize(size_t size) { m_bufdata->ResizeIfNeeded(size); }
+ void SetDataLen(size_t len)
+ {
+ wxASSERT(len <= m_bufdata->m_size);
+ m_bufdata->m_len = len;
+ }
+
+ // Ensure the buffer is big enough and return a pointer to it
+ void *GetWriteBuf(size_t sizeNeeded)
+ {
+ m_bufdata->ResizeIfNeeded(sizeNeeded);
+ return m_bufdata->m_data;
+ }
+
+ // Update the length after the write
+ void UngetWriteBuf(size_t sizeUsed) { SetDataLen(sizeUsed); }
+
+ // Like the above, but appends to the buffer
+ void *GetAppendBuf(size_t sizeNeeded)
+ {
+ m_bufdata->ResizeIfNeeded(m_bufdata->m_len + sizeNeeded);
+ return (char*)m_bufdata->m_data + m_bufdata->m_len;
+ }
+
+ // Update the length after the append
+ void UngetAppendBuf(size_t sizeUsed)
+ {
+ SetDataLen(m_bufdata->m_len + sizeUsed);
+ }
+
+ // Other ways to append to the buffer
+ void AppendByte(char data)
+ {
+ wxCHECK_RET( m_bufdata->m_data, _T("invalid wxMemoryBuffer") );
+
+ m_bufdata->ResizeIfNeeded(m_bufdata->m_len + 1);
+ *(((char*)m_bufdata->m_data) + m_bufdata->m_len) = data;
+ m_bufdata->m_len += 1;
+ }
+
+ void AppendData(const void *data, size_t len)
+ {
+ memcpy(GetAppendBuf(len), data, len);
+ UngetAppendBuf(len);
+ }
+
+ operator const char *() const { return (const char*)GetData(); }
+
+private:
+ wxMemoryBufferData* m_bufdata;
+};