]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxStringBuffer helper
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 1 Dec 2001 17:16:16 +0000 (17:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 1 Dec 2001 17:16:16 +0000 (17:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12804 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/wxstring.tex
include/wx/string.h

index 9b1f85ca85fa2c336f0e1076e58187395f3a4d8b..7ad9ea73add37ce87517e3aed45932d1529335ff 100644 (file)
@@ -1116,3 +1116,57 @@ Implicit conversion to a C string.
 
 These comparisons are case-sensitive.
 
+
+\section{\class{wxStringBuffer}}\label{wxstringbuffer}
+
+This tiny class allows to conveniently access the \helpref{wxString}{wxstring} 
+internal buffer as a writable pointer without any risk to forget to restore
+the string to the usable state later.
+
+For example, assuming you have a low-level OS function called 
+{\tt GetMeaningOfLifeAsString(char *)} returning the value in the provided
+buffer (which must be writable, of course) you might call it like this:
+
+\begin{verbatim}
+    wxString theAnswer;
+    GetMeaningOfLifeAsString(wxStringBuffer(theAnswer, 1024));
+    if ( theAnswer != "42" )
+    {
+        wxLogError("Something is very wrong!");
+    }
+\end{verbatim}
+
+\wxheading{Derived from}
+
+None
+
+\wxheading{Include files}
+
+<wx/string.h>
+
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+\membersection{wxStringBuffer::wxStringBuffer}
+
+\func{}{wxStringBuffer}{\param{const wxString\& }{str}, \param{size\_t }{len}}
+
+Constructs a writable string buffer object associated with the given string
+and containing enough space for at least {\it len} characters. Basicly, this
+is equivalent to calling \helpref{GetWriteBuf}{wxstringgetwritebuf} and
+saving the result.
+
+\membersection{wxStringBuffer::\destruct{wxStringBuffer}}
+
+\func{}{\destruct{wxStringBuffer}}{\void}
+
+Restores the string passed to the constructor to the usable state by calling 
+\helpref{UngetWriteBuf}{wxstringungetwritebuf} on it.
+
+\membersection{wxStringBuffer::operator wxChar *}
+
+\constfunc{wxChar *}{operator wxChar *}{\void}
+
+Returns the writable pointer to a buffer of the size at least equal to the
+length specified in the constructor.
+
+
index dc244ec1d842e29cee25674439c7a2d5032127c7..6c035428b1b0ba41624afd801551adfd07e18829 100644 (file)
@@ -1082,6 +1082,25 @@ public:
     { Copy(array); }
 };
 
+// ----------------------------------------------------------------------------
+// wxStringBuffer: a tiny class allowing to get a writable pointer into string
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxStringBuffer
+{
+public:
+    wxStringBuffer(wxString& str, size_t lenWanted = 1024)
+        : m_str(str) { m_buf = m_str.GetWriteBuf(lenWanted); }
+
+    ~wxStringBuffer() { m_str.UngetWriteBuf(); }
+
+    operator wxChar*() const { return m_buf; }
+
+private:
+    wxString& m_str;
+    wxChar   *m_buf;
+};
+
 // ---------------------------------------------------------------------------
 // wxString comparison functions: operator versions are always case sensitive
 // ---------------------------------------------------------------------------