]> git.saurik.com Git - wxWidgets.git/commitdiff
split wxCharTypeBuffer<T> into wxScopedCharTypeBuffer<T> and wxCharTypeBuffer<T>...
authorVáclav Slavík <vslavik@fastmail.fm>
Fri, 27 Mar 2009 15:33:55 +0000 (15:33 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Fri, 27 Mar 2009 15:33:55 +0000 (15:33 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59887 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
include/wx/buffer.h
include/wx/mimetype.h
include/wx/motif/private.h
include/wx/string.h
include/wx/strvararg.h
include/wx/ustring.h
include/wx/utils.h
include/wx/variant.h
include/wx/wxcrt.h
include/wx/wxcrtvararg.h
interface/wx/buffer.h
src/common/string.cpp
src/common/strvararg.cpp
src/common/ustring.cpp
src/common/variant.cpp
tests/strings/strings.cpp

index 51214ee9972178926206b15db26e8705dde93a71..e3e1ac0e66bc27c0b71451ad0cacf1c55a334671 100644 (file)
@@ -64,35 +64,61 @@ extern WXDLLIMPEXP_DATA_BASE(UntypedBufferData * const) untypedNullDataPtr;
 
 } // namespace wxPrivate
 
+
+// Reference-counted character buffer for storing string data. The buffer
+// is only valid for as long as the "parent" object that provided the data
+// is valid; see wxCharTypeBuffer<T> for persistent variant.
 template <typename T>
-class wxCharTypeBuffer
+class wxScopedCharTypeBuffer
 {
 public:
     typedef T CharType;
 
-    wxCharTypeBuffer(const CharType *str = NULL)
+    wxScopedCharTypeBuffer()
     {
-        if ( str )
-            m_data = new Data(wxStrdup(str));
-        else
-            m_data = GetNullData();
+        m_data = GetNullData();
     }
 
-    wxCharTypeBuffer(size_t len)
+    // Creates "non-owned" buffer, i.e. 'str' is not owned by the buffer
+    // and doesn't get freed by dtor. Used e.g. to point to wxString's internal
+    // storage.
+    static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str)
     {
-        m_data = new Data((CharType *)malloc((len + 1)*sizeof(CharType)));
-        m_data->Get()[len] = (CharType)0;
+        wxScopedCharTypeBuffer buf;
+        if ( str )
+            buf.m_data = new Data(const_cast<CharType*>(str), Data::NonOwned);
+        return buf;
     }
 
-    static const wxCharTypeBuffer CreateNonOwned(const CharType *str)
+    // Creates "owned" buffer, i.e. takes over ownership of 'str' and frees it
+    // in dtor (if ref.count reaches 0).
+    static const wxScopedCharTypeBuffer CreateOwned(const CharType *str)
     {
-        wxCharTypeBuffer buf;
+        wxScopedCharTypeBuffer buf;
         if ( str )
-            buf.m_data = new Data(const_cast<CharType*>(str), Data::NonOwned);
+            buf.m_data = new Data(wxStrdup(str));
         return buf;
     }
 
-    ~wxCharTypeBuffer()
+    wxScopedCharTypeBuffer(const wxScopedCharTypeBuffer& src)
+    {
+        m_data = src.m_data;
+        IncRef();
+    }
+
+    wxScopedCharTypeBuffer& operator=(const wxScopedCharTypeBuffer& src)
+    {
+        if ( &src == this )
+            return *this;
+
+        DecRef();
+        m_data = src.m_data;
+        IncRef();
+
+        return *this;
+    }
+
+    ~wxScopedCharTypeBuffer()
     {
         DecRef();
     }
@@ -110,7 +136,7 @@ public:
 
         CharType * const p = m_data->Get();
 
-        wxCharTypeBuffer *self = const_cast<wxCharTypeBuffer*>(this);
+        wxScopedCharTypeBuffer *self = const_cast<wxScopedCharTypeBuffer*>(this);
         self->m_data->Set(NULL);
         self->DecRef();
 
@@ -122,62 +148,12 @@ public:
         DecRef();
     }
 
-    wxCharTypeBuffer(const wxCharTypeBuffer& src)
-    {
-        m_data = src.m_data;
-        IncRef();
-    }
-
-    wxCharTypeBuffer& operator=(const CharType *str)
-    {
-        DecRef();
-
-        if ( str )
-            m_data = new Data(wxStrdup(str));
-        return *this;
-    }
-
-    wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
-    {
-        if ( &src == this )
-            return *this;
-
-        DecRef();
-        m_data = src.m_data;
-        IncRef();
-
-        return *this;
-    }
-
-    bool extend(size_t len)
-    {
-        wxASSERT_MSG( m_data->m_owned, _T("cannot extend non-owned buffer") );
-        wxASSERT_MSG( m_data->m_ref == 1, _T("can't extend shared buffer") );
-
-        CharType *str =
-            (CharType *)realloc(data(), (len + 1) * sizeof(CharType));
-        if ( !str )
-            return false;
-
-        if ( m_data == GetNullData() )
-        {
-            m_data = new Data(str);
-        }
-        else
-        {
-            m_data->Set(str);
-            m_data->m_owned = true;
-        }
-
-        return true;
-    }
-
     CharType *data() { return m_data->Get(); }
     const CharType *data() const { return  m_data->Get(); }
     operator const CharType *() const { return data(); }
     CharType operator[](size_t n) const { return data()[n]; }
 
-private:
+protected:
     // reference-counted data
     struct Data : public wxPrivate::UntypedBufferData
     {
@@ -212,19 +188,136 @@ private:
         m_data = GetNullData();
     }
 
-private:
+    // sets this object to a be copy of 'other'; if 'src' is non-owned,
+    // a deep copy is made and 'this' will contain new instance of the data
+    void MakeOwnedCopyOf(const wxScopedCharTypeBuffer& src)
+    {
+        this->DecRef();
+
+        if ( src.m_data == this->GetNullData() )
+        {
+            this->m_data = this->GetNullData();
+        }
+        else if ( src.m_data->m_owned )
+        {
+            this->m_data = src.m_data;
+            this->IncRef();
+        }
+        else
+        {
+            // if the scoped buffer had non-owned data, we have to make
+            // a copy here, because src.m_data->m_str is valid only for as long
+            // as 'src' exists
+            this->m_data = new Data(wxStrdup(src.m_data->Get()));
+        }
+    }
+
+protected:
     Data *m_data;
 };
 
+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)
+    {
+        if ( str )
+            this->m_data = new Data(wxStrdup(str));
+        else
+            this->m_data = this->GetNullData();
+    }
+
+    wxCharTypeBuffer(size_t len)
+    {
+        this->m_data = new Data((CharType *)malloc((len + 1)*sizeof(CharType)));
+        this->m_data->Get()[len] = (CharType)0;
+    }
+
+    wxCharTypeBuffer(const wxCharTypeBuffer& src)
+    {
+        this->m_data = src.m_data;
+        this->IncRef();
+    }
+
+    wxCharTypeBuffer& operator=(const CharType *str)
+    {
+        this->DecRef();
+
+        if ( str )
+            this->m_data = new Data(wxStrdup(str));
+        return *this;
+    }
+
+    wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src)
+    {
+        if ( &src == this )
+            return *this;
+
+        this->DecRef();
+        this->m_data = src.m_data;
+        this->IncRef();
+
+        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);
+        }
+        else
+        {
+            this->m_data->Set(str);
+            this->m_data->m_owned = true;
+        }
+
+        return true;
+    }
+};
+
 WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer<char> )
 
 class wxCharBuffer : public wxCharTypeBuffer<char>
 {
 public:
     typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
+    typedef wxScopedCharTypeBuffer<char> wxScopedCharTypeBufferBase;
 
     wxCharBuffer(const wxCharTypeBufferBase& buf)
         : wxCharTypeBufferBase(buf) {}
+    wxCharBuffer(const wxScopedCharTypeBufferBase& buf)
+        : wxCharTypeBufferBase(buf) {}
 
     wxCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
     wxCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
@@ -239,9 +332,12 @@ class wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
 {
 public:
     typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
+    typedef wxScopedCharTypeBuffer<wchar_t> wxScopedCharTypeBufferBase;
 
     wxWCharBuffer(const wxCharTypeBufferBase& buf)
         : wxCharTypeBufferBase(buf) {}
+    wxWCharBuffer(const wxScopedCharTypeBufferBase& buf)
+        : wxCharTypeBufferBase(buf) {}
 
     wxWCharBuffer(const CharType *str = NULL) : wxCharTypeBufferBase(str) {}
     wxWCharBuffer(size_t len) : wxCharTypeBufferBase(len) {}
@@ -255,12 +351,14 @@ template <typename T>
 class wxWritableCharTypeBuffer : public wxCharTypeBuffer<T>
 {
 public:
-    typedef typename wxCharTypeBuffer<T>::CharType CharType;
+    typedef typename wxScopedCharTypeBuffer<T>::CharType CharType;
 
-    wxWritableCharTypeBuffer(const wxCharTypeBuffer<T>& src)
+    wxWritableCharTypeBuffer(const wxScopedCharTypeBuffer<T>& src)
         : wxCharTypeBuffer<T>(src) {}
     // FIXME-UTF8: this won't be needed after converting mb_str()/wc_str() to
     //             always return a buffer
+    //             + we should derive this class from wxScopedCharTypeBuffer
+    //               then
     wxWritableCharTypeBuffer(const CharType *str = NULL)
         : wxCharTypeBuffer<T>(str) {}
 
index f15a133dea643d4537d7d7fd4bc66e6438d8d5ef..b91059aaa0cd18e575e0f270fe2b3df05b0e9397 100644 (file)
@@ -143,8 +143,8 @@ public:
         CtorString(const wchar_t *str) : m_str(str) {}
         CtorString(const wxString& str) : m_str(str) {}
         CtorString(const wxCStrData& str) : m_str(str) {}
-        CtorString(const wxCharBuffer& str) : m_str(str) {}
-        CtorString(const wxWCharBuffer& str) : m_str(str) {}
+        CtorString(const wxScopedCharBuffer& str) : m_str(str) {}
+        CtorString(const wxScopedWCharBuffer& str) : m_str(str) {}
 
         operator const wxString*() const { return &m_str; }
 
index 89b3e70e2e48136e103d862e95e93dcc49767540..9895862d9df4a0a17ec1933068097accb2aee3ff 100644 (file)
@@ -130,7 +130,7 @@ extern XColor itemColors[5] ;
 
 wxString wxXmStringToString( const XmString& xmString );
 XmString wxStringToXmString( const char* string );
-inline XmString wxStringToXmString( const wxCharBuffer& string )
+inline XmString wxStringToXmString( const wxScopedCharBuffer& string )
     { return wxStringToXmString(string.data()); }
 inline XmString wxStringToXmString( const wxString& string )
     { return wxStringToXmString((const char*)string.mb_str()); }
index ec66dce85c61d59510dd176e800b1d5a3434ec04..ebd2f0f774e71561ccf5be68c27edc82c9538aa0 100644 (file)
@@ -245,8 +245,9 @@ public:
 
     operator const void*() const { return AsChar(); }
 
-    inline const wxCharBuffer AsCharBuf() const;
-    inline const wxWCharBuffer AsWCharBuf() const;
+    // returns buffers that are valid as long as the associated wxString exists
+    inline const wxScopedCharBuffer AsCharBuf() const;
+    inline const wxScopedWCharBuffer AsWCharBuf() const;
 
     inline wxString AsString() const;
 
@@ -486,14 +487,14 @@ private:
 
 #if wxUSE_UNICODE_UTF8
   // even char* -> char* needs conversion, from locale charset to UTF-8
-  typedef SubstrBufFromType<wxCharBuffer>    SubstrBufFromWC;
-  typedef SubstrBufFromType<wxCharBuffer>    SubstrBufFromMB;
+  typedef SubstrBufFromType<wxScopedCharBuffer>    SubstrBufFromWC;
+  typedef SubstrBufFromType<wxScopedCharBuffer>    SubstrBufFromMB;
 #elif wxUSE_UNICODE_WCHAR
-  typedef SubstrBufFromType<const wchar_t*>  SubstrBufFromWC;
-  typedef SubstrBufFromType<wxWCharBuffer>   SubstrBufFromMB;
+  typedef SubstrBufFromType<const wchar_t*>        SubstrBufFromWC;
+  typedef SubstrBufFromType<wxScopedWCharBuffer>   SubstrBufFromMB;
 #else
-  typedef SubstrBufFromType<const char*>     SubstrBufFromMB;
-  typedef SubstrBufFromType<wxCharBuffer>    SubstrBufFromWC;
+  typedef SubstrBufFromType<const char*>           SubstrBufFromMB;
+  typedef SubstrBufFromType<wxScopedCharBuffer>    SubstrBufFromWC;
 #endif
 
 
@@ -522,8 +523,8 @@ private:
     { return str ? str : wxT(""); }
   static const SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
     { return SubstrBufFromWC(str, (str && n == npos) ? wxWcslen(str) : n); }
-  static wxWCharBuffer ImplStr(const char* str,
-                               const wxMBConv& conv = wxConvLibc)
+  static wxScopedWCharBuffer ImplStr(const char* str,
+                                     const wxMBConv& conv = wxConvLibc)
     { return ConvertStr(str, npos, conv).data; }
   static SubstrBufFromMB ImplStr(const char* str, size_t n,
                                  const wxMBConv& conv = wxConvLibc)
@@ -535,7 +536,7 @@ private:
   static const SubstrBufFromMB ImplStr(const char* str, size_t n,
                                        const wxMBConv& WXUNUSED(conv) = wxConvLibc)
     { return SubstrBufFromMB(str, (str && n == npos) ? wxStrlen(str) : n); }
-  static wxCharBuffer ImplStr(const wchar_t* str)
+  static wxScopedCharBuffer ImplStr(const wchar_t* str)
     { return ConvertStr(str, npos, wxConvLibc).data; }
   static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
     { return ConvertStr(str, n, wxConvLibc); }
@@ -560,14 +561,14 @@ private:
 
 #else // wxUSE_UNICODE_UTF8
 
-  static wxCharBuffer ImplStr(const char* str,
-                              const wxMBConv& conv = wxConvLibc)
+  static wxScopedCharBuffer ImplStr(const char* str,
+                                    const wxMBConv& conv = wxConvLibc)
     { return ConvertStr(str, npos, conv).data; }
   static SubstrBufFromMB ImplStr(const char* str, size_t n,
                                  const wxMBConv& conv = wxConvLibc)
     { return ConvertStr(str, n, conv); }
 
-  static wxCharBuffer ImplStr(const wchar_t* str)
+  static wxScopedCharBuffer ImplStr(const wchar_t* str)
     { return ConvertStr(str, npos, wxMBConvUTF8()).data; }
   static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
     { return ConvertStr(str, n, wxMBConvUTF8()); }
@@ -1275,9 +1276,9 @@ public:
   wxString(const wchar_t *pwz, const wxMBConv& WXUNUSED(conv), size_t nLength)
     { assign(pwz, nLength); }
 
-  wxString(const wxCharBuffer& buf)
+  wxString(const wxScopedCharBuffer& buf)
     { assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
-  wxString(const wxWCharBuffer& buf)
+  wxString(const wxScopedWCharBuffer& buf)
     { assign(buf.data()); } // FIXME-UTF8: fix for embedded NUL and buffer length
 
     // NB: this version uses m_impl.c_str() to force making a copy of the
@@ -1650,7 +1651,7 @@ public:
     static wxString FromAscii(const char *ascii, size_t len);
     static wxString FromAscii(const char *ascii);
     static wxString FromAscii(char ascii);
-    const wxCharBuffer ToAscii() const;
+    const wxScopedCharBuffer ToAscii() const;
 #else // ANSI
     static wxString FromAscii(const char *ascii) { return wxString( ascii ); }
     static wxString FromAscii(const char *ascii, size_t len)
@@ -1721,31 +1722,37 @@ public:
                       "string must be valid UTF-8" );
         return s;
     }
-    const wxCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
-    const wxCharBuffer ToUTF8() const { return utf8_str(); }
+    const wxScopedCharBuffer utf8_str() const { return mb_str(wxMBConvUTF8()); }
+    const wxScopedCharBuffer ToUTF8() const { return utf8_str(); }
 #else // ANSI
     static wxString FromUTF8(const char *utf8)
       { return wxString(wxMBConvUTF8().cMB2WC(utf8)); }
     static wxString FromUTF8(const char *utf8, size_t len)
     {
         size_t wlen;
-        wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
+        wxScopedWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8, len == npos ? wxNO_LEN : len, &wlen));
         return wxString(buf.data(), wlen);
     }
     static wxString FromUTF8Unchecked(const char *utf8, size_t len = npos)
     {
         size_t wlen;
-        wxWCharBuffer buf(wxMBConvUTF8().cMB2WC(utf8,
-                                                len == npos ? wxNO_LEN : len,
-                                                &wlen));
+        wxScopedWCharBuffer buf
+                            (
+                              wxMBConvUTF8().cMB2WC
+                                             (
+                                               utf8,
+                                               len == npos ? wxNO_LEN : len,
+                                               &wlen
+                                             )
+                            );
         wxASSERT_MSG( !utf8 || !*utf8 || wlen,
                       "string must be valid UTF-8" );
 
         return wxString(buf.data(), wlen);
     }
