Loading...
Searching...
No Matches
juce_MemoryBlock.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API MemoryBlock
{
public:
//==============================================================================
MemoryBlock() noexcept;
MemoryBlock (size_t initialSize,
bool initialiseToZero = false);
MemoryBlock (const MemoryBlock&);
MemoryBlock (const void* dataToInitialiseFrom, size_t sizeInBytes);
~MemoryBlock() noexcept;
MemoryBlock& operator= (const MemoryBlock&);
MemoryBlock (MemoryBlock&&) noexcept;
MemoryBlock& operator= (MemoryBlock&&) noexcept;
//==============================================================================
bool operator== (const MemoryBlock& other) const noexcept;
bool operator!= (const MemoryBlock& other) const noexcept;
bool matches (const void* data, size_t dataSize) const noexcept;
//==============================================================================
void* getData() noexcept { return data; }
const void* getData() const noexcept { return data; }
template <typename Type>
char& operator[] (const Type offset) noexcept { return data [offset]; }
template <typename Type>
const char& operator[] (const Type offset) const noexcept { return data [offset]; }
char* begin() noexcept { return data; }
const char* begin() const noexcept { return data; }
char* end() noexcept { return begin() + getSize(); }
const char* end() const noexcept { return begin() + getSize(); }
//==============================================================================
bool isEmpty() const noexcept { return getSize() == 0; }
size_t getSize() const noexcept { return size; }
void setSize (size_t newSize,
bool initialiseNewSpaceToZero = false);
void ensureSize (size_t minimumSize,
bool initialiseNewSpaceToZero = false);
void reset();
//==============================================================================
void fillWith (uint8 valueToUse) noexcept;
void append (const void* data, size_t numBytes);
void replaceAll (const void* data, size_t numBytes);
void insert (const void* dataToInsert, size_t numBytesToInsert, size_t insertPosition);
void removeSection (size_t startByte, size_t numBytesToRemove);
//==============================================================================
void copyFrom (const void* srcData,
int destinationOffset,
size_t numBytes) noexcept;
void copyTo (void* destData,
int sourceOffset,
size_t numBytes) const noexcept;
//==============================================================================
void swapWith (MemoryBlock& other) noexcept;
//==============================================================================
String toString() const;
//==============================================================================
void loadFromHexString (StringRef sourceHexString);
//==============================================================================
void setBitRange (size_t bitRangeStart,
size_t numBits,
int binaryNumberToApply) noexcept;
int getBitRange (size_t bitRangeStart,
size_t numBitsToRead) const noexcept;
//==============================================================================
String toBase64Encoding() const;
bool fromBase64Encoding (StringRef encodedString);
//==============================================================================
#ifndef DOXYGEN
[[deprecated ("Use the replaceAll method instead, which will also replace the data when numBytes == 0.")]]
void replaceWith (const void* srcData, size_t numBytes)
{
if (numBytes > 0)
replaceAll (srcData, numBytes);
}
#endif
private:
//==============================================================================
using HeapBlockType = HeapBlock<char, true>;
HeapBlockType data;
size_t size = 0;
JUCE_LEAK_DETECTOR (MemoryBlock)
};
} // 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::matches
bool matches(const void *data, size_t dataSize) const noexcept
Definition juce_MemoryBlock.cpp:107
juce::MemoryBlock::end
char * end() noexcept
Definition juce_MemoryBlock.h:117
juce::MemoryBlock::MemoryBlock
MemoryBlock() noexcept
Definition juce_MemoryBlock.cpp:26
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