#ifndef _WX_BUFFER_H
#define _WX_BUFFER_H
-#include "wx/wxchar.h"
+#include "wx/chartype.h"
+#include "wx/wxcrtbase.h"
#include <stdlib.h> // malloc() and free()
-inline char *wxStrDup(const char *s) { return wxStrdupA(s); }
-#if wxUSE_WCHAR_T
- inline wchar_t *wxStrDup(const wchar_t *ws) { return wxStrdupW(ws); }
-#endif
+class WXDLLIMPEXP_FWD_BASE wxCStrData;
// ----------------------------------------------------------------------------
// Special classes for (wide) character strings: they use malloc/free instead
// ----------------------------------------------------------------------------
template <typename T>
-class wxCharTypeBuffer
+class WXDLLIMPEXP_BASE wxCharTypeBuffer
{
public:
typedef T CharType;
wxCharTypeBuffer(const CharType *str = NULL)
- : m_str(str ? wxStrDup(str) : NULL),
+ : m_str(str ? wxStrdup(str) : NULL),
m_owned(true)
{
}
m_str[len] = (CharType)0;
}
- static wxCharTypeBuffer CreateNonOwned(const CharType *str)
+ static const wxCharTypeBuffer CreateNonOwned(const CharType *str)
{
wxCharTypeBuffer buf;
- buf.m_str = str;
+ buf.m_str = wx_const_cast(CharType*, str);
buf.m_owned = false;
return buf;
}
{
if ( m_owned )
free(m_str);
- m_str = str ? wxStrDup(str) : NULL;
+ m_str = str ? wxStrdup(str) : NULL;
m_owned = true;
return *this;
}
wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
{
- if ( m_owned )
- free(m_str);
- CopyFrom(src);
+ if (&src != this)
+ {
+ if ( m_owned )
+ free(m_str);
+ CopyFrom(src);
+ }
return *this;
}
bool m_owned;
};
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer<char> )
+
class WXDLLIMPEXP_BASE wxCharBuffer : public wxCharTypeBuffer<char>
{
public:
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
+ wxCharBuffer(const wxCharTypeBufferBase& buf)
+ : wxCharTypeBufferBase(buf) {}
+
wxCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
wxCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
};
#if wxUSE_WCHAR_T
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer<wchar_t> )
+
class WXDLLIMPEXP_BASE wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
{
public:
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
+ wxWCharBuffer(const wxCharTypeBufferBase& buf)
+ : wxCharTypeBufferBase(buf) {}
+
wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
wxWCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
#define wxWX2WCbuf wxWCharBuffer
#endif // Unicode/ANSI
+// type of the value returned by wxString::utf8_str()
+#if wxUSE_UNICODE_UTF8
+ #define wxUTF8Buf char *
+#else
+ #define wxUTF8Buf wxCharBuffer
+#endif
+
// ----------------------------------------------------------------------------
// A class for holding growable data buffers (not necessarily strings)
// ----------------------------------------------------------------------------
};
-class wxMemoryBuffer
+class WXDLLIMPEXP_BASE wxMemoryBuffer
{
public:
// ctor and dtor
wxMemoryBuffer& operator=(const wxMemoryBuffer& src)
{
- m_bufdata->DecRef();
- m_bufdata = src.m_bufdata;
- m_bufdata->IncRef();
+ if (&src != this)
+ {
+ m_bufdata->DecRef();
+ m_bufdata = src.m_bufdata;
+ m_bufdata->IncRef();
+ }
return *this;
}