-    const wxCharBuffer utf8_str() const
+    const wxScopedCharBuffer utf8_str() const
       { return wxMBConvUTF8().cWC2MB(wc_str()); }
-    const wxCharBuffer ToUTF8() const { return utf8_str(); }
+    const wxScopedCharBuffer ToUTF8() const { return utf8_str(); }
 #endif
 
     // functions for storing binary data in wxString:
@@ -1755,7 +1762,8 @@ public:
     // version for NUL-terminated data:
     static wxString From8BitData(const char *data)
       { return wxString(data, wxConvISO8859_1); }
-    const wxCharBuffer To8BitData() const { return mb_str(wxConvISO8859_1); }
+    const wxScopedCharBuffer To8BitData() const
+        { return mb_str(wxConvISO8859_1); }
 #else // ANSI
     static wxString From8BitData(const char *data, size_t len)
       { return wxString(data, len); }
@@ -1778,9 +1786,9 @@ public:
 
 #if wxUSE_UTF8_LOCALE_ONLY
     const char* mb_str() const { return wx_str(); }
-    const wxCharBuffer mb_str(const wxMBConv& conv) const;
+    const wxScopedCharBuffer mb_str(const wxMBConv& conv) const;
 #else
-    const wxCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
+    const wxScopedCharBuffer mb_str(const wxMBConv& conv = wxConvLibc) const;
 #endif
 
     const wxWX2MBbuf mbc_str() const { return mb_str(*wxConvCurrent); }
@@ -1788,14 +1796,14 @@ public:
 #if wxUSE_UNICODE_WCHAR
     const wchar_t* wc_str() const { return wx_str(); }
 #elif wxUSE_UNICODE_UTF8
-    const wxWCharBuffer wc_str() const;
+    const wxScopedWCharBuffer wc_str() const;
 #endif
     // for compatibility with !wxUSE_UNICODE version
     const wxWX2WCbuf wc_str(const wxMBConv& WXUNUSED(conv)) const
       { return wc_str(); }
 
 #if wxMBFILES
-    const wxCharBuffer fn_str() const { return mb_str(wxConvFile); }
+    const wxScopedCharBuffer fn_str() const { return mb_str(wxConvFile); }
 #else // !wxMBFILES
     const wxWX2WCbuf fn_str() const { return wc_str(); }
 #endif // wxMBFILES/!wxMBFILES
@@ -1809,13 +1817,14 @@ public:
     const wxWX2MBbuf mbc_str() const { return mb_str(); }
 
 #if wxUSE_WCHAR_T
-    const wxWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const;
+    const wxScopedWCharBuffer wc_str(const wxMBConv& conv = wxConvLibc) const;
 #endif // wxUSE_WCHAR_T
-    const wxCharBuffer fn_str() const { return wxConvFile.cWC2WX( wc_str( wxConvLibc ) ); }
+    const wxScopedCharBuffer fn_str() const
+        { return wxConvFile.cWC2WX( wc_str( wxConvLibc ) ); }
 #endif // Unicode/ANSI
 
 #if wxUSE_UNICODE_UTF8
-    const wxWCharBuffer t_str() const { return wc_str(); }
+    const wxScopedWCharBuffer t_str() const { return wc_str(); }
 #elif wxUSE_UNICODE_WCHAR
     const wchar_t* t_str() const { return wx_str(); }
 #else
@@ -1910,11 +1919,11 @@ public:
   wxString& operator=(const unsigned char *psz)
     { return operator=((const char*)psz); }
 
-    // from wxWCharBuffer
-  wxString& operator=(const wxWCharBuffer& s)
+    // from wxScopedWCharBuffer
+  wxString& operator=(const wxScopedWCharBuffer& s)
     { return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
-    // from wxCharBuffer
-  wxString& operator=(const wxCharBuffer& s)
+    // from wxScopedCharBuffer
+  wxString& operator=(const wxScopedCharBuffer& s)
     { return operator=(s.data()); } // FIXME-UTF8: fix for embedded NULs
 
   // string concatenation
@@ -1950,9 +1959,9 @@ public:
   wxString& operator<<(wchar_t ch) { append(1, ch); return *this; }
 
       // string += buffer (i.e. from wxGetString)
-  wxString& operator<<(const wxWCharBuffer& s)
+  wxString& operator<<(const wxScopedWCharBuffer& s)
     { return operator<<((const wchar_t *)s); }
-  wxString& operator<<(const wxCharBuffer& s)
+  wxString& operator<<(const wxScopedCharBuffer& s)
     { return operator<<((const char *)s); }
 
     // string += C string
@@ -1971,9 +1980,9 @@ public:
     { append(pwz); return *this; }
   wxString& Append(const wxCStrData& psz)
     { append(psz); return *this; }
-  wxString& Append(const wxCharBuffer& psz)
+  wxString& Append(const wxScopedCharBuffer& psz)
     { append(psz); return *this; }
-  wxString& Append(const wxWCharBuffer& psz)
+  wxString& Append(const wxScopedWCharBuffer& psz)
     { append(psz); return *this; }
   wxString& Append(const char* psz, size_t nLen)
     { append(psz, nLen); return *this; }
@@ -1981,9 +1990,9 @@ public:
     { append(pwz, nLen); return *this; }
   wxString& Append(const wxCStrData& psz, size_t nLen)
     { append(psz, nLen); return *this; }
-  wxString& Append(const wxCharBuffer& psz, size_t nLen)
+  wxString& Append(const wxScopedCharBuffer& psz, size_t nLen)
     { append(psz, nLen); return *this; }
-  wxString& Append(const wxWCharBuffer& psz, size_t nLen)
+  wxString& Append(const wxScopedWCharBuffer& psz, size_t nLen)
     { append(psz, nLen); return *this; }
     // append count copies of given character
   wxString& Append(wxUniChar ch, size_t count = 1u)
@@ -2064,9 +2073,9 @@ public:
     { return compare(s); }
   int Cmp(const wxCStrData& s) const
     { return compare(s); }
-  int Cmp(const wxCharBuffer& s) const
+  int Cmp(const wxScopedCharBuffer& s) const
     { return compare(s); }
-  int Cmp(const wxWCharBuffer& s) const
+  int Cmp(const wxScopedWCharBuffer& s) const
     { return compare(s); }
     // same as Cmp() but not case-sensitive
   int CmpNoCase(const wxString& s) const;
@@ -2089,9 +2098,9 @@ public:
 
   bool IsSameAs(const wxCStrData& str, bool compareWithCase = true) const
     { return IsSameAs(str.AsString(), compareWithCase); }
-  bool IsSameAs(const wxCharBuffer& str, bool compareWithCase = true) const
+  bool IsSameAs(const wxScopedCharBuffer& str, bool compareWithCase = true) const
     { return IsSameAs(str.data(), compareWithCase); }
-  bool IsSameAs(const wxWCharBuffer& str, bool compareWithCase = true) const
+  bool IsSameAs(const wxScopedWCharBuffer& str, bool compareWithCase = true) const
     { return IsSameAs(str.data(), compareWithCase); }
     // comparison with a single character: returns true if equal
   bool IsSameAs(wxUniChar c, bool compareWithCase = true) const;
@@ -2198,9 +2207,9 @@ public:
 
   int Find(const wxCStrData& sub) const
     { return Find(sub.AsString()); }
-  int Find(const wxCharBuffer& sub) const
+  int Find(const wxScopedCharBuffer& sub) const
     { return Find(sub.data()); }
-  int Find(const wxWCharBuffer& sub) const
+  int Find(const wxScopedWCharBuffer& sub) const
     { return Find(sub.data()); }
 
       // replace first (or all of bReplaceAll) occurrences of substring with
@@ -2454,15 +2463,15 @@ public:
 
   wxString& append(const wxCStrData& str)
     { return append(str.AsString()); }
-  wxString& append(const wxCharBuffer& str)
+  wxString& append(const wxScopedCharBuffer& str)
     { return append(str.data()); }
-  wxString& append(const wxWCharBuffer& str)
+  wxString& append(const wxScopedWCharBuffer& str)
     { return append(str.data()); }
   wxString& append(const wxCStrData& str, size_t n)
     { return append(str.AsString(), 0, n); }
-  wxString& append(const wxCharBuffer& str, size_t n)
+  wxString& append(const wxScopedCharBuffer& str, size_t n)
     { return append(str.data(), n); }
-  wxString& append(const wxWCharBuffer& str, size_t n)
+  wxString& append(const wxScopedWCharBuffer& str, size_t n)
     { return append(str.data(), n); }
 
     // append n copies of ch
@@ -2586,15 +2595,15 @@ public:
 
   wxString& assign(const wxCStrData& str)
     { return assign(str.AsString()); }
-  wxString& assign(const wxCharBuffer& str)
+  wxString& assign(const wxScopedCharBuffer& str)
     { return assign(str.data()); }
-  wxString& assign(const wxWCharBuffer& str)
+  wxString& assign(const wxScopedWCharBuffer& str)
     { return assign(str.data()); }
   wxString& assign(const wxCStrData& str, size_t len)
     { return assign(str.AsString(), len); }
-  wxString& assign(const wxCharBuffer& str, size_t len)
+  wxString& assign(const wxScopedCharBuffer& str, size_t len)
     { return assign(str.data(), len); }
-  wxString& assign(const wxWCharBuffer& str, size_t len)
+  wxString& assign(const wxScopedWCharBuffer& str, size_t len)
     { return assign(str.data(), len); }
 
     // same as `= n copies of ch'
@@ -2645,9 +2654,9 @@ public:
   int compare(const wchar_t* sz) const;
   int compare(const wxCStrData& str) const
     { return compare(str.AsString()); }
-  int compare(const wxCharBuffer& str) const
+  int compare(const wxScopedCharBuffer& str) const
     { return compare(str.data()); }
-  int compare(const wxWCharBuffer& str) const
+  int compare(const wxScopedWCharBuffer& str) const
     { return compare(str.data()); }
     // comparison with a substring
   int compare(size_t nStart, size_t nLen, const wxString& str) const;
@@ -3028,9 +3037,9 @@ public:
       SubstrBufFromWC str(ImplStr(sz, n));
       return PosFromImpl(m_impl.find(str.data, PosToImpl(nStart), str.len));
   }
