JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
fbuffer.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------
2// Project : SDK Base
3// Version : 1.0
4//
5// Category : Helpers
6// Filename : base/source/fbuffer.h
7// Created by : Steinberg, 2008
8// Description :
9//
10//-----------------------------------------------------------------------------
11// LICENSE
12// (c) 2023, Steinberg Media Technologies GmbH, All Rights Reserved
13//-----------------------------------------------------------------------------
14// Redistribution and use in source and binary forms, with or without modification,
15// are permitted provided that the following conditions are met:
16//
17// * Redistributions of source code must retain the above copyright notice,
18// this list of conditions and the following disclaimer.
19// * Redistributions in binary form must reproduce the above copyright notice,
20// this list of conditions and the following disclaimer in the documentation
21// and/or other materials provided with the distribution.
22// * Neither the name of the Steinberg Media Technologies nor the names of its
23// contributors may be used to endorse or promote products derived from this
24// software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35// OF THE POSSIBILITY OF SUCH DAMAGE.
36//-----------------------------------------------------------------------------
37
38#pragma once
39
41#include <cstring>
42
43namespace Steinberg {
44class String;
45
46//------------------------------------------------------------------------
54//------------------------------------------------------------------------
55class Buffer
56{
57public:
58//---------------------------------------------------------------------
59
62 Buffer ();
63
68 Buffer (const void* b, uint32 size);
69
74 Buffer (uint32 size, uint8 initVal);
75
79 Buffer (uint32 size);
80
84 Buffer (const Buffer& buff);
85
88 virtual ~Buffer ();
89
93 void operator = (const Buffer& buff);
94
99 bool operator == (const Buffer& buff)const;
100
101 uint32 getSize () const {return memSize;}
102
107 bool setSize (uint32 newSize);
108
113 bool grow (uint32 memSize);
114 bool setMaxSize (uint32 size) {return grow (size);}
115
116 void fillup (uint8 initVal = 0);
117 uint32 getFillSize ()const {return fillSize;}
118 bool setFillSize (uint32 c);
119 inline void flush () {setFillSize (0);}
120 bool truncateToFillSize ();
121
122 bool isFull () const { return (fillSize == memSize); }
123 uint32 getFree () const { return (memSize - fillSize); }
124
125 inline void shiftStart (int32 amount) {return shiftAt (0, amount);}
126 void shiftAt (uint32 position, int32 amount);
127 void move (int32 amount, uint8 initVal = 0);
128
129 bool copy (uint32 from, uint32 to, uint32 bytes);
130 uint32 get (void* b, uint32 size);
131
132 void setDelta (uint32 d) {delta = d;}
133
134 bool put (uint8);
135 bool put (char16 c);
136 bool put (char c);
137 bool put (const void* , uint32 size);
138 bool put (void* , uint32 size);
139 bool put (uint8* , uint32 size);
140 bool put (char8* , uint32 size);
141 bool put (const uint8* , uint32 size);
142 bool put (const char8* , uint32 size);
143 bool put (const String&);
144
145 void set (uint8 value);
146
147 // strings ----------------
148 bool appendString (const tchar* s);
149 bool appendString (tchar* s);
150 bool appendString (tchar c) { return put (c); }
151
152 bool appendString8 (const char8* s);
153 bool appendString16 (const char16* s);
154
155 bool appendString8 (char8* s) { return appendString8 ((const char8*)s); }
156 bool appendString8 (unsigned char* s) { return appendString8 ((const char8*)s); }
157 bool appendString8 (const unsigned char* s) { return appendString8 ((const char8*)s); }
158
159 bool appendString8 (char8 c) { return put ((uint8)c); }
160 bool appendString8 (unsigned char c) { return put (c); }
161 bool appendString16 (char16 c) { return put (c); }
162 bool appendString16 (char16* s) { return appendString16 ((const char16*)s); }
163
164 bool prependString (const tchar* s);
165 bool prependString (tchar* s);
166 bool prependString (tchar c);
167
168 bool prependString8 (const char8* s);
169 bool prependString16 (const char16* s);
170
171 bool prependString8 (char8 c);
172 bool prependString8 (unsigned char c) { return prependString8 ((char8)c); }
173 bool prependString8 (char8* s) { return prependString8 ((const char8*)s); }
174 bool prependString8 (unsigned char* s) { return prependString8((const char8*)s); }
175 bool prependString8 (const unsigned char* s) { return prependString8 ((const char8*)s); }
176 bool prependString16 (char16 c);
177 bool prependString16 (char16* s) { return prependString16 ((const char16*)s); }
178
179 bool operator+= (const char* s) { return appendString8 (s); }
180 bool operator+= (char c) { return appendString8 (c); }
181 bool operator+= (const char16* s) { return appendString16 (s); }
182 bool operator+= (char16 c) { return appendString16 (c); }
183
184 bool operator= (const char* s) { flush (); return appendString8 (s); }
185 bool operator= (const char16* s) { flush (); return appendString16 (s); }
186 bool operator= (char8 c) { flush (); return appendString8 (c); }
187 bool operator= (char16 c) { flush (); return appendString16 (c); }
188
189 void endString () {put (tchar (0));}
190 void endString8 () {put (char8 (0));}
191 void endString16 () {put (char16 (0));}
192
193 bool makeHexString (String& result);
194 bool fromHexString (const char8* string);
195
196 // conversion
197 operator void* () const { return (void*)buffer; }
198 inline tchar* str () const {return (tchar*)buffer;}
199 inline char8* str8 () const {return (char8*)buffer;}
200 inline char16* str16 () const {return (char16*)buffer;}
201 inline int8* int8Ptr () const {return (int8*)buffer;}
202 inline uint8* uint8Ptr () const {return (uint8*)buffer; }
203 inline int16* int16Ptr () const {return (int16*)buffer; }
204 inline uint16* uint16Ptr () const {return (uint16*)buffer; }
205 inline int32* int32Ptr () const {return (int32*)buffer; }
206 inline uint32* uint32Ptr () const {return (uint32*)buffer; }
207 inline float* floatPtr () const {return (float*)buffer; }
208 inline double* doublePtr () const {return (double*)buffer; }
209 inline char16* wcharPtr () const {return (char16*)buffer;}
210
211 int8* operator + (uint32 i);
212
213 int32 operator ! () { return buffer == nullptr; }
214
215 enum swapSize
216 {
217 kSwap16 = 2,
218 kSwap32 = 4,
219 kSwap64 = 8
220 };
221 bool swap (int16 swapSize);
222 static bool swap (void* buffer, uint32 bufferSize, int16 swapSize);
223
224 void take (Buffer& from);
225 int8* pass ();
226
231 virtual bool toWideString (int32 sourceCodePage); // Buffer contains char8 of given encoding -> utf16
232
237 virtual bool toMultibyteString (int32 destCodePage); // Buffer contains utf16 -> char8 of given encoding
238
239//------------------------------------------------------------------------
240protected:
241 static const uint32 defaultDelta = 0x1000; // 0x1000
242
243 int8* buffer;
244 uint32 memSize;
245 uint32 fillSize;
246 uint32 delta;
247};
248
249inline bool Buffer::put (void* p, uint32 count) { return put ((const void*)p , count ); }
250inline bool Buffer::put (uint8 * p, uint32 count) { return put ((const void*)p , count ); }
251inline bool Buffer::put (char8* p, uint32 count) { return put ((const void*)p , count ); }
252inline bool Buffer::put (const uint8* p, uint32 count) { return put ((const void*)p , count ); }
253inline bool Buffer::put (const char8* p, uint32 count) { return put ((const void*)p , count ); }
254
255//------------------------------------------------------------------------
256inline bool Buffer::appendString (const tchar* s)
257{
258#ifdef UNICODE
259 return appendString16 (s);
260#else
261 return appendString8 (s);
262#endif
263}
264
265//------------------------------------------------------------------------
266inline bool Buffer::appendString (tchar* s)
267{
268#ifdef UNICODE
269 return appendString16 (s);
270#else
271 return appendString8 (s);
272#endif
273}
274
275//------------------------------------------------------------------------
276inline bool Buffer::prependString (const tchar* s)
277{
278#ifdef UNICODE
279 return prependString16 (s);
280#else
281 return prependString8 (s);
282#endif
283}
284
285//------------------------------------------------------------------------
286inline bool Buffer::prependString (tchar* s)
287{
288#ifdef UNICODE
289 return prependString16 (s);
290#else
291 return prependString8 (s);
292#endif
293}
294
295//------------------------------------------------------------------------
296inline bool Buffer::prependString (tchar c)
297{
298#ifdef UNICODE
299 return prependString16 (c);
300#else
301 return prependString8 (c);
302#endif
303}
304
305//------------------------------------------------------------------------
306} // namespace Steinberg
uint32 getSize() const
Definition fbuffer.h:101
void take(Buffer &from)
takes another Buffer's memory, frees the current Buffer's memory
Definition fbuffer.cpp:576
void shiftStart(int32 amount)
moves all memory by given amount, grows the Buffer if necessary
Definition fbuffer.h:125
uint16 * uint16Ptr() const
conversion
Definition fbuffer.h:204
void flush()
sets fill size to zero
Definition fbuffer.h:119
int8 * int8Ptr() const
conversion
Definition fbuffer.h:201
bool put(uint8)
append value at end, grows Buffer if necessary
Definition fbuffer.cpp:168
void operator=(const Buffer &buff)
Assignment operator - copies contents from a given Buffer and increases the size if necessary.
Definition fbuffer.cpp:127
bool truncateToFillSize()
Definition fbuffer.cpp:393
virtual bool toWideString(int32 sourceCodePage)
Converts a Buffer's content to UTF-16 from a given multi-byte code page, Buffer must contain char8 of...
Definition fbuffer.cpp:598
bool setFillSize(uint32 c)
sets a new fill size, does not change any memory
Definition fbuffer.cpp:382
bool isFull() const
Definition fbuffer.h:122
void move(int32 amount, uint8 initVal=0)
shifts memory at start without growing the buffer, so data is lost and initialized with init val
Definition fbuffer.cpp:441
void setDelta(uint32 d)
define the block size by which the Buffer grows, see grow()
Definition fbuffer.h:132
float * floatPtr() const
conversion
Definition fbuffer.h:207
void fillup(uint8 initVal=0)
set from fillSize to end
Definition fbuffer.cpp:521
virtual bool toMultibyteString(int32 destCodePage)
Converts a Buffer's content from UTF-16 to a given multi-byte code page, Buffer must contain UTF-16 e...
Definition fbuffer.cpp:619
bool copy(uint32 from, uint32 to, uint32 bytes)
copies a number of bytes from one position to another, the size may be adapted
Definition fbuffer.cpp:280
tchar * str() const
conversion
Definition fbuffer.h:198
char16 * str16() const
conversion
Definition fbuffer.h:200
uint32 getFree() const
Definition fbuffer.h:123
int16 * int16Ptr() const
conversion
Definition fbuffer.h:203
bool operator==(const Buffer &buff) const
Comparison operator - copies contents from a given Buffer and increases the size if necessary.
Definition fbuffer.cpp:140
uint32 get(void *b, uint32 size)
copy to buffer from fillSize, and shift fillSize
Definition fbuffer.cpp:150
uint32 getFillSize() const
Definition fbuffer.h:117
char16 * wcharPtr() const
conversion
Definition fbuffer.h:209
uint8 * uint8Ptr() const
conversion
Definition fbuffer.h:202
Buffer()
Default constructor, allocates no memory at all.
Definition fbuffer.cpp:45
bool setMaxSize(uint32 size)
see grow()
Definition fbuffer.h:114
char8 * str8() const
conversion
Definition fbuffer.h:199
int32 * int32Ptr() const
conversion
Definition fbuffer.h:205
virtual ~Buffer()
Destructor - deallocates the internal memory.
Definition fbuffer.cpp:119
bool setSize(uint32 newSize)
Sets a new size for this Buffer, keeping as much content as possible.
Definition fbuffer.cpp:470
uint32 * uint32Ptr() const
conversion
Definition fbuffer.h:206
double * doublePtr() const
conversion
Definition fbuffer.h:208
bool grow(uint32 memSize)
Increases the Buffer to the next block, block size given by delta.
Definition fbuffer.cpp:402
int8 * operator+(uint32 i)
Definition fbuffer.cpp:528
int8 * pass()
pass the current Buffer's memory
Definition fbuffer.cpp:588
void shiftAt(uint32 position, int32 amount)
moves memory starting at the given position
Definition fbuffer.cpp:415
bool swap(int16 swapSize)
swap all bytes of this Buffer by the given swapSize
Definition fbuffer.cpp:539