wxstringbufferthis tiny class allows to conveniently access the wxstring internal buffer as a writable pointer without any risk of forgetting to restore the string to the usable state later. for example, assuming you have a low-level os function called getmeaningoflifeasstring(char *) returning the value in the provided buffer (which must be writable, of course) you might call it like this:
wxstring theanswer; getmeaningoflifeasstring(wxstringbuffer(theanswer, 1024)); if ( theanswer != "42" ) { wxlogerror("something is very wrong!"); }note that the exact usage of this depends on whether on not wxuse_stl is enabled. if wxuse_stl is enabled, wxstringbuffer creates a separate empty character buffer, and if wxuse_stl is disabled, it uses getwritebuf() from wxstring, keeping the same buffer wxstring uses intact. in other words, relying on wxstringbuffer containing the old wxstring data is probably not a good idea if you want to build your program in both with and without wxuse_stl. derived from none include files <wx/string.h> members
wxstringbuffer::wxstringbuffer
wxstringbuffer::wxstringbufferwxstringbuffer(const wxstring& str, size_t len) constructs a writable string buffer object associated with the given string and containing enough space for at least len characters. basically, this is equivalent to calling getwritebuf and saving the result.
wxstringbuffer::~wxstringbuffer~wxstringbuffer() restores the string passed to the constructor to the usable state by calling ungetwritebuf on it.
wxstringbuffer::operator wxchar *wxchar * operator wxchar *() returns the writable pointer to a buffer of the size at least equal to the length specified in the constructor.
|