-  size_t find(const wxCharBuffer& s, size_t nStart = 0, size_t n = npos) const
+  size_t find(const wxScopedCharBuffer& s, size_t nStart = 0, size_t n = npos) const
     { return find(s.data(), nStart, n); }
-  size_t find(const wxWCharBuffer& s, size_t nStart = 0, size_t n = npos) const
+  size_t find(const wxScopedWCharBuffer& s, size_t nStart = 0, size_t n = npos) const
     { return find(s.data(), nStart, n); }
   size_t find(const wxCStrData& s, size_t nStart = 0, size_t n = npos) const
     { return find(s.AsWChar(), nStart, n); }
@@ -3074,9 +3083,9 @@ public:
       SubstrBufFromWC str(ImplStr(sz, n));
       return PosFromImpl(m_impl.rfind(str.data, PosToImpl(nStart), str.len));
   }
-  size_t rfind(const wxCharBuffer& s, size_t nStart = npos, size_t n = npos) const
+  size_t rfind(const wxScopedCharBuffer& s, size_t nStart = npos, size_t n = npos) const
     { return rfind(s.data(), nStart, n); }
-  size_t rfind(const wxWCharBuffer& s, size_t nStart = npos, size_t n = npos) const
+  size_t rfind(const wxScopedWCharBuffer& s, size_t nStart = npos, size_t n = npos) const
     { return rfind(s.data(), nStart, n); }
   size_t rfind(const wxCStrData& s, size_t nStart = npos, size_t n = npos) const
     { return rfind(s.AsWChar(), nStart, n); }
@@ -3262,54 +3271,54 @@ public:
   // and additional overloads for the versions taking strings:
   size_t find_first_of(const wxCStrData& sz, size_t nStart = 0) const
     { return find_first_of(sz.AsString(), nStart); }
-  size_t find_first_of(const wxCharBuffer& sz, size_t nStart = 0) const
+  size_t find_first_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
     { return find_first_of(sz.data(), nStart); }
-  size_t find_first_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+  size_t find_first_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
     { return find_first_of(sz.data(), nStart); }
   size_t find_first_of(const wxCStrData& sz, size_t nStart, size_t n) const
     { return find_first_of(sz.AsWChar(), nStart, n); }
-  size_t find_first_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_first_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
     { return find_first_of(sz.data(), nStart, n); }
-  size_t find_first_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_first_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
     { return find_first_of(sz.data(), nStart, n); }
 
   size_t find_last_of(const wxCStrData& sz, size_t nStart = 0) const
     { return find_last_of(sz.AsString(), nStart); }
-  size_t find_last_of(const wxCharBuffer& sz, size_t nStart = 0) const
+  size_t find_last_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
     { return find_last_of(sz.data(), nStart); }
-  size_t find_last_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+  size_t find_last_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
     { return find_last_of(sz.data(), nStart); }
   size_t find_last_of(const wxCStrData& sz, size_t nStart, size_t n) const
     { return find_last_of(sz.AsWChar(), nStart, n); }
-  size_t find_last_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_last_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
     { return find_last_of(sz.data(), nStart, n); }
-  size_t find_last_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_last_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
     { return find_last_of(sz.data(), nStart, n); }
 
   size_t find_first_not_of(const wxCStrData& sz, size_t nStart = 0) const
     { return find_first_not_of(sz.AsString(), nStart); }
-  size_t find_first_not_of(const wxCharBuffer& sz, size_t nStart = 0) const
+  size_t find_first_not_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
     { return find_first_not_of(sz.data(), nStart); }
-  size_t find_first_not_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+  size_t find_first_not_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
     { return find_first_not_of(sz.data(), nStart); }
   size_t find_first_not_of(const wxCStrData& sz, size_t nStart, size_t n) const
     { return find_first_not_of(sz.AsWChar(), nStart, n); }
-  size_t find_first_not_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_first_not_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
     { return find_first_not_of(sz.data(), nStart, n); }
-  size_t find_first_not_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_first_not_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
     { return find_first_not_of(sz.data(), nStart, n); }
 
   size_t find_last_not_of(const wxCStrData& sz, size_t nStart = 0) const
     { return find_last_not_of(sz.AsString(), nStart); }
-  size_t find_last_not_of(const wxCharBuffer& sz, size_t nStart = 0) const
+  size_t find_last_not_of(const wxScopedCharBuffer& sz, size_t nStart = 0) const
     { return find_last_not_of(sz.data(), nStart); }
-  size_t find_last_not_of(const wxWCharBuffer& sz, size_t nStart = 0) const
+  size_t find_last_not_of(const wxScopedWCharBuffer& sz, size_t nStart = 0) const
     { return find_last_not_of(sz.data(), nStart); }
   size_t find_last_not_of(const wxCStrData& sz, size_t nStart, size_t n) const
     { return find_last_not_of(sz.AsWChar(), nStart, n); }
-  size_t find_last_not_of(const wxCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_last_not_of(const wxScopedCharBuffer& sz, size_t nStart, size_t n) const
     { return find_last_not_of(sz.data(), nStart, n); }
-  size_t find_last_not_of(const wxWCharBuffer& sz, size_t nStart, size_t n) const
+  size_t find_last_not_of(const wxScopedWCharBuffer& sz, size_t nStart, size_t n) const
     { return find_last_not_of(sz.data(), nStart, n); }
 
       // string += string
@@ -3342,9 +3351,9 @@ public:
       m_impl += s.AsString().m_impl;
       return *this;
   }
-  wxString& operator+=(const wxCharBuffer& s)
+  wxString& operator+=(const wxScopedCharBuffer& s)
     { return operator+=(s.data()); }
-  wxString& operator+=(const wxWCharBuffer& s)
+  wxString& operator+=(const wxScopedWCharBuffer& s)
     { return operator+=(s.data()); }
       // string += char
   wxString& operator+=(wxUniChar ch)
@@ -3517,9 +3526,9 @@ namespace wxPrivate
 template <>
 struct wxStringAsBufHelper<char>
 {
-    static wxCharBuffer Get(const wxString& s, size_t *len)
+    static wxScopedCharBuffer Get(const wxString& s, size_t *len)
     {
-        wxCharBuffer buf(s.mb_str());
+        wxScopedCharBuffer buf(s.mb_str());
         if ( len )
             *len = buf ? strlen(buf) : 0;
         return buf;
@@ -3529,11 +3538,11 @@ struct wxStringAsBufHelper<char>
 template <>
 struct wxStringAsBufHelper<wchar_t>
 {
-    static wxWCharBuffer Get(const wxString& s, size_t *len)
+    static wxScopedWCharBuffer Get(const wxString& s, size_t *len)
     {
         if ( len )
             *len = s.length();
-        return wxWCharBuffer::CreateNonOwned(s.wx_str());
+        return wxScopedWCharBuffer::CreateNonOwned(s.wx_str());
     }
 };
 
@@ -3542,20 +3551,20 @@ struct wxStringAsBufHelper<wchar_t>
 template <>
 struct wxStringAsBufHelper<char>
 {
-    static wxCharBuffer Get(const wxString& s, size_t *len)
+    static wxScopedCharBuffer Get(const wxString& s, size_t *len)
     {
         if ( len )
             *len = s.utf8_length();
-        return wxCharBuffer::CreateNonOwned(s.wx_str());
+        return wxScopedCharBuffer::CreateNonOwned(s.wx_str());
     }
 };
 
 template <>
 struct wxStringAsBufHelper<wchar_t>
 {
-    static wxWCharBuffer Get(const wxString& s, size_t *len)
+    static wxScopedWCharBuffer Get(const wxString& s, size_t *len)
     {
-        wxWCharBuffer wbuf(s.wc_str());
+        wxScopedWCharBuffer wbuf(s.wc_str());
         if ( len )
             *len = wxWcslen(wbuf);
         return wbuf;
@@ -3859,32 +3868,32 @@ inline bool operator!=(const wxString& s1, const wxCStrData& s2)
 inline bool operator!=(const wxCStrData& s1, const wxString& s2)
     { return s1.AsString() != s2; }
 
-inline bool operator==(const wxString& s1, const wxWCharBuffer& s2)
+inline bool operator==(const wxString& s1, const wxScopedWCharBuffer& s2)
     { return (s1.Cmp((const wchar_t *)s2) == 0); }
-inline bool operator==(const wxWCharBuffer& s1, const wxString& s2)
+inline bool operator==(const wxScopedWCharBuffer& s1, const wxString& s2)
     { return (s2.Cmp((const wchar_t *)s1) == 0); }
-inline bool operator!=(const wxString& s1, const wxWCharBuffer& s2)
+inline bool operator!=(const wxString& s1, const wxScopedWCharBuffer& s2)
     { return (s1.Cmp((const wchar_t *)s2) != 0); }
-inline bool operator!=(const wxWCharBuffer& s1, const wxString& s2)
+inline bool operator!=(const wxScopedWCharBuffer& s1, const wxString& s2)
     { return (s2.Cmp((const wchar_t *)s1) != 0); }
 
-inline bool operator==(const wxString& s1, const wxCharBuffer& s2)
+inline bool operator==(const wxString& s1, const wxScopedCharBuffer& s2)
     { return (s1.Cmp((const char *)s2) == 0); }
-inline bool operator==(const wxCharBuffer& s1, const wxString& s2)
+inline bool operator==(const wxScopedCharBuffer& s1, const wxString& s2)
     { return (s2.Cmp((const char *)s1) == 0); }
-inline bool operator!=(const wxString& s1, const wxCharBuffer& s2)
+inline bool operator!=(const wxString& s1, const wxScopedCharBuffer& s2)
     { return (s1.Cmp((const char *)s2) != 0); }
-inline bool operator!=(const wxCharBuffer& s1, const wxString& s2)
+inline bool operator!=(const wxScopedCharBuffer& s1, const wxString& s2)
     { return (s2.Cmp((const char *)s1) != 0); }
 
-inline wxString operator+(const wxString& string, const wxWCharBuffer& buf)
+inline wxString operator+(const wxString& string, const wxScopedWCharBuffer& buf)
     { return string + (const wchar_t *)buf; }
-inline wxString operator+(const wxWCharBuffer& buf, const wxString& string)
+inline wxString operator+(const wxScopedWCharBuffer& buf, const wxString& string)
     { return (const wchar_t *)buf + string; }
 
-inline wxString operator+(const wxString& string, const wxCharBuffer& buf)
+inline wxString operator+(const wxString& string, const wxScopedCharBuffer& buf)
     { return string + (const char *)buf; }
-inline wxString operator+(const wxCharBuffer& buf, const wxString& string)
+inline wxString operator+(const wxScopedCharBuffer& buf, const wxString& string)
     { return (const char *)buf + string; }
 
 // comparison with char
@@ -3942,16 +3951,16 @@ wxDEFINE_ALL_COMPARISONS(const char *, const wxCStrData&, wxCMP_CHAR_CSTRDATA)
 
 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxString&);
 WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCStrData&);
-WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxCharBuffer&);
+WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxScopedCharBuffer&);
 #ifndef __BORLANDC__
-WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxWCharBuffer&);
+WXDLLIMPEXP_BASE wxSTD ostream& operator<<(wxSTD ostream&, const wxScopedWCharBuffer&);
 #endif
 
 #if wxUSE_UNICODE && defined(HAVE_WOSTREAM)
 
 WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxString&);
 WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxCStrData&);
-WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxWCharBuffer&);
+WXDLLIMPEXP_BASE wxSTD wostream& operator<<(wxSTD wostream&, const wxScopedWCharBuffer&);
 
 #endif  // wxUSE_UNICODE && defined(HAVE_WOSTREAM)
 
@@ -4002,19 +4011,19 @@ inline const char* wxCStrData::AsChar() const
 }
 #endif // wxUSE_UTF8_LOCALE_ONLY
 
-inline const wxCharBuffer wxCStrData::AsCharBuf() const
+inline const wxScopedCharBuffer wxCStrData::AsCharBuf() const
 {
 #if !wxUSE_UNICODE
-    return wxCharBuffer::CreateNonOwned(AsChar());
+    return wxScopedCharBuffer::CreateNonOwned(AsChar());
 #else
     return AsString().mb_str();
 #endif
 }
 
-inline const wxWCharBuffer wxCStrData::AsWCharBuf() const
+inline const wxScopedWCharBuffer wxCStrData::AsWCharBuf() const
 {
 #if wxUSE_UNICODE_WCHAR
-    return wxWCharBuffer::CreateNonOwned(AsWChar());
+    return wxScopedWCharBuffer::CreateNonOwned(AsWChar());
 #else
     return AsString().wc_str();
 #endif
index e81a083a61dcab04e42e70b76e183f68f167388d..112d11827eb7e5b7c4b0bd3dca67d4fb2b91c6a1 100644 (file)
@@ -128,16 +128,16 @@ class WXDLLIMPEXP_BASE wxFormatString
 {
 public:
     wxFormatString(const char *str)
-        : m_char(wxCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
+        : m_char(wxScopedCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
     wxFormatString(const wchar_t *str)
-        : m_wchar(wxWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
+        : m_wchar(wxScopedWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {}
     wxFormatString(const wxString& str)
         : m_str(&str), m_cstr(NULL) {}
     wxFormatString(const wxCStrData& str)
         : m_str(NULL), m_cstr(&str) {}
-    wxFormatString(const wxCharBuffer& str)
+    wxFormatString(const wxScopedCharBuffer& str)
         : m_char(str), m_str(NULL), m_cstr(NULL)  {}
-    wxFormatString(const wxWCharBuffer& str)
+    wxFormatString(const wxScopedWCharBuffer& str)
         : m_wchar(str), m_str(NULL), m_cstr(NULL) {}
 
 
@@ -168,7 +168,7 @@ private:
     // ..AsWChar() below)
     const char* InputAsChar();
     const char* AsChar();
-    wxCharBuffer m_convertedChar;
+    wxScopedCharBuffer m_convertedChar;
 #endif // !wxUSE_UNICODE_WCHAR
 
 #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
@@ -178,12 +178,12 @@ public:
 private:
     const wchar_t* InputAsWChar();
     const wchar_t* AsWChar();
-    wxWCharBuffer m_convertedWChar;
+    wxScopedWCharBuffer m_convertedWChar;
 #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY
 
 private:
-    wxCharBuffer  m_char;
-    wxWCharBuffer m_wchar;
+    wxScopedCharBuffer  m_char;
+    wxScopedWCharBuffer m_wchar;
 
     // NB: we can use a pointer here, because wxFormatString is only used
     //     as function argument, so it has shorter life than the string
@@ -240,12 +240,12 @@ struct wxFormatStringArgumentFinder<wxString>
     : public wxFormatStringArgumentFinder<const wxString&> {};
 
 template<>
-struct wxFormatStringArgumentFinder<wxCharBuffer>
-    : public wxFormatStringArgumentFinder<const wxCharBuffer&> {};
+struct wxFormatStringArgumentFinder<wxScopedCharBuffer>
+    : public wxFormatStringArgumentFinder<const wxScopedCharBuffer&> {};
 
 template<>
-struct wxFormatStringArgumentFinder<wxWCharBuffer>
-    : public wxFormatStringArgumentFinder<const wxWCharBuffer&> {};
+struct wxFormatStringArgumentFinder<wxScopedWCharBuffer>
+    : public wxFormatStringArgumentFinder<const wxScopedWCharBuffer&> {};
 
 
 // ----------------------------------------------------------------------------
@@ -314,7 +314,7 @@ struct wxArgNormalizerWchar : public wxArgNormalizer<T>
 template<typename CharType>
 struct wxArgNormalizerWithBuffer
 {
-    typedef wxCharTypeBuffer<CharType> CharBuffer;
+    typedef wxScopedCharTypeBuffer<CharType> CharBuffer;
 
     wxArgNormalizerWithBuffer() {}
     wxArgNormalizerWithBuffer(const CharBuffer& buf,
@@ -409,12 +409,12 @@ struct wxArgNormalizerUtf8<const char*>
     {
         if ( wxLocaleIsUtf8 )
         {
-            m_value = wxCharBuffer::CreateNonOwned(s);
+            m_value = wxScopedCharBuffer::CreateNonOwned(s);
         }
         else
         {
             // convert to widechar string first:
-            wxWCharBuffer buf(wxConvLibc.cMB2WC(s));
+            wxScopedWCharBuffer buf(wxConvLibc.cMB2WC(s));
 
             // then to UTF-8:
             if ( buf )
@@ -485,10 +485,10 @@ WX_ARG_NORMALIZER_FORWARD(char*, const char*);
 WX_ARG_NORMALIZER_FORWARD(wchar_t*, const wchar_t*);
 
 // versions for passing wx[W]CharBuffer:
-WX_ARG_NORMALIZER_FORWARD(wxCharBuffer, const char*);
-WX_ARG_NORMALIZER_FORWARD(const wxCharBuffer&, const char*);
-WX_ARG_NORMALIZER_FORWARD(wxWCharBuffer, const wchar_t*);
-WX_ARG_NORMALIZER_FORWARD(const wxWCharBuffer&, const wchar_t*);
+WX_ARG_NORMALIZER_FORWARD(wxScopedCharBuffer, const char*);
+WX_ARG_NORMALIZER_FORWARD(const wxScopedCharBuffer&, const char*);
+WX_ARG_NORMALIZER_FORWARD(wxScopedWCharBuffer, const wchar_t*);
+WX_ARG_NORMALIZER_FORWARD(const wxScopedWCharBuffer&, const wchar_t*);
 
 // versions for std::[w]string:
 #if wxUSE_STD_STRING
index cf42a1024c17140e6ebb809b7555715892bf90cc..68494d576721ebde298be32bb1f9768c19feeb3a 100644 (file)
 
 #if SIZEOF_WCHAR_T == 2
 typedef wxWCharBuffer wxU16CharBuffer;
+typedef wxScopedWCharBuffer wxScopedU16CharBuffer;
 #else
 typedef wxCharTypeBuffer<wxChar16> wxU16CharBuffer;
+typedef wxScopedCharTypeBuffer<wxChar16> wxScopedU16CharBuffer;
 #endif
 
 #if SIZEOF_WCHAR_T == 4
 typedef wxWCharBuffer wxU32CharBuffer;
+typedef wxScopedWCharBuffer wxScopedU32CharBuffer;
 #else
 typedef wxCharTypeBuffer<wxChar32> wxU32CharBuffer;
+typedef wxScopedCharTypeBuffer<wxChar32> wxScopedU32CharBuffer;
 #endif
 
 
@@ -35,15 +39,15 @@ public:
 
     wxUString( const wxChar32 *str )                            { assign(str); }
     wxUString( const wxUString &str )                           { assign(str); }
-    wxUString( const wxU32CharBuffer &buf )                     { assign(buf); }
+    wxUString( const wxScopedU32CharBuffer &buf )                     { assign(buf); }
 
     wxUString( const char *str )                                { assign(str); }
-    wxUString( const wxCharBuffer &buf )                        { assign(buf); }
+    wxUString( const wxScopedCharBuffer &buf )                        { assign(buf); }
     wxUString( const char *str, const wxMBConv &conv )          { assign(str,conv); }
-    wxUString( const wxCharBuffer &buf, const wxMBConv &conv )  { assign(buf,conv); }
+    wxUString( const wxScopedCharBuffer &buf, const wxMBConv &conv )  { assign(buf,conv); }
 
     wxUString( const wxChar16 *str )                            { assign(str); }
-    wxUString( const wxU16CharBuffer &buf )                     { assign(buf); }
+    wxUString( const wxScopedU16CharBuffer &buf )                     { assign(buf); }
 
     wxUString( const wxCStrData *cstr )                         { assign(cstr); }
     wxUString( const wxString &str )                            { assign(str); }
@@ -116,11 +120,11 @@ public:
 
     // conversions
 
-    wxCharBuffer utf8_str() const;
-    wxU16CharBuffer utf16_str() const;
+    wxScopedCharBuffer utf8_str() const;
+    wxScopedU16CharBuffer utf16_str() const;
 
 #if SIZEOF_WCHAR_T == 2
-    wxWCharBuffer wc_str() const
+    wxScopedWCharBuffer wc_str() const
     {
        return utf16_str();
     }
@@ -145,13 +149,13 @@ public:
     }
 
 #if wxUSE_UNICODE_UTF8
-    wxCharBuffer wx_str()
+    wxScopedCharBuffer wx_str()
     {
         return utf8_str();
     }
 #else
 #if SIZEOF_WCHAR_T == 2
-    wxWCharBuffer wx_str()
+    wxScopedWCharBuffer wx_str()
     {
         return utf16_str();
     }
@@ -201,7 +205,7 @@ public:
         return (wxUString &) base->assign( n, ch );
     }
 
-    wxUString &assign( const wxU32CharBuffer &buf )
+    wxUString &assign( const wxScopedU32CharBuffer &buf )
     {
         return assign( buf.data() );
     }
@@ -211,7 +215,7 @@ public:
         return assignFromCString( str );
     }
 
-    wxUString &assign( const wxCharBuffer &buf )
+    wxUString &assign( const wxScopedCharBuffer &buf )
     {
         return assignFromCString( buf.data() );
     }
@@ -221,7 +225,7 @@ public:
         return assignFromCString( str, conv );
     }
 
-    wxUString &assign( const wxCharBuffer &buf, const wxMBConv &conv )
+    wxUString &assign( const wxScopedCharBuffer &buf, const wxMBConv &conv )
     {
         return assignFromCString( buf.data(), conv );
     }
@@ -231,7 +235,7 @@ public:
         return assignFromUTF16( str );
     }
 
-    wxUString &assign( const wxU16CharBuffer &buf )
+    wxUString &assign( const wxScopedU16CharBuffer &buf )
     {
         return assignFromUTF16( buf.data() );
     }
@@ -360,12 +364,12 @@ public:
 
     // append [wx overload]
 
-    wxUString &append( const wxU16CharBuffer &buf )
+    wxUString &append( const wxScopedU16CharBuffer &buf )
     {
         return append( buf.data() );
     }
 
-    wxUString &append( const wxU32CharBuffer &buf )
+    wxUString &append( const wxScopedU32CharBuffer &buf )
     {
         return append( buf.data() );
     }
@@ -375,7 +379,7 @@ public:
         return append( wxUString( str ) );
     }
 
-    wxUString &append( const wxCharBuffer &buf )
+    wxUString &append( const wxScopedCharBuffer &buf )
     {
         return append( wxUString( buf ) );
     }
@@ -467,17 +471,17 @@ public:
         return insert( n, wxUString( s ) );
     }
 
-    wxUString &insert( size_type n, const wxCharBuffer &buf )
+    wxUString &insert( size_type n, const wxScopedCharBuffer &buf )
     {
         return insert( n, wxUString( buf ) );
     }
 
-    wxUString &insert( size_type n, const wxU16CharBuffer &buf )
+    wxUString &insert( size_type n, const wxScopedU16CharBuffer &buf )
     {
         return insert( n, wxUString( buf ) );
     }
 
-    wxUString &insert( size_type n, const wxU32CharBuffer &buf )
+    wxUString &insert( size_type n, const wxScopedU32CharBuffer &buf )
     {
         return insert( n, buf.data() );
     }
@@ -536,11 +540,11 @@ public:
         { return assign( s ); }
     wxUString& operator=(const wxChar32 *s)
         { return assign( s ); }
-    wxUString& operator=(const wxCharBuffer &s)
+    wxUString& operator=(const wxScopedCharBuffer &s)
         { return assign( s ); }
-    wxUString& operator=(const wxU16CharBuffer &s)
+    wxUString& operator=(const wxScopedU16CharBuffer &s)
         { return assign( s ); }
-    wxUString& operator=(const wxU32CharBuffer &s)
+    wxUString& operator=(const wxScopedU32CharBuffer &s)
         { return assign( s ); }
     wxUString& operator=(const char ch)
         { return assign( ch ); }
@@ -566,11 +570,11 @@ public:
         { return append( s ); }
     wxUString& operator+=(const wxChar32 *s)
         { return append( s ); }
-    wxUString& operator+=(const wxCharBuffer &s)
+    wxUString& operator+=(const wxScopedCharBuffer &s)
         { return append( s ); }
-    wxUString& operator+=(const wxU16CharBuffer &s)
+    wxUString& operator+=(const wxScopedU16CharBuffer &s)
         { return append( s ); }
-    wxUString& operator+=(const wxU32CharBuffer &s)
+    wxUString& operator+=(const wxScopedU32CharBuffer &s)
         { return append( s ); }
     wxUString& operator+=(const char ch)
         { return append( ch ); }
@@ -597,11 +601,11 @@ inline wxUString operator+(const wxUString &s1, const wxChar16* s2)
     { return s1 + wxUString(s2); }
 inline wxUString operator+(const wxUString &s1, const wxChar32 *s2)
     { return s1 + wxUString(s2); }
-inline wxUString operator+(const wxUString &s1, const wxCharBuffer &s2)
+inline wxUString operator+(const wxUString &s1, const wxScopedCharBuffer &s2)
     { return s1 + wxUString(s2); }
-inline wxUString operator+(const wxUString &s1, const wxU16CharBuffer &s2)
+inline wxUString operator+(const wxUString &s1, const wxScopedU16CharBuffer &s2)
     { return s1 + wxUString(s2); }
-inline wxUString operator+(const wxUString &s1, const wxU32CharBuffer &s2)
+inline wxUString operator+(const wxUString &s1, const wxScopedU32CharBuffer &s2)
     { return s1 + wxUString(s2); }
 inline wxUString operator+(const wxUString &s1, char s2)
     { return s1 + wxUString(s2); }
@@ -624,11 +628,11 @@ inline wxUString operator+(const wxChar16* s1, const wxUString &s2)
     { return wxUString(s1) + s2; }
 inline wxUString operator+(const wxChar32 *s1, const wxUString &s2)
     { return wxUString(s1) + s2; }
-inline wxUString operator+(const wxCharBuffer &s1, const wxUString &s2)
+inline wxUString operator+(const wxScopedCharBuffer &s1, const wxUString &s2)
     { return wxUString(s1) + s2; }
-inline wxUString operator+(const wxU16CharBuffer &s1, const wxUString &s2)
+inline wxUString operator+(const wxScopedU16CharBuffer &s1, const wxUString &s2)
     { return wxUString(s1) + s2; }
-inline wxUString operator+(const wxU32CharBuffer &s1, const wxUString &s2)
+inline wxUString operator+(const wxScopedU32CharBuffer &s1, const wxUString &s2)
     { return wxUString(s1) + s2; }
 inline wxUString operator+(char s1, const wxUString &s2)
     { return wxUString(s1) + s2; }
@@ -686,9 +690,9 @@ wxUSTRING_COMP_OPERATORS( const wxString & )
 wxUSTRING_COMP_OPERATORS( const char * )
 wxUSTRING_COMP_OPERATORS( const wxChar16 * )
 wxUSTRING_COMP_OPERATORS( const wxChar32 * )
-wxUSTRING_COMP_OPERATORS( const wxCharBuffer & )
-wxUSTRING_COMP_OPERATORS( const wxU16CharBuffer & )
-wxUSTRING_COMP_OPERATORS( const wxU32CharBuffer & )
+wxUSTRING_COMP_OPERATORS( const wxScopedCharBuffer & )
+wxUSTRING_COMP_OPERATORS( const wxScopedU16CharBuffer & )
+wxUSTRING_COMP_OPERATORS( const wxScopedU32CharBuffer & )
 wxUSTRING_COMP_OPERATORS( const wxCStrData * )
 
 #endif // _WX_USTRING_H_
index 6f6ad149c69687729ab3ea27a51a51902a7146b7..37927b4e1e588b924b26ecdd28ac5706fb0d2da4 100644 (file)
@@ -438,7 +438,7 @@ inline bool wxSetEnv(const wxString& var, const char *value)
 inline bool wxSetEnv(const wxString& var, const wchar_t *value)
     { return wxSetEnv(var, wxString(value)); }
 template<typename T>
-inline bool wxSetEnv(const wxString& var, const wxCharTypeBuffer<T>& value)
+inline bool wxSetEnv(const wxString& var, const wxScopedCharTypeBuffer<T>& value)
     { return wxSetEnv(var, wxString(value)); }
 inline bool wxSetEnv(const wxString& var, const wxCStrData& value)
     { return wxSetEnv(var, wxString(value)); }
index a491b6f2ad99a6563cd8279ab1b2145ee9da1831..73e675eaeff1b9dddb3279854dc9ac247b01e0ca 100644 (file)
@@ -210,8 +210,8 @@ public:
     wxVariant(const char* val, const wxString& name = wxEmptyString);
     wxVariant(const wchar_t* val, const wxString& name = wxEmptyString);
     wxVariant(const wxCStrData& val, const wxString& name = wxEmptyString);
-    wxVariant(const wxCharBuffer& val, const wxString& name = wxEmptyString);
-    wxVariant(const wxWCharBuffer& val, const wxString& name = wxEmptyString);
+    wxVariant(const wxScopedCharBuffer& val, const wxString& name = wxEmptyString);
+    wxVariant(const wxScopedWCharBuffer& val, const wxString& name = wxEmptyString);
 
     bool operator== (const wxString& value) const;
     bool operator!= (const wxString& value) const;
@@ -225,7 +225,7 @@ public:
     wxVariant& operator=(const wxCStrData& value)
         { return *this = value.AsString(); }
     template<typename T>
-    wxVariant& operator=(const wxCharTypeBuffer<T>& value)
+    wxVariant& operator=(const wxScopedCharTypeBuffer<T>& value)
         { return *this = value.data(); }
 
     inline operator wxString () const {  return MakeString(); }
index 8183944aed51b7a34fc2bbc7cc221e28fd89de38..5979cbfaf51fd135392c7f3d8dfe4a185fb61191 100644 (file)
@@ -30,8 +30,8 @@
 /* checks whether the passed in pointer is NULL and if the string is empty */
 inline bool wxIsEmpty(const char *s) { return !s || !*s; }
 inline bool wxIsEmpty(const wchar_t *s) { return !s || !*s; }
-inline bool wxIsEmpty(const wxCharBuffer& s) { return wxIsEmpty(s.data()); }
-inline bool wxIsEmpty(const wxWCharBuffer& s) { return wxIsEmpty(s.data()); }
+inline bool wxIsEmpty(const wxScopedCharBuffer& s) { return wxIsEmpty(s.data()); }
+inline bool wxIsEmpty(const wxScopedWCharBuffer& s) { return wxIsEmpty(s.data()); }
 inline bool wxIsEmpty(const wxString& s) { return s.empty(); }
 inline bool wxIsEmpty(const wxCStrData& s) { return s.AsString().empty(); }
 
@@ -158,7 +158,7 @@ inline char* wxTmemset(char* szOut, const char cIn, size_t len)
 //     wxSetlocale(category, NULL) -- which is a common thing to do -- would be
 //     ambiguous
 WXDLLIMPEXP_BASE char* wxSetlocale(int category, const char *locale);
-inline char* wxSetlocale(int category, const wxCharBuffer& locale)
+inline char* wxSetlocale(int category, const wxScopedCharBuffer& locale)
     { return wxSetlocale(category, locale.data()); }
 inline char* wxSetlocale(int category, const wxString& locale)
     { return wxSetlocale(category, locale.mb_str()); }
@@ -173,13 +173,13 @@ inline char* wxSetlocale(int category, const wxCStrData& locale)
 // NB: these are defined in wxcrtbase.h, see the comment there
 // inline size_t wxStrlen(const char *s) { return s ? strlen(s) : 0; }
 // inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_Strlen_(s) : 0; }
-inline size_t wxStrlen(const wxCharBuffer& s) { return wxStrlen(s.data()); }
-inline size_t wxStrlen(const wxWCharBuffer& s) { return wxStrlen(s.data()); }
+inline size_t wxStrlen(const wxScopedCharBuffer& s) { return wxStrlen(s.data()); }
+inline size_t wxStrlen(const wxScopedWCharBuffer& s) { return wxStrlen(s.data()); }
 inline size_t wxStrlen(const wxString& s) { return s.length(); }
 inline size_t wxStrlen(const wxCStrData& s) { return s.AsString().length(); }
 
 // this is a function new in 2.9 so we don't care about backwards compatibility and
-// so don't need to support wxCharBuffer/wxWCharBuffer overloads
+// so don't need to support wxScopedCharBuffer/wxScopedWCharBuffer overloads
 #if defined(wxCRT_StrnlenA)
 inline size_t wxStrnlen(const char *str, size_t maxlen) { return wxCRT_StrnlenA(str, maxlen); }
 #else
@@ -211,8 +211,8 @@ inline size_t wxStrnlen(const wchar_t *str, size_t maxlen)
 // NB: these are defined in wxcrtbase.h, see the comment there
 // inline char* wxStrdup(const char *s) { return wxStrdupA(s); }
 // inline wchar_t* wxStrdup(const wchar_t *s) { return wxStrdupW(s); }
-inline char* wxStrdup(const wxCharBuffer& s) { return wxStrdup(s.data()); }
-inline wchar_t* wxStrdup(const wxWCharBuffer& s) { return wxStrdup(s.data()); }
+inline char* wxStrdup(const wxScopedCharBuffer& s) { return wxStrdup(s.data()); }
+inline wchar_t* wxStrdup(const wxScopedWCharBuffer& s) { return wxStrdup(s.data()); }
 inline char* wxStrdup(const wxString& s) { return wxStrdup(s.mb_str()); }
 inline char* wxStrdup(const wxCStrData& s) { return wxStrdup(s.AsCharBuf()); }
 
@@ -224,13 +224,13 @@ inline char *wxStrcpy(char *dest, const wxString& src)
     { return wxCRT_StrcpyA(dest, src.mb_str()); }
 inline char *wxStrcpy(char *dest, const wxCStrData& src)
     { return wxCRT_StrcpyA(dest, src.AsCharBuf()); }
-inline char *wxStrcpy(char *dest, const wxCharBuffer& src)
+inline char *wxStrcpy(char *dest, const wxScopedCharBuffer& src)
     { return wxCRT_StrcpyA(dest, src.data()); }
 inline wchar_t *wxStrcpy(wchar_t *dest, const wxString& src)
     { return wxCRT_StrcpyW(dest, src.wc_str()); }
 inline wchar_t *wxStrcpy(wchar_t *dest, const wxCStrData& src)
     { return wxCRT_StrcpyW(dest, src.AsWCharBuf()); }
-inline wchar_t *wxStrcpy(wchar_t *dest, const wxWCharBuffer& src)
+inline wchar_t *wxStrcpy(wchar_t *dest, const wxScopedWCharBuffer& src)
     { return wxCRT_StrcpyW(dest, src.data()); }
 inline char *wxStrcpy(char *dest, const wchar_t *src)
     { return wxCRT_StrcpyA(dest, wxConvLibc.cWC2MB(src)); }
@@ -245,13 +245,13 @@ inline char *wxStrncpy(char *dest, const wxString& src, size_t n)
     { return wxCRT_StrncpyA(dest, src.mb_str(), n); }
 inline char *wxStrncpy(char *dest, const wxCStrData& src, size_t n)
     { return wxCRT_StrncpyA(dest, src.AsCharBuf(), n); }
-inline char *wxStrncpy(char *dest, const wxCharBuffer& src, size_t n)
+inline char *wxStrncpy(char *dest, const wxScopedCharBuffer& src, size_t n)
     { return wxCRT_StrncpyA(dest, src.data(), n); }
 inline wchar_t *wxStrncpy(wchar_t *dest, const wxString& src, size_t n)
     { return wxCRT_StrncpyW(dest, src.wc_str(), n); }
 inline wchar_t *wxStrncpy(wchar_t *dest, const wxCStrData& src, size_t n)
     { return wxCRT_StrncpyW(dest, src.AsWCharBuf(), n); }
-inline wchar_t *wxStrncpy(wchar_t *dest, const wxWCharBuffer& src, size_t n)
+inline wchar_t *wxStrncpy(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n)
     { return wxCRT_StrncpyW(dest, src.data(), n); }
 inline char *wxStrncpy(char *dest, const wchar_t *src, size_t n)
     { return wxCRT_StrncpyA(dest, wxConvLibc.cWC2MB(src), n); }
@@ -296,13 +296,13 @@ inline char *wxStrcat(char *dest, const wxString& src)
     { return wxCRT_StrcatA(dest, src.mb_str()); }
 inline char *wxStrcat(char *dest, const wxCStrData& src)
     { return wxCRT_StrcatA(dest, src.AsCharBuf()); }
-inline char *wxStrcat(char *dest, const wxCharBuffer& src)
+inline char *wxStrcat(char *dest, const wxScopedCharBuffer& src)
     { return wxCRT_StrcatA(dest, src.data()); }
 inline wchar_t *wxStrcat(wchar_t *dest, const wxString& src)
     { return wxCRT_StrcatW(dest, src.wc_str()); }
 inline wchar_t *wxStrcat(wchar_t *dest, const wxCStrData& src)
     { return wxCRT_StrcatW(dest, src.AsWCharBuf()); }
-inline wchar_t *wxStrcat(wchar_t *dest, const wxWCharBuffer& src)
+inline wchar_t *wxStrcat(wchar_t *dest, const wxScopedWCharBuffer& src)
     { return wxCRT_StrcatW(dest, src.data()); }
 inline char *wxStrcat(char *dest, const wchar_t *src)
     { return wxCRT_StrcatA(dest, wxConvLibc.cWC2MB(src)); }
@@ -317,13 +317,13 @@ inline char *wxStrncat(char *dest, const wxString& src, size_t n)
     { return wxCRT_StrncatA(dest, src.mb_str(), n); }
 inline char *wxStrncat(char *dest, const wxCStrData& src, size_t n)
     { return wxCRT_StrncatA(dest, src.AsCharBuf(), n); }
-inline char *wxStrncat(char *dest, const wxCharBuffer& src, size_t n)
+inline char *wxStrncat(char *dest, const wxScopedCharBuffer& src, size_t n)
     { return wxCRT_StrncatA(dest, src.data(), n); }
 inline wchar_t *wxStrncat(wchar_t *dest, const wxString& src, size_t n)
     { return wxCRT_StrncatW(dest, src.wc_str(), n); }
 inline wchar_t *wxStrncat(wchar_t *dest, const wxCStrData& src, size_t n)
     { return wxCRT_StrncatW(dest, src.AsWCharBuf(), n); }
-inline wchar_t *wxStrncat(wchar_t *dest, const wxWCharBuffer& src, size_t n)
+inline wchar_t *wxStrncat(wchar_t *dest, const wxScopedWCharBuffer& src, size_t n)
     { return wxCRT_StrncatW(dest, src.data(), n); }
 inline char *wxStrncat(char *dest, const wchar_t *src, size_t n)
     { return wxCRT_StrncatA(dest, wxConvLibc.cWC2MB(src), n); }
@@ -349,45 +349,45 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
         { return WX_STR_CALL(crtA, s1, s2); }                                 \
     inline rettype WX_STR_DECL(name, const char *, const wchar_t *)           \
         { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); }        \
-    inline rettype WX_STR_DECL(name, const char *, const wxCharBuffer&)       \
+    inline rettype WX_STR_DECL(name, const char *, const wxScopedCharBuffer&)       \
         { return WX_STR_CALL(crtA, s1, s2.data()); }                          \
-    inline rettype WX_STR_DECL(name, const char *, const wxWCharBuffer&)      \
+    inline rettype WX_STR_DECL(name, const char *, const wxScopedWCharBuffer&)      \
         { return WX_STR_CALL(forString, wxString(s1), s2.data()); }           \
                                                                               \
     inline rettype WX_STR_DECL(name, const wchar_t *, const wchar_t *)        \
         { return WX_STR_CALL(crtW, s1, s2); }                                 \
     inline rettype WX_STR_DECL(name, const wchar_t *, const char *)           \
         { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); }        \
-    inline rettype WX_STR_DECL(name, const wchar_t *, const wxWCharBuffer&)   \
+    inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedWCharBuffer&)   \
         { return WX_STR_CALL(crtW, s1, s2.data()); }                          \
