X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de4983f3236c2043479abb21857aca958a7b61f0..36a0190ebd5bd9a7302f60f6dcd608b80574e21c:/interface/wx/buffer.h diff --git a/interface/wx/buffer.h b/interface/wx/buffer.h index bb14bb1ab2..8ab9dce8aa 100644 --- a/interface/wx/buffer.h +++ b/interface/wx/buffer.h @@ -2,8 +2,7 @@ // Name: buffer.h // Purpose: interface of wxMemoryBuffer // Author: wxWidgets team -// RCS-ID: $Id$ -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -57,16 +56,24 @@ public: The buffer's destructor will not destroy @a str. The returned buffer's data is valid only as long as @a str is valid. + + @param str String data. + @param len If specified, length of the string, otherwise the string + is considered to be NUL-terminated. */ - static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str); + static const wxScopedCharTypeBuffer CreateNonOwned(const CharType *str, size_t len = wxNO_LEN); /** 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). + + @param str String data. + @param len If specified, length of the string, otherwise the string + is considered to be NUL-terminated. */ - static const wxScopedCharTypeBuffer CreateOwned(const CharType *str); + static const wxScopedCharTypeBuffer CreateOwned(CharType *str, size_t len = wxNO_LEN); /** Copy constructor. @@ -94,6 +101,9 @@ public: /// Returns const pointer to the stored data. const CharType *data() const; + /// Returns length of the string stored. + size_t length() const; + /// Implicit conversion to C string. operator const CharType *() const; @@ -133,9 +143,13 @@ public: /** Creates (owned) buffer from @a str and takes ownership of it. + @param str String data. + @param len If specified, length of the string, otherwise the string + is considered to be NUL-terminated. + @see wxScopedCharTypeBuffer::CreateOwned() */ - wxCharTypeBuffer(const CharType *str = NULL); + wxCharTypeBuffer(const CharType *str = NULL, size_t len = wxNO_LEN); /** @@ -163,7 +177,7 @@ public: wxCharTypeBuffer(const wxScopedCharTypeBuffer& src); /** - Assigns @a str to this buffer and takes ownership of it (i.e. the + Assigns @a str to this buffer and takes ownership of it (i.e.\ the buffer becomes "owned"). */ wxCharTypeBuffer& operator=(const CharType *str); @@ -185,8 +199,27 @@ public: Can only be called on buffers that don't share data with another buffer (i.e. reference count of the data is 1). + + @see shrink() */ bool extend(size_t len); + + /** + Shrinks the buffer to have size @a len and NUL-terminates the string + at this length. + + Can only be called on buffers that don't share data with another + buffer (i.e. reference count of the data is 1). + + @param len Length to shrink to. Must not be larger than current length. + + @note The string is not reallocated to take less memory. + + @since 2.9.0 + + @see extend() + */ + bool shrink(size_t len); }; /** @@ -253,9 +286,9 @@ public: Create a new buffer. @param size - size of the new buffer. + size of the new buffer, 1KiB by default. */ - wxMemoryBuffer(size_t size = DefBufSize); + wxMemoryBuffer(size_t size = 1024); /** Append a single byte to the buffer. @@ -265,6 +298,27 @@ public: */ void AppendByte(char data); + /** + Single call to append a data block to the buffer. + + @param data + Pointer to block to append to the buffer. + @param len + Length of data to append. + */ + void AppendData(const void *data, size_t len); + + /** + Clear the buffer contents. + + The buffer won't contain any data after this method is called. + + @see IsEmpty() + + @since 2.9.4 + */ + void Clear(); + /** Ensure that the buffer is big enough and return a pointer to the start of the empty space in the buffer. This pointer can be used to directly @@ -299,6 +353,15 @@ public: */ void* GetWriteBuf(size_t sizeNeeded); + /** + Returns true if the buffer contains no data. + + @see Clear() + + @since 2.9.4 + */ + bool IsEmpty() const; + /** Ensures the buffer has at least @a size bytes available. */