]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: buffer.h | |
e54c96f1 | 3 | // Purpose: interface of wxMemoryBuffer |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxMemoryBuffer | |
7c913512 | 11 | |
23324ae1 | 12 | A @b wxMemoryBuffer is a useful data structure for storing arbitrary sized |
8024723d FM |
13 | blocks of memory. wxMemoryBuffer guarantees deletion of the memory block when |
14 | the object is destroyed. | |
7c913512 | 15 | |
23324ae1 | 16 | @library{wxbase} |
8024723d | 17 | @category{data} |
23324ae1 | 18 | */ |
7c913512 | 19 | class wxMemoryBuffer |
23324ae1 FM |
20 | { |
21 | public: | |
8024723d FM |
22 | /** |
23 | Copy constructor, refcounting is used for performance, but wxMemoryBuffer | |
24 | is not a copy-on-write structure so changes made to one buffer effect all | |
25 | copies made from it. | |
26 | ||
27 | @see @ref overview_refcount | |
28 | */ | |
29 | wxMemoryBuffer(const wxMemoryBuffer& src); | |
30 | ||
23324ae1 FM |
31 | /** |
32 | Create a new buffer. | |
8024723d | 33 | |
7c913512 | 34 | @param size |
8024723d | 35 | size of the new buffer. |
23324ae1 | 36 | */ |
7c913512 | 37 | wxMemoryBuffer(size_t size); |
23324ae1 FM |
38 | |
39 | /** | |
40 | Append a single byte to the buffer. | |
8024723d | 41 | |
7c913512 | 42 | @param data |
4cc4bfaf | 43 | New byte to append to the buffer. |
23324ae1 FM |
44 | */ |
45 | void AppendByte(char data); | |
46 | ||
47 | /** | |
48 | Ensure that the buffer is big enough and return a pointer to the start | |
7c913512 | 49 | of the empty space in the buffer. This pointer can be used to directly |
8024723d FM |
50 | write data into the buffer, this new data will be appended to the |
51 | existing data. | |
52 | ||
7c913512 | 53 | @param sizeNeeded |
4cc4bfaf FM |
54 | Amount of extra space required in the buffer for |
55 | the append operation | |
23324ae1 | 56 | */ |
4cc4bfaf | 57 | void* GetAppendBuf(size_t sizeNeeded); |
23324ae1 FM |
58 | |
59 | /** | |
60 | Returns the size of the buffer. | |
61 | */ | |
d2aa927a | 62 | size_t GetBufSize() const; |
23324ae1 FM |
63 | |
64 | /** | |
65 | Return a pointer to the data in the buffer. | |
66 | */ | |
d2aa927a | 67 | void* GetData() const; |
23324ae1 FM |
68 | |
69 | /** | |
70 | Returns the length of the valid data in the buffer. | |
71 | */ | |
d2aa927a | 72 | size_t GetDataLen() const; |
23324ae1 FM |
73 | |
74 | /** | |
75 | Ensure the buffer is big enough and return a pointer to the | |
76 | buffer which can be used to directly write into the buffer | |
4cc4bfaf | 77 | up to @a sizeNeeded bytes. |
23324ae1 | 78 | */ |
4cc4bfaf | 79 | void* GetWriteBuf(size_t sizeNeeded); |
23324ae1 FM |
80 | |
81 | /** | |
4cc4bfaf | 82 | Ensures the buffer has at least @a size bytes available. |
23324ae1 FM |
83 | */ |
84 | void SetBufSize(size_t size); | |
85 | ||
86 | /** | |
8024723d FM |
87 | Sets the length of the data stored in the buffer. |
88 | Mainly useful for truncating existing data. | |
89 | ||
7c913512 | 90 | @param size |
4cc4bfaf FM |
91 | New length of the valid data in the buffer. This is |
92 | distinct from the allocated size | |
23324ae1 FM |
93 | */ |
94 | void SetDataLen(size_t size); | |
95 | ||
96 | /** | |
97 | Update the length after completing a direct append, which | |
98 | you must have used GetAppendBuf() to initialise. | |
8024723d | 99 | |
7c913512 | 100 | @param sizeUsed |
4cc4bfaf FM |
101 | This is the amount of new data that has been |
102 | appended. | |
23324ae1 FM |
103 | */ |
104 | void UngetAppendBuf(size_t sizeUsed); | |
105 | ||
106 | /** | |
107 | Update the buffer after completing a direct write, which | |
108 | you must have used GetWriteBuf() to initialise. | |
8024723d | 109 | |
7c913512 | 110 | @param sizeUsed |
4cc4bfaf FM |
111 | The amount of data written in to buffer |
112 | by the direct write | |
23324ae1 FM |
113 | */ |
114 | void UngetWriteBuf(size_t sizeUsed); | |
115 | }; | |
e54c96f1 | 116 |