-    inline rettype WX_STR_DECL(name, const wchar_t *, const wxCharBuffer&)    \
+    inline rettype WX_STR_DECL(name, const wchar_t *, const wxScopedCharBuffer&)    \
         { return WX_STR_CALL(forString, wxString(s1), s2.data()); }           \
                                                                               \
-    inline rettype WX_STR_DECL(name, const wxCharBuffer&, const char *)       \
+    inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const char *)       \
         { return WX_STR_CALL(crtA, s1.data(), s2); }                          \
-    inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wchar_t *)    \
+    inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wchar_t *)    \
         { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); }        \
-    inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCharBuffer&)\
+    inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedCharBuffer&)\
         { return WX_STR_CALL(crtA, s1.data(), s2.data()); }                   \
-    inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxWCharBuffer&)   \
+    inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxScopedWCharBuffer&)   \
         { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); }        \
                                                                               \
-    inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wchar_t *)   \
+    inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wchar_t *)   \
         { return WX_STR_CALL(crtW, s1.data(), s2); }                          \
-    inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const char *)      \
+    inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const char *)      \
         { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); }        \
-    inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxWCharBuffer&)  \
+    inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedWCharBuffer&)  \
         { return WX_STR_CALL(crtW, s1.data(), s2.data()); }                   \
