+typedef wxScopedCharTypeBuffer<char> wxScopedCharBuffer;
+typedef wxScopedCharTypeBuffer<wchar_t> wxScopedWCharBuffer;
+
+
+// this buffer class always stores data in "owned" (persistent) manner
+template <typename T>
+class wxCharTypeBuffer : public wxScopedCharTypeBuffer<T>
+{
+protected:
+ typedef typename wxScopedCharTypeBuffer<T>::Data Data;
+
+public:
+ typedef T CharType;
+
+ wxCharTypeBuffer(const CharType *str = NULL, size_t len = wxNO_LEN)
+ {
+ if ( str )
+ {
+ if ( len == wxNO_LEN )
+ len = wxStrlen(str);
+ this->m_data = new Data(StrCopy(str, len), len);
+ }
+ else
+ {
+ this->m_data = this->GetNullData();
+ }
+ }
+
+ wxCharTypeBuffer(size_t len)
+ {
+ this->m_data =
+ new Data((CharType *)malloc((len + 1)*sizeof(CharType)), len);
+ this->m_data->Get()[len] = (CharType)0;
+ }
+
+ wxCharTypeBuffer(const wxCharTypeBuffer& src)
+ : wxScopedCharTypeBuffer<T>(src) {}
+
+ wxCharTypeBuffer& operator=(const CharType *str)
+ {
+ this->DecRef();
+
+ if ( str )
+ this->m_data = new Data(wxStrdup(str), wxStrlen(str));
+ return *this;
+ }
+
+ wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
+ {
+ wxScopedCharTypeBuffer<T>::operator=(src);
+ return *this;
+ }
+
+ wxCharTypeBuffer(const wxScopedCharTypeBuffer<T>& src)
+ {
+ MakeOwnedCopyOf(src);
+ }
+
+ wxCharTypeBuffer& operator=(const wxScopedCharTypeBuffer<T>& src)
+ {
+ MakeOwnedCopyOf(src);
+ return *this;
+ }
+
+ bool extend(size_t len)
+ {
+ wxASSERT_MSG( this->m_data->m_owned, "cannot extend non-owned buffer" );
+ wxASSERT_MSG( this->m_data->m_ref == 1, "can't extend shared buffer" );
+
+ CharType *str =
+ (CharType *)realloc(this->data(), (len + 1) * sizeof(CharType));
+ if ( !str )
+ return false;
+
+ if ( this->m_data == this->GetNullData() )
+ {
+ this->m_data = new Data(str, len);
+ }
+ else
+ {
+ this->m_data->Set(str, len);
+ this->m_data->m_owned = true;
+ }
+
+ return true;
+ }
+
+ void shrink(size_t len)
+ {
+ wxASSERT_MSG( this->m_data->m_owned, "cannot shrink non-owned buffer" );
+ wxASSERT_MSG( this->m_data->m_ref == 1, "can't shrink shared buffer" );
+
+ wxASSERT( len <= this->length() );
+
+ this->m_data->m_length = len;
+ this->data()[len] = 0;
+ }
+};
+
+WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxScopedCharTypeBuffer<char> )