From: Mattia Barbon Date: Fri, 18 Jul 2003 20:08:47 +0000 (+0000) Subject: Added wxStringBufferLength: works like wxStringBuffer, except X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/941b78cc1da712afca54adb29bb6c04d6ba9b295 Added wxStringBufferLength: works like wxStringBuffer, except it calls UngetWriteBuffer(size_t) instead of UngetWriteBuffer(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22094 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/string.h b/include/wx/string.h index 21aa8d6034..1bf5e9d1f8 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -1031,6 +1031,62 @@ public: // wxStringBuffer: a tiny class allowing to get a writable pointer into string // ---------------------------------------------------------------------------- +#if wxUSE_STL + +class WXDLLIMPEXP_BASE wxStringBuffer +{ +public: + wxStringBuffer(wxString& str, size_t lenWanted = 1024) + : m_str(str), m_buf(lenWanted), m_len(lenWanted) + { } + + ~wxStringBuffer() { m_str.assign(m_buf.data(), m_len); } + + operator wxChar*() { return m_buf.data(); } + +private: + wxString& m_str; +#if wxUSE_UNICODE + wxWCharBuffer m_buf; +#else + wxCharBuffer m_buf; +#endif + size_t m_len; + + DECLARE_NO_COPY_CLASS(wxStringBuffer) +}; + +class WXDLLIMPEXP_BASE wxStringBufferLength +{ +public: + wxStringBufferLength(wxString& str, size_t lenWanted = 1024) + : m_str(str), m_buf(lenWanted), m_len(0), m_lenSet(false) + { } + + ~wxStringBufferLength() + { + wxASSERT(m_lenSet); + m_str.assign(m_buf.data(), m_len); + } + + operator wxChar*() { return m_buf.data(); } + void SetLength(size_t length) { m_len = length; m_lenSet = true; } + +private: + wxString& m_str; +#if wxUSE_UNICODE + wxWCharBuffer m_buf; +#else + wxCharBuffer m_buf; +#endif + size_t m_len; + bool m_lenSet; + + DECLARE_NO_COPY_CLASS(wxStringBufferLength) +}; + +#else // if !wxUSE_STL + class WXDLLIMPEXP_BASE wxStringBuffer { public: @@ -1049,6 +1105,33 @@ private: DECLARE_NO_COPY_CLASS(wxStringBuffer) }; +class WXDLLIMPEXP_BASE wxStringBufferLength +{ +public: + wxStringBufferLength(wxString& str, size_t lenWanted = 1024) + : m_str(str), m_buf(NULL), m_len(0), m_lenSet(false) + { m_buf = m_str.GetWriteBuf(lenWanted); } + + ~wxStringBufferLength() + { + wxASSERT(m_lenSet); + m_str.UngetWriteBuf(m_len); + } + + operator wxChar*() const { return m_buf; } + void SetLength(size_t length) { m_len = length; m_lenSet = true; } + +private: + wxString& m_str; + wxChar *m_buf; + size_t m_len; + bool m_lenSet; + + DECLARE_NO_COPY_CLASS(wxStringBufferLength) +}; + +#endif // !wxUSE_STL + // --------------------------------------------------------------------------- // wxString comparison functions: operator versions are always case sensitive // ---------------------------------------------------------------------------