-    inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCharBuffer&)   \
+    inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxScopedCharBuffer&)   \
         { return WX_STR_CALL(forString, wxString(s1), wxString(s2)); }        \
                                                                               \
     inline rettype WX_STR_DECL(name, const wxString&, const char*)            \
         { return WX_STR_CALL(forString, s1, s2); }                            \
     inline rettype WX_STR_DECL(name, const wxString&, const wchar_t*)         \
         { return WX_STR_CALL(forString, s1, s2); }                            \
-    inline rettype WX_STR_DECL(name, const wxString&, const wxCharBuffer&)    \
+    inline rettype WX_STR_DECL(name, const wxString&, const wxScopedCharBuffer&)    \
         { return WX_STR_CALL(forString, s1, s2); }                            \
-    inline rettype WX_STR_DECL(name, const wxString&, const wxWCharBuffer&)   \
+    inline rettype WX_STR_DECL(name, const wxString&, const wxScopedWCharBuffer&)   \
         { return WX_STR_CALL(forString, s1, s2); }                            \
     inline rettype WX_STR_DECL(name, const wxString&, const wxString&)        \
         { return WX_STR_CALL(forString, s1, s2); }                            \
@@ -398,9 +398,9 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
         { return WX_STR_CALL(forString, s1.AsString(), s2); }                 \
     inline rettype WX_STR_DECL(name, const wxCStrData&, const wchar_t*)       \
         { return WX_STR_CALL(forString, s1.AsString(), s2); }                 \
-    inline rettype WX_STR_DECL(name, const wxCStrData&, const wxCharBuffer&)  \
+    inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedCharBuffer&)  \
         { return WX_STR_CALL(forString, s1.AsString(), s2); }                 \
-    inline rettype WX_STR_DECL(name, const wxCStrData&, const wxWCharBuffer&) \
+    inline rettype WX_STR_DECL(name, const wxCStrData&, const wxScopedWCharBuffer&) \
         { return WX_STR_CALL(forString, s1.AsString(), s2); }                 \
     inline rettype WX_STR_DECL(name, const wxCStrData&, const wxString&)      \
         { return WX_STR_CALL(forString, s1.AsString(), s2); }                 \
@@ -422,14 +422,14 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
     inline int WX_STR_DECL(name, const wchar_t *, const wxString&)            \
         { return -WX_STR_CALL(forString, s2, s1); }                           \
                                                                               \
-    inline int WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&)      \
+    inline int WX_STR_DECL(name, const wxScopedCharBuffer&, const wxCStrData&)      \
         { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); }         \
-    inline int WX_STR_DECL(name, const wxCharBuffer&, const wxString&)        \
+    inline int WX_STR_DECL(name, const wxScopedCharBuffer&, const wxString&)        \
         { return -WX_STR_CALL(forString, s2, s1.data()); }                    \
                                                                               \
-    inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&)     \
+    inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&)     \
         { return -WX_STR_CALL(forString, s2.AsString(), s1.data()); }         \
-    inline int WX_STR_DECL(name, const wxWCharBuffer&, const wxString&)       \
+    inline int WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&)       \
         { return -WX_STR_CALL(forString, s2, s1.data()); }
 
 
@@ -449,14 +449,14 @@ inline wchar_t *wxStrncat(wchar_t *dest, const char *src, size_t n)
     inline rettype WX_STR_DECL(name, const wchar_t *, const wxString&)        \
         { return WX_STR_CALL(crtW, s1, s2.wc_str()); }                        \
                                                                               \
-    inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxCStrData&)  \
+    inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxCStrData&)  \
         { return WX_STR_CALL(crtA, s1.data(), s2.AsCharBuf()); }              \
-    inline rettype WX_STR_DECL(name, const wxCharBuffer&, const wxString&)    \
+    inline rettype WX_STR_DECL(name, const wxScopedCharBuffer&, const wxString&)    \
         { return WX_STR_CALL(crtA, s1.data(), s2.mb_str()); }                 \
                                                                               \
-    inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxCStrData&) \
+    inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxCStrData&) \
         { return WX_STR_CALL(crtW, s1.data(), s2.AsWCharBuf()); }             \
-    inline rettype WX_STR_DECL(name, const wxWCharBuffer&, const wxString&)   \
+    inline rettype WX_STR_DECL(name, const wxScopedWCharBuffer&, const wxString&)   \
         { return WX_STR_CALL(crtW, s1.data(), s2.wc_str()); }
 
 template<typename T>
@@ -490,7 +490,7 @@ inline int wxStrcoll_String(const wxString& s1, const T& s2)
     // NB: strcoll() doesn't work correctly on UTF-8 strings, so we have to use
     //     wc_str() even if wxUSE_UNICODE_UTF8; the (const wchar_t*) cast is
     //     there just as optimization to avoid going through
-    //     wxStrcoll<wxWCharBuffer>:
+    //     wxStrcoll<wxScopedWCharBuffer>:
     return wxStrcoll((const wchar_t*)s1.wc_str(), s2);
 #else
     return wxStrcoll((const char*)s1.mb_str(), s2);
@@ -548,7 +548,7 @@ inline size_t wxStrxfrm(char *dest, const char *src, size_t n)
 inline size_t wxStrxfrm(wchar_t *dest, const wchar_t *src, size_t n)
     { return wxCRT_StrxfrmW(dest, src, n); }
 template<typename T>
-inline size_t wxStrxfrm(T *dest, const wxCharTypeBuffer<T>& src, size_t n)
+inline size_t wxStrxfrm(T *dest, const wxScopedCharTypeBuffer<T>& src, size_t n)
     { return wxStrxfrm(dest, src.data(), n); }
 inline size_t wxStrxfrm(char *dest, const wxString& src, size_t n)
     { return wxCRT_StrxfrmA(dest, src.mb_str(), n); }
@@ -566,7 +566,7 @@ inline char *wxStrtok(char *str, const char *delim, char **saveptr)
 inline wchar_t *wxStrtok(wchar_t *str, const wchar_t *delim, wchar_t **saveptr)
     { return wxCRT_StrtokW(str, delim, saveptr); }
 template<typename T>
-inline T *wxStrtok(T *str, const wxCharTypeBuffer<T>& delim, T **saveptr)
+inline T *wxStrtok(T *str, const wxScopedCharTypeBuffer<T>& delim, T **saveptr)
     { return wxStrtok(str, delim.data(), saveptr); }
 inline char *wxStrtok(char *str, const wxCStrData& delim, char **saveptr)
     { return wxCRT_StrtokA(str, delim.AsCharBuf(), saveptr); }
@@ -628,22 +628,22 @@ inline const char *wxStrrchr(const char *s, const wxUniCharRef& c)
 inline const wchar_t *wxStrrchr(const wchar_t *s, const wxUniCharRef& c)
     { return wxCRT_StrrchrW(s, (wchar_t)c); }
 template<typename T>
-inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, T c)
+inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, T c)
     { return wxStrchr(s.data(), c); }
 template<typename T>
-inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, T c)
+inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, T c)
     { return wxStrrchr(s.data(), c); }
 template<typename T>
-inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
+inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniChar& c)
     { return wxStrchr(s.data(), (T)c); }
 template<typename T>
-inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniChar& c)
+inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniChar& c)
     { return wxStrrchr(s.data(), (T)c); }
 template<typename T>
-inline const T* wxStrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
+inline const T* wxStrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniCharRef& c)
     { return wxStrchr(s.data(), (T)c); }
 template<typename T>
-inline const T* wxStrrchr(const wxCharTypeBuffer<T>& s, const wxUniCharRef& c)
+inline const T* wxStrrchr(const wxScopedCharTypeBuffer<T>& s, const wxUniCharRef& c)
     { return wxStrrchr(s.data(), (T)c); }
 // these functions return char* pointer into the non-temporary conversion buffer
 // used by c_str()'s implicit conversion to char*, for ANSI build compatibility
@@ -717,7 +717,7 @@ inline const wchar_t *wxStrpbrk(const wxCStrData& s, const wchar_t *accept)
 inline const char *wxStrpbrk(const wxCStrData& s, const wxCStrData& accept)
     { return wxCRT_StrpbrkA(s.AsChar(), accept.AsCharBuf()); }
 template <typename S, typename T>
