// ----------------------------------------------------------------------------
template <typename T>
-class WXDLLIMPEXP_BASE wxCharTypeBuffer
+class wxCharTypeBuffer
{
public:
typedef T CharType;
{
}
- wxCharTypeBuffer(const wxCStrData& cstr)
- {
- FromCStrData(cstr);
- }
-
wxCharTypeBuffer(size_t len)
: m_str((CharType *)malloc((len + 1)*sizeof(CharType)))
{
operator const CharType *() const { return m_str; }
CharType operator[](size_t n) const { return m_str[n]; }
-private:
- void FromCStrData(const wxCStrData& cstr);
-
private:
CharType *m_str;
};
class WXDLLIMPEXP_BASE wxCharBuffer : public wxCharTypeBuffer<char>
{
public:
- wxCharBuffer(const CharType *str = NULL) : wxCharTypeBuffer<char>(str) {}
- wxCharBuffer(const wxCStrData& cstr) : wxCharTypeBuffer<char>(cstr) {}
- wxCharBuffer(size_t len) : wxCharTypeBuffer<char>(len) {}
+ typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
+
+ wxCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
+ wxCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
+
+#if !wxUSE_UNICODE
+ wxCharBuffer(const wxCStrData& cstr);
+#endif
};
#if wxUSE_WCHAR_T
class WXDLLIMPEXP_BASE wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
{
public:
- wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBuffer<wchar_t>(str) {}
- wxWCharBuffer(const wxCStrData& cstr) : wxCharTypeBuffer<wchar_t>(cstr) {}
- wxWCharBuffer(size_t len) : wxCharTypeBuffer<wchar_t>(len) {}
+ typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
+
+ wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
+ wxWCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
+
+#if wxUSE_UNICODE
+ wxWCharBuffer(const wxCStrData& cstr);
+#endif
};
#endif // wxUSE_WCHAR_T
+// wxCharTypeBuffer<T> implicitly convertible to T*
+template <typename T>
+class wxWritableCharTypeBuffer : public wxCharTypeBuffer<T>
+{
+public:
+ typedef typename wxCharTypeBuffer<T>::CharType CharType;
+
+ wxWritableCharTypeBuffer(const wxCharTypeBuffer<T>& src)
+ : wxCharTypeBuffer<T>(src) {}
+ // FIXME-UTF8: this won't be needed after converting mb_str()/wc_str() to
+ // always return a buffer
+ wxWritableCharTypeBuffer(const CharType *str = NULL)
+ : wxCharTypeBuffer<T>(str) {}
+
+ operator CharType*() { return this->data(); }
+};
+
+typedef wxWritableCharTypeBuffer<char> wxWritableCharBuffer;
+typedef wxWritableCharTypeBuffer<wchar_t> wxWritableWCharBuffer;
+
+
#if wxUSE_UNICODE
- typedef wxWCharBuffer wxWxCharBuffer;
+ #define wxWxCharBuffer wxWCharBuffer
#define wxMB2WXbuf wxWCharBuffer
#define wxWX2MBbuf wxCharBuffer
#define wxWC2WXbuf wxChar*
#define wxWX2WCbuf wxChar*
#else // ANSI
- typedef wxCharBuffer wxWxCharBuffer;
+ #define wxWxCharBuffer wxCharBuffer
#define wxMB2WXbuf wxChar*
#define wxWX2MBbuf wxChar*