+#define DEFINE_BUFFER(classname, chartype, strdupfunc) \
+class WXDLLIMPEXP_BASE classname \
+{ \
+public: \
+ classname(const chartype *str) \
+ : m_str(str ? strdupfunc(str) : NULL) \
+ { \
+ } \
+ \
+ classname(size_t len) \
+ : m_str((chartype *)malloc((len + 1)*sizeof(chartype))) \
+ { \
+ m_str[len] = (chartype)0; \
+ } \
+ \
+ /* no need to check for NULL, free() does it */ \
+ ~classname() { free(m_str); } \
+ \
+ /* \
+ WARNING: \
+ \
+ the copy ctor and assignment operators change the passed in object \
+ even although it is declared as "const", so: \
+ \
+ a) it shouldn't be really const \
+ b) you shouldn't use it afterwards (or know that it was reset) \
+ \
+ This is very ugly but is unfortunately needed to make the normal use\
+ of classname buffer objects possible and is very similar to what \
+ std::auto_ptr<> does (as if it were an excuse...) \
+ */ \
+ \
+ /* \
+ because of the remark above, release() is declared const even if it \
+ isn't really const \
+ */ \
+ chartype *release() const \
+ { \
+ chartype *p = m_str; \
+ ((classname *)this)->m_str = NULL; \
+ return p; \
+ } \
+ \
+ classname(const classname& src) \
+ : m_str(src.release()) \
+ { \
+ } \
+ \
+ classname& operator=(const chartype *str) \
+ { \
+ free(m_str); \
+ m_str = str ? strdupfunc(str) : NULL; \
+ return *this; \
+ } \
+ \
+ classname& operator=(const classname& src) \
+ { \
+ free(m_str); \
+ m_str = src.release(); \
+ \
+ return *this; \
+ } \
+ \
+ chartype *data() { return m_str; } \
+ const chartype *data() const { return m_str; } \
+ operator const chartype *() const { return m_str; } \
+ chartype operator[](size_t n) const { return m_str[n]; } \
+ \
+private: \
+ chartype *m_str; \
+}
+
+DEFINE_BUFFER(wxCharBuffer, char, wxStrdupA);
+
+#if wxUSE_WCHAR_T
+
+DEFINE_BUFFER(wxWCharBuffer, wchar_t, wxStrdupW);
+
+#endif // wxUSE_WCHAR_T
+
+#undef DEFINE_BUFFER
+
+#if wxUSE_UNICODE
+ #define wxMB2WXbuf wxWCharBuffer
+ #define wxWX2MBbuf wxCharBuffer
+ #define wxWC2WXbuf wxChar*
+ #define wxWX2WCbuf wxChar*
+#else // ANSI
+ #define wxMB2WXbuf wxChar*
+ #define wxWX2MBbuf wxChar*
+ #define wxWC2WXbuf wxCharBuffer
+ #define wxWX2WCbuf wxWCharBuffer
+#endif // Unicode/ANSI
+
+// ----------------------------------------------------------------------------
+// A class for holding growable data buffers (not necessarily strings)
+// ----------------------------------------------------------------------------
+
+// This class manages the actual data buffer pointer and is ref-counted.
+class wxMemoryBufferData