-inline const T *wxStrpbrk(const S& s, const wxCharTypeBuffer<T>& accept)
+inline const T *wxStrpbrk(const S& s, const wxScopedCharTypeBuffer<T>& accept)
     { return wxStrpbrk(s, accept.data()); }
 
 
@@ -820,7 +820,7 @@ inline double wxStrtod(const char *nptr, char **endptr)
 inline double wxStrtod(const wchar_t *nptr, wchar_t **endptr)
     { return wxCRT_StrtodW(nptr, endptr); }
 template<typename T>
-inline double wxStrtod(const wxCharTypeBuffer<T>& nptr, T **endptr)
+inline double wxStrtod(const wxScopedCharTypeBuffer<T>& nptr, T **endptr)
     { return wxStrtod(nptr.data(), endptr); }
 
 // We implement wxStrto*() like this so that the code compiles when NULL is
@@ -884,7 +884,7 @@ inline double wxStrtod(const wxCStrData& nptr, T endptr)
     inline rettype name(const wchar_t *nptr, wchar_t **endptr, int base)      \
         { return implW(nptr, endptr, base); }                                 \
     template<typename T>                                                      \
-    inline rettype name(const wxCharTypeBuffer<T>& nptr, T **endptr, int base)\
+    inline rettype name(const wxScopedCharTypeBuffer<T>& nptr, T **endptr, int base)\
         { return name(nptr.data(), endptr); }                                 \
     template<typename T>                                                      \
     inline rettype name(const wxString& nptr, T endptr, int base)             \
@@ -930,8 +930,8 @@ inline char* wxGetenv(const char *name) { return wxCRT_GetenvA(name); }
 inline wchar_t* wxGetenv(const wchar_t *name) { return wxCRT_GetenvW(name); }
 inline char* wxGetenv(const wxString& name) { return wxCRT_GetenvA(name.mb_str()); }
 inline char* wxGetenv(const wxCStrData& name) { return wxCRT_GetenvA(name.AsCharBuf()); }
-inline char* wxGetenv(const wxCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
-inline wchar_t* wxGetenv(const wxWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
+inline char* wxGetenv(const wxScopedCharBuffer& name) { return wxCRT_GetenvA(name.data()); }
+inline wchar_t* wxGetenv(const wxScopedWCharBuffer& name) { return wxCRT_GetenvW(name.data()); }
 
 // ----------------------------------------------------------------------------
 //                            time.h functions
index 1f6343c88d14a69d7b1d0d48e299cd62f7bc569d..e454f6c703620c7d9773ce0957b877f668808cf8 100644 (file)
@@ -445,7 +445,7 @@ wxVsnprintf(wchar_t *str, size_t size, const wxString& format, va_list argptr);
 #ifdef __WINDOWS__
     #define wxScanfConvertFormatW(fmt) fmt
 #else
-    const wxWCharBuffer
+    const wxScopedWCharBuffer
     WXDLLIMPEXP_BASE wxScanfConvertFormatW(const wchar_t *format);
 #endif
 
@@ -463,9 +463,9 @@ WX_DEFINE_SCANFUNC(wxSscanf, 2, (const char *str, const char *format),
                    wxCRT_SscanfA, (str, format))
 WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wchar_t *str, const wchar_t *format),
                    wxCRT_SscanfW, (str, wxScanfConvertFormatW(format)))
-WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxCharBuffer& str, const char *format),
+WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxScopedCharBuffer& str, const char *format),
                    wxCRT_SscanfA, (str.data(), format))
-WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxWCharBuffer& str, const wchar_t *format),
+WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxScopedWCharBuffer& str, const wchar_t *format),
                    wxCRT_SscanfW, (str.data(), wxScanfConvertFormatW(format)))
 WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxString& str, const char *format),
                    wxCRT_SscanfA, (str.mb_str(), format))
@@ -480,8 +480,8 @@ WX_DEFINE_SCANFUNC(wxSscanf, 2, (const wxCStrData& str, const wchar_t *format),
 #ifndef __VISUALC___
 int WXDLLIMPEXP_BASE wxVsscanf(const char *str, const char *format, va_list ap);
 int WXDLLIMPEXP_BASE wxVsscanf(const wchar_t *str, const wchar_t *format, va_list ap);
-int WXDLLIMPEXP_BASE wxVsscanf(const wxCharBuffer& str, const char *format, va_list ap);
-int WXDLLIMPEXP_BASE wxVsscanf(const wxWCharBuffer& str, const wchar_t *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxScopedCharBuffer& str, const char *format, va_list ap);
+int WXDLLIMPEXP_BASE wxVsscanf(const wxScopedWCharBuffer& str, const wchar_t *format, va_list ap);
 int WXDLLIMPEXP_BASE wxVsscanf(const wxString& str, const char *format, va_list ap);
 int WXDLLIMPEXP_BASE wxVsscanf(const wxString& str, const wchar_t *format, va_list ap);
 int WXDLLIMPEXP_BASE wxVsscanf(const wxCStrData& str, const char *format, va_list ap);
index d8766639b0b3e9affdf68bd698563f06764dfce3..bb14bb1ab26dcfeb3ee1d20fd8222d962caf7317 100644 (file)
 
 
 /**
-    wxCharTypeBuffer<T> is a template class for storing characters.
+    wxScopedCharTypeBuffer<T> is a template class for storing characters.
+
+    Data are stored in reference-counted buffer. In other words, making a copy
+    of wxScopedCharTypeBuffer<T> will @em not make another copy of the stored
+    string data, it will still point to the same location in memory.
+
+    wxScopedCharTypeBuffer<T> supports two storage modes: owned and non-owned.
+    "Owned" data buffer (created with CreateOwned() or wxCharTypeBuffer<T>
+    derived class) owns the data and frees them when the last buffer pointing
+    to them is destroyed.
+
+    "Non-owned" buffer (created with CreateNonOwned()), on the other hand,
+    references data owned by somebody else -- typical use is by
+    wxString::mb_str() or wxString::wc_str(), which may return non-owned buffer
+    pointing to wxString's internal store.
+
+    Because of this, the validity of data stored in wxScopedCharTypeBuffer<T>
+    is limited by the lifetime of the "parent" object that created the
+    buffer (e.g. the wxString on which mb_str() was called).
 
-    @todo provide better docs for this class
+    If you need to preserve the data for longer, assign it to
+    wxCharTypeBuffer<T> instead of wxScopedCharTypeBuffer<T>. On the other
+    hand, use wxScopedCharTypeBuffer<T> if the buffer is to be destroyed before
+    the "parent" object -- typical use would be creating it on the stack and
+    destroying when it goes out of scope (hence the class' name).
 
     @tparam T
         The type of the characters stored in this class.
 
+    @since 2.9.0
+
     @nolibrary
     @category{data}
 */
 template <typename T>
-class wxCharTypeBuffer
+class wxScopedCharTypeBuffer
 {
 public:
+    /// Stored characters type.
     typedef T CharType;
 
+    /// Default constructor, creates NULL buffer.
+    wxScopedCharTypeBuffer();
+
+    /**
+        Creates non-owned buffer from string data @a str.
+
+        The buffer's destructor will not destroy @a str. The returned buffer's
+        data is valid only as long as @a str is valid.
+     */
+    static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str);
+
+    /**
+        Creates owned buffer from @a str and takes ownership of it.
+
+        The buffer's destructor will free @a str when its reference count
+        reaches zero (initial count is 1).
+     */
+    static const wxScopedCharTypeBuffer CreateOwned(const CharType *str);
+
+    /**
+        Copy constructor.
+
+        Increases reference count on the data, does @em not make wxStrdup()
+        copy of the data.
+     */
+    wxScopedCharTypeBuffer(const wxScopedCharTypeBuffer& src);
+
+    /// Assignment operator behaves in the same way as the copy constructor.
+    wxScopedCharTypeBuffer& operator=(const wxScopedCharTypeBuffer& src);
+
+    /**
+        Destructor. Frees stored data if it is in "owned" mode and data's
+        reference count reaches zero.
+     */
+    ~wxScopedCharTypeBuffer();
+
+    /// Resets the buffer to NULL, freeing the data if necessary.
+    void reset();
+
+    /// Returns pointer to the stored data.
+    CharType *data();
+
+    /// Returns const pointer to the stored data.
+    const CharType *data() const;
+
+    /// Implicit conversion to C string.
+    operator const CharType *() const;
+
+    /// Random access to the stored C string.
+    CharType operator[](size_t n) const;
+};
+
+/// Scoped char buffer.
+typedef wxScopedCharTypeBuffer<char> wxScopedCharBuffer;
+
+/// Scoped wchar_t buffer.
+typedef wxScopedCharTypeBuffer<wchar_t> wxScopedWCharBuffer;
+
+/**
+    wxCharTypeBuffer<T> is a template class for storing characters.
+
+    The difference from wxScopedCharTypeBuffer<T> is that this class
+    doesn't have non-owned mode and the data stored in it are valid for
+    as long as the buffer instance exists. Other than that, this class'
+    behaviour is the same as wxScopedCharTypeBuffer<T>'s -- in particular,
+    the data are reference-counted and copying the buffer is cheap.
+
+    wxScopedCharTypeBuffer<T> buffers can be converted into wxCharTypeBuffer<T>.
+
+    @tparam T
+        The type of the characters stored in this class.
+
+    @since 2.9.0
+
+    @nolibrary
+    @category{data}
+*/
+template <typename T>
+class wxCharTypeBuffer : public wxScopedCharTypeBuffer<T>
+{
+public:
+    /**
+        Creates (owned) buffer from @a str and takes ownership of it.
+
+        @see wxScopedCharTypeBuffer<T>::CreateOwned()
+     */
     wxCharTypeBuffer(const CharType *str = NULL);
+
+
+    /**
+        Creates (owned) buffer of size @a len.
+
+        @see wxScopedCharTypeBuffer<T>::CreateOwned()
+     */
     wxCharTypeBuffer(size_t len);
+
+    /**
+        Copy constructor.
+
+        Increases reference count on the data, does @em not make wxStrdup()
+        copy of the data.
+     */
     wxCharTypeBuffer(const wxCharTypeBuffer& src);
-    ~wxCharTypeBuffer();
 
-    void reset();
+    /**
+        Makes a copy of scoped buffer @a src.
+
+        If @a src is a non-owned buffer, a copy of its data is made using
+        wxStrdup(). If @a src is an owned buffer, this constructor behaves
+        in the usual way (reference count on buffer data is incremented).
+     */
+    wxCharTypeBuffer(const wxScopedCharTypeBuffer<T>& src);
 
+    /**
+        Assigns @a str to this buffer and takes ownership of it (i.e. the
+        buffer becomes "owned").
+     */
     wxCharTypeBuffer& operator=(const CharType *str);
+
+    /// Assignment operator behaves in the same way as the copy constructor.
     wxCharTypeBuffer& operator=(const wxCharTypeBuffer& src);
 
-    bool extend(size_t len);
+    /**
+        Assigns a scoped buffer to this buffer.
 
-    CharType *data();
-    const CharType *data() const;
-    operator const CharType *() const;
-    CharType operator[](size_t n) const;
+        If @a src is a non-owned buffer, a copy of its data is made using
+        wxStrdup(). If @a src is an owned buffer, the assignment behaves
+        in the usual way (reference count on buffer data is incremented).
+     */
+    wxCharTypeBuffer& operator=(const wxScopedCharTypeBuffer<T>& src);
+
+    /**
+        Extends the buffer to have size @a len.
+
+        Can only be called on buffers that don't share data with another
+        buffer (i.e. reference count of the data is 1).
+     */
+    bool extend(size_t len);
 };
 
 /**
     This is a specialization of wxCharTypeBuffer<T> for @c char type.
 
-    @todo provide better docs for this class
-
     @nolibrary
     @category{data}
 */
