- 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);
+ of wxCharTypeBuffer 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;
+ ((wxCharTypeBuffer *)this)->m_str = NULL;
+ return p;
+ }
+
+ void reset()
+ {
+ free(m_str);
+ m_str = NULL;
+ }
+
+ wxCharTypeBuffer(const wxCharTypeBuffer& src)
+ : m_str(src.release())
+ {
+ }
+
+ wxCharTypeBuffer& operator=(const CharType *str)
+ {
+ free(m_str);
+ m_str = str ? wxStrDup(str) : NULL;
+ return *this;
+ }
+
+ wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
+ {
+ free(m_str);
+ m_str = src.release();
+
+ return *this;
+ }
+
+ bool extend(size_t len)
+ {
+ CharType *
+ str = (CharType *)realloc(m_str, (len + 1)*sizeof(CharType));
+ if ( !str )
+ return false;
+
+ m_str = str;
+
+ return true;
+ }
+
+ 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;
+};
+
+class WXDLLIMPEXP_BASE wxCharBuffer : public wxCharTypeBuffer<char>
+{
+public:
+ 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
+};