OpenShot Audio Library | OpenShotAudio: juce_MemoryBlock.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_MemoryBlock.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
32 class JUCE_API MemoryBlock
33{
34public:
35 //==============================================================================
37 MemoryBlock() noexcept;
38
44 MemoryBlock (size_t initialSize,
45 bool initialiseToZero = false);
46
48 MemoryBlock (const MemoryBlock&);
49
55 MemoryBlock (const void* dataToInitialiseFrom, size_t sizeInBytes);
56
58 ~MemoryBlock() noexcept;
59
63 MemoryBlock& operator= (const MemoryBlock&);
64
66 MemoryBlock (MemoryBlock&&) noexcept;
67
69 MemoryBlock& operator= (MemoryBlock&&) noexcept;
70
71 //==============================================================================
75 bool operator== (const MemoryBlock& other) const noexcept;
76
80 bool operator!= (const MemoryBlock& other) const noexcept;
81
83 bool matches (const void* data, size_t dataSize) const noexcept;
84
85 //==============================================================================
91 void* getData() noexcept { return data; }
92
98 const void* getData() const noexcept { return data; }
99
103 template <typename Type>
104 char& operator[] (const Type offset) noexcept { return data [offset]; }
105
107 template <typename Type>
108 const char& operator[] (const Type offset) const noexcept { return data [offset]; }
109
111 char* begin() noexcept { return data; }
112
114 const char* begin() const noexcept { return data; }
115
117 char* end() noexcept { return begin() + getSize(); }
118
120 const char* end() const noexcept { return begin() + getSize(); }
121
122 //==============================================================================
124 bool isEmpty() const noexcept { return getSize() == 0; }
125
127 size_t getSize() const noexcept { return size; }
128
141 void setSize (size_t newSize,
142 bool initialiseNewSpaceToZero = false);
143
153 void ensureSize (size_t minimumSize,
154 bool initialiseNewSpaceToZero = false);
155
157 void reset();
158
159 //==============================================================================
163 void fillWith (uint8 valueToUse) noexcept;
164
168 void append (const void* data, size_t numBytes);
169
173 void replaceAll (const void* data, size_t numBytes);
174
180 void insert (const void* dataToInsert, size_t numBytesToInsert, size_t insertPosition);
181
189 void removeSection (size_t startByte, size_t numBytesToRemove);
190
191 //==============================================================================
199 void copyFrom (const void* srcData,
200 int destinationOffset,
201 size_t numBytes) noexcept;
202
210 void copyTo (void* destData,
211 int sourceOffset,
212 size_t numBytes) const noexcept;
213
214 //==============================================================================
218 void swapWith (MemoryBlock& other) noexcept;
219
220 //==============================================================================
222 String toString() const;
223
224 //==============================================================================
232 void loadFromHexString (StringRef sourceHexString);
233
234 //==============================================================================
236 void setBitRange (size_t bitRangeStart,
237 size_t numBits,
238 int binaryNumberToApply) noexcept;
239
241 int getBitRange (size_t bitRangeStart,
242 size_t numBitsToRead) const noexcept;
243
244 //==============================================================================
256 String toBase64Encoding() const;
257
269 bool fromBase64Encoding (StringRef encodedString);
270
271 //==============================================================================
272 #ifndef DOXYGEN
273 [[deprecated ("Use the replaceAll method instead, which will also replace the data when numBytes == 0.")]]
274 void replaceWith (const void* srcData, size_t numBytes)
275 {
276 if (numBytes > 0)
277 replaceAll (srcData, numBytes);
278 }
279 #endif
280
281private:
282 //==============================================================================
283 using HeapBlockType = HeapBlock<char, true>;
284 HeapBlockType data;
285 size_t size = 0;
286
287 JUCE_LEAK_DETECTOR (MemoryBlock)
288};
289
290} // namespace juce
juce::MemoryBlock
Definition juce_MemoryBlock.h:33
juce::MemoryBlock::end
const char * end() const noexcept
Definition juce_MemoryBlock.h:120
juce::MemoryBlock::begin
const char * begin() const noexcept
Definition juce_MemoryBlock.h:114
juce::MemoryBlock::isEmpty
bool isEmpty() const noexcept
Definition juce_MemoryBlock.h:124
juce::MemoryBlock::end
char * end() noexcept
Definition juce_MemoryBlock.h:117
juce::MemoryBlock::getData
void * getData() noexcept
Definition juce_MemoryBlock.h:91
juce::MemoryBlock::getSize
size_t getSize() const noexcept
Definition juce_MemoryBlock.h:127
juce::MemoryBlock::getData
const void * getData() const noexcept
Definition juce_MemoryBlock.h:98
juce::MemoryBlock::begin
char * begin() noexcept
Definition juce_MemoryBlock.h:111
juce::StringRef
Definition juce_StringRef.h:62
juce::String
Definition juce_String.h:53