@@ -54,8 +199,10 @@ class wxCharBuffer : public wxCharTypeBuffer<char>
 {
 public:
     typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
+    typedef wxScopedCharTypeBuffer<char> wxScopedCharTypeBufferBase;
 
     wxCharBuffer(const wxCharTypeBufferBase& buf);
+    wxCharBuffer(const wxScopedCharTypeBufferBase& buf);
     wxCharBuffer(const CharType *str = NULL);
     wxCharBuffer(size_t len);
     wxCharBuffer(const wxCStrData& cstr);
@@ -63,7 +210,6 @@ public:
 
 /**
     This is a specialization of wxCharTypeBuffer<T> for @c wchar_t type.
-    This class is available only when <tt>wxUSE_WCHAR_T==1</tt>
 
     @nolibrary
     @category{data}
@@ -72,8 +218,10 @@ class wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
 {
 public:
     typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
+    typedef wxScopedCharTypeBuffer<wchar_t> wxScopedCharTypeBufferBase;
 
     wxWCharBuffer(const wxCharTypeBufferBase& buf);
+    wxWCharBuffer(const wxScopedCharTypeBufferBase& buf);
     wxWCharBuffer(const CharType *str = NULL);
     wxWCharBuffer(size_t len);
     wxWCharBuffer(const wxCStrData& cstr);
index f3d684f1a468832e6f2d3cf91513e45a828e46c1..960b6d2d35f2ea044e75c6c4dfe9eab0b88788cd 100644 (file)
@@ -182,7 +182,7 @@ static wxStrCacheStatsDumper s_showCacheStats;
 wxSTD ostream& operator<<(wxSTD ostream& os, const wxCStrData& str)
 {
 #if wxUSE_UNICODE && !wxUSE_UNICODE_UTF8
-    const wxCharBuffer buf(str.AsCharBuf());
+    const wxScopedCharBuffer buf(str.AsCharBuf());
     if ( !buf )
         os.clear(wxSTD ios_base::failbit);
     else
@@ -199,13 +199,13 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str)
     return os << str.c_str();
 }
 
-wxSTD ostream& operator<<(wxSTD ostream& os, const wxCharBuffer& str)
+wxSTD ostream& operator<<(wxSTD ostream& os, const wxScopedCharBuffer& str)
 {
     return os << str.data();
 }
 
 #ifndef __BORLANDC__
-wxSTD ostream& operator<<(wxSTD ostream& os, const wxWCharBuffer& str)
+wxSTD ostream& operator<<(wxSTD ostream& os, const wxScopedWCharBuffer& str)
 {
     return os << str.data();
 }
@@ -223,7 +223,7 @@ wxSTD wostream& operator<<(wxSTD wostream& wos, const wxCStrData& str)
     return wos << str.AsWChar();
 }
 
-wxSTD wostream& operator<<(wxSTD wostream& wos, const wxWCharBuffer& str)
+wxSTD wostream& operator<<(wxSTD wostream& wos, const wxScopedWCharBuffer& str)
 {
     return wos << str.data();
 }
@@ -395,7 +395,7 @@ const char* wxCStrData::AsChar() const
     //             adding more fields to wxString and require profiling results
     //             to be sure that we really gain enough from them to justify
     //             doing it.
-    wxCharBuffer buf(str->mb_str());
+    wxScopedCharBuffer buf(str->mb_str());
 
     // if it failed, return empty string and not NULL to avoid crashes in code
     // written with either wxWidgets 2 wxString or std::string behaviour in
@@ -426,7 +426,7 @@ const wchar_t* wxCStrData::AsWChar() const
     wxString *str = wxConstCast(m_str, wxString);
 
     // convert the string:
-    wxWCharBuffer buf(str->wc_str());
+    wxScopedWCharBuffer buf(str->wc_str());
 
     // notice that here, unlike above in AsChar(), conversion can't fail as our
     // internal UTF-8 is always well-formed -- or the string was corrupted and
@@ -465,15 +465,15 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
 {
     // anything to do?
     if ( !psz || nLength == 0 )
-        return SubstrBufFromMB(L"", 0);
+        return SubstrBufFromMB(wxWCharBuffer(L""), 0);
 
     if ( nLength == npos )
         nLength = wxNO_LEN;
 
     size_t wcLen;
-    wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
+    wxScopedWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
     if ( !wcLen )
-        return SubstrBufFromMB(_T(""), 0);
+        return SubstrBufFromMB(wxWCharBuffer(L""), 0);
     else
         return SubstrBufFromMB(wcBuf, wcLen);
 }
@@ -486,7 +486,7 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
 {
     // anything to do?
     if ( !psz || nLength == 0 )
-        return SubstrBufFromMB("", 0);
+        return SubstrBufFromMB(wxCharBuffer(""), 0);
 
     // if psz is already in UTF-8, we don't have to do the roundtrip to
     // wchar_t* and back:
@@ -509,9 +509,9 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
 
     // first convert to wide string:
     size_t wcLen;
-    wxWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
+    wxScopedWCharBuffer wcBuf(conv.cMB2WC(psz, nLength, &wcLen));
     if ( !wcLen )
-        return SubstrBufFromMB("", 0);
+        return SubstrBufFromMB(wxCharBuffer(""), 0);
 
     // and then to UTF-8:
     SubstrBufFromMB buf(ConvertStr(wcBuf, wcLen, wxMBConvStrictUTF8()));
@@ -529,15 +529,15 @@ wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLengt
 {
     // anything to do?
     if ( !pwz || nLength == 0 )
-        return SubstrBufFromWC("", 0);
+        return SubstrBufFromWC(wxCharBuffer(""), 0);
 
     if ( nLength == npos )
         nLength = wxNO_LEN;
 
     size_t mbLen;
-    wxCharBuffer mbBuf(conv.cWC2MB(pwz, nLength, &mbLen));
+    wxScopedCharBuffer mbBuf(conv.cWC2MB(pwz, nLength, &mbLen));
     if ( !mbLen )
-        return SubstrBufFromWC("", 0);
+        return SubstrBufFromWC(wxCharBuffer(""), 0);
     else
         return SubstrBufFromWC(mbBuf, mbLen);
 }
@@ -547,14 +547,14 @@ wxString::SubstrBufFromWC wxString::ConvertStr(const wchar_t *pwz, size_t nLengt
 #if wxUSE_UNICODE_WCHAR
 
 //Convert wxString in Unicode mode to a multi-byte string
-const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
+const wxScopedCharBuffer wxString::mb_str(const wxMBConv& conv) const
 {
     return conv.cWC2MB(wx_str(), length() + 1 /* size, not length */, NULL);
 }
 
 #elif wxUSE_UNICODE_UTF8
 
-const wxWCharBuffer wxString::wc_str() const
+const wxScopedWCharBuffer wxString::wc_str() const
 {
     return wxMBConvStrictUTF8().cMB2WC
                                 (
@@ -564,20 +564,23 @@ const wxWCharBuffer wxString::wc_str() const
                                 );
 }
 
-const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
+const wxScopedCharBuffer wxString::mb_str(const wxMBConv& conv) const
 {
     if ( conv.IsUTF8() )
-        return wxCharBuffer::CreateNonOwned(m_impl.c_str());
+        return wxScopedCharBuffer::CreateNonOwned(m_impl.c_str());
 
     // FIXME-UTF8: use wc_str() here once we have buffers with length
 
     size_t wcLen;
-    wxWCharBuffer wcBuf(wxMBConvStrictUTF8().cMB2WC
-                                             (
-                                                m_impl.c_str(),
-                                                m_impl.length() + 1, // size
-                                                &wcLen
-                                             ));
+    wxScopedWCharBuffer wcBuf
+                        (
+                          wxMBConvStrictUTF8().cMB2WC
+                                               (
+                                                 m_impl.c_str(),
+                                                 m_impl.length() + 1, // size
+                                                 &wcLen
+                                               )
+                        );
     if ( !wcLen )
         return wxCharBuffer("");
 
@@ -588,7 +591,7 @@ const wxCharBuffer wxString::mb_str(const wxMBConv& conv) const
 
 //Converts this string to a wide character string if unicode
 //mode is not enabled and wxUSE_WCHAR_T is enabled
-const wxWCharBuffer wxString::wc_str(const wxMBConv& conv) const
+const wxScopedWCharBuffer wxString::wc_str(const wxMBConv& conv) const
 {
     return conv.cMB2WC(wx_str(), length() + 1 /* size, not length */, NULL);
 }
@@ -1196,7 +1199,7 @@ wxString wxString::FromAscii(char ascii)
     return wxString(wxUniChar((wchar_t)c));
 }
 
-const wxCharBuffer wxString::ToAscii() const
+const wxScopedCharBuffer wxString::ToAscii() const
 {
     // this will allocate enough space for the terminating NUL too
     wxCharBuffer buffer(length());
@@ -2085,8 +2088,8 @@ bool wxString::Matches(const wxString& mask) const
 
   // FIXME-UTF8: implement using iterators, remove #if
 #if wxUSE_UNICODE_UTF8
-  wxWCharBuffer maskBuf = mask.wc_str();
-  wxWCharBuffer txtBuf = wc_str();
+  const wxScopedWCharBuffer maskBuf = mask.wc_str();
+  const wxScopedWCharBuffer txtBuf = wc_str();
   const wxChar *pszMask = maskBuf.data();
   const wxChar *pszTxt = txtBuf.data();
 #else
index a10cdc26dd39bca1e679895149994eb783930abe..32775972bd5b2c570709d6778ef54058a87e0673 100644 (file)
@@ -520,7 +520,7 @@ class wxScanfFormatConverterWchar : public wxFormatConverterBase<wchar_t>
     }
 };
 
-const wxWCharBuffer wxScanfConvertFormatW(const wchar_t *format)
+const wxScopedWCharBuffer wxScanfConvertFormatW(const wchar_t *format)
 {
     return wxScanfFormatConverterWchar().Convert(format);
 }
index f198c386eaf66cd0d7b5412f3d298a26700ed23d..1da0c9256a5a63334941179f76256cf1f2d5722e 100644 (file)
@@ -399,7 +399,7 @@ wxUString &wxUString::assignFromCString( const char* str )
     if (!str)
         return assign( wxUString() );
 
-    wxWCharBuffer buffer = wxConvLibc.cMB2WC( str );
+    wxScopedWCharBuffer buffer = wxConvLibc.cMB2WC( str );
 
     return assign( buffer );
 }
@@ -409,12 +409,12 @@ wxUString &wxUString::assignFromCString( const char* str, const wxMBConv &conv )
     if (!str)
         return assign( wxUString() );
 
-    wxWCharBuffer buffer = conv.cMB2WC( str );
+    wxScopedWCharBuffer buffer = conv.cMB2WC( str );
 
     return assign( buffer );
 }
 
-wxCharBuffer wxUString::utf8_str() const
+wxScopedCharBuffer wxUString::utf8_str() const
 {
     size_type utf8_length = 0;
     const wxChar32 *ptr = data();
@@ -491,7 +491,7 @@ wxCharBuffer wxUString::utf8_str() const
     return result;
 }
 
-wxU16CharBuffer wxUString::utf16_str() const
+wxScopedU16CharBuffer wxUString::utf16_str() const
 {
     size_type utf16_length = 0;
     const wxChar32 *ptr = data();
index b7c479588dc4dcfef200ac10230782f14f014ce1..661a6190e51e4649657f97507198d3869629fcb1 100644 (file)
@@ -908,13 +908,13 @@ wxVariant::wxVariant(const wxCStrData& val, const wxString& name)
     m_name = name;
 }
 
-wxVariant::wxVariant(const wxCharBuffer& val, const wxString& name)
+wxVariant::wxVariant(const wxScopedCharBuffer& val, const wxString& name)
 {
     m_data = new wxVariantDataString(wxString(val));
     m_name = name;
 }
 
-wxVariant::wxVariant(const wxWCharBuffer& val, const wxString& name)
+wxVariant::wxVariant(const wxScopedWCharBuffer& val, const wxString& name)
 {
     m_data = new wxVariantDataString(wxString(val));
     m_name = name;
index b29747338ade7436b10072d2cd4b1c62f2171de1..ffeeac6d92d8ee98d7ad4b845bfa82a84f4263c9 100644 (file)
@@ -61,6 +61,7 @@ private:
         CPPUNIT_TEST( ExplicitConversion );
         CPPUNIT_TEST( IndexedAccess );
         CPPUNIT_TEST( BeforeAndAfter );
+        CPPUNIT_TEST( ScopedBuffers );
     CPPUNIT_TEST_SUITE_END();
 
     void String();
@@ -93,6 +94,7 @@ private:
     void ExplicitConversion();
     void IndexedAccess();
     void BeforeAndAfter();
+    void ScopedBuffers();
 
     DECLARE_NO_COPY_CLASS(StringTestCase)
 };
@@ -924,3 +926,26 @@ void StringTestCase::BeforeAndAfter()
     CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterLast(';') );
 }
 
+void StringTestCase::ScopedBuffers()
+{
+    // wxString relies on efficient buffers, verify they work as they should
+
+    const char *literal = "Hello World!";
+
+    // non-owned buffer points to the string passed to it
+    wxScopedCharBuffer sbuf = wxScopedCharBuffer::CreateNonOwned(literal);
+    CPPUNIT_ASSERT( sbuf.data() == literal );
+
+    // a copy of scoped non-owned buffer still points to the same string
+    wxScopedCharBuffer sbuf2(sbuf);
+    CPPUNIT_ASSERT( sbuf.data() == sbuf2.data() );
+
+    // but assigning it to wxCharBuffer makes a full copy
+    wxCharBuffer buf(sbuf);
+    CPPUNIT_ASSERT( buf.data() != literal );
+    CPPUNIT_ASSERT_EQUAL( literal, buf.data() );
+
+    wxCharBuffer buf2 = sbuf;
+    CPPUNIT_ASSERT( buf2.data() != literal );
+    CPPUNIT_ASSERT_EQUAL( literal, buf2.data() );
+}