OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
Public Member Functions | List of all members
juce::MemoryBlock Class Reference

`#include <juce_MemoryBlock.h>`

## Public Member Functions
| 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
const void * | getData () const noexcept
template<typename Type >
char & | operator[] (const Type offset) noexcept
template<typename Type >
const char & | operator[] (const Type offset) const noexcept
char * | begin () noexcept
const char * | begin () const noexcept
char * | end () noexcept
const char * | end () const noexcept
bool | isEmpty () const noexcept
size_t | getSize () const noexcept
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)
void | replaceWith (const void *srcData, size_t numBytes)

## Detailed Description

A class to hold a resizable block of raw data.

Definition at line 32 of file juce_MemoryBlock.h.

## Constructor & Destructor Documentation

## ◆ MemoryBlock() [1/5]

juce::MemoryBlock::MemoryBlock | ( |  | ) |
| noexcept

Create an uninitialised block with 0 size.

Definition at line 26 of file juce_MemoryBlock.cpp.

## ◆ MemoryBlock() [2/5]

juce::MemoryBlock::MemoryBlock | ( | size_t | initialSize,
|  | bool | initialiseToZero = false )

Creates a memory block with a given initial size.

Parameters

  initialSize | the size of block to create
  initialiseToZero | whether to clear the memory or just leave it uninitialised

Definition at line 28 of file juce_MemoryBlock.cpp.

## ◆ MemoryBlock() [3/5]

juce::MemoryBlock::MemoryBlock | ( | const MemoryBlock & | other | ) |

Creates a copy of another memory block.

Definition at line 41 of file juce_MemoryBlock.cpp.

## ◆ MemoryBlock() [4/5]

juce::MemoryBlock::MemoryBlock | ( | const void * | dataToInitialiseFrom,
|  | size_t | sizeInBytes )

Creates a memory block using a copy of a block of data.

Parameters

  dataToInitialiseFrom | some data to copy into this block
  sizeInBytes | how much space to use

Definition at line 52 of file juce_MemoryBlock.cpp.

## ◆ ~MemoryBlock()

juce::MemoryBlock::~MemoryBlock | ( |  | ) |
| noexcept

Destructor.

Definition at line 68 of file juce_MemoryBlock.cpp.

## ◆ MemoryBlock() [5/5]

juce::MemoryBlock::MemoryBlock | ( | MemoryBlock && | other | ) |
| noexcept

Move constructor

Definition at line 83 of file juce_MemoryBlock.cpp.

## Member Function Documentation

## ◆ append()

void juce::MemoryBlock::append | ( | const void * | data,
|  | size_t | numBytes )

Adds another block of data to the end of this one. The data pointer must not be null. This block's size will be increased accordingly.

Definition at line 166 of file juce_MemoryBlock.cpp.

## ◆ begin() [1/2]

const char * juce::MemoryBlock::begin | ( |  | ) | const
| inline noexcept

Returns an iterator for the data.

Definition at line 114 of file juce_MemoryBlock.h.

## ◆ begin() [2/2]

char * juce::MemoryBlock::begin | ( |  | ) |
| inline noexcept

Returns an iterator for the data.

Definition at line 111 of file juce_MemoryBlock.h.

## ◆ copyFrom()

void juce::MemoryBlock::copyFrom | ( | const void * | srcData,
|  | int | destinationOffset,
|  | size_t | numBytes )
| noexcept

Copies data into this MemoryBlock from a memory address.

Parameters

  srcData | the memory location of the data to copy into this block
  destinationOffset | the offset in this block at which the data being copied should begin
  numBytes | how much to copy in (if this goes beyond the size of the memory block, it will be clipped so not to do anything nasty)

Definition at line 224 of file juce_MemoryBlock.cpp.

Referenced by juce::InterprocessConnection::sendMessage().

## ◆ copyTo()

void juce::MemoryBlock::copyTo | ( | void * | destData,
|  | int | sourceOffset,
|  | size_t | numBytes ) const
| noexcept

Copies data from this MemoryBlock to a memory address.

Parameters

  destData | the memory location to write to
  sourceOffset | the offset within this block from which the copied data will be read
  numBytes | how much to copy (if this extends beyond the limits of the memory block, zeros will be used for that portion of the data)

Definition at line 242 of file juce_MemoryBlock.cpp.

Referenced by juce::Uuid::operator=().

## ◆ end() [1/2]

const char * juce::MemoryBlock::end | ( |  | ) | const
| inline noexcept

Returns an end-iterator for the data.

Definition at line 120 of file juce_MemoryBlock.h.

## ◆ end() [2/2]

char * juce::MemoryBlock::end | ( |  | ) |
| inline noexcept

Returns an end-iterator for the data.

Definition at line 117 of file juce_MemoryBlock.h.

## ◆ ensureSize()

void juce::MemoryBlock::ensureSize | ( | size_t | minimumSize,
|  | bool | initialiseNewSpaceToZero = false )

Increases the block's size only if it's smaller than a given size.

Parameters

  minimumSize | if the block is already bigger than this size, no action will be taken; otherwise it will be increased to this size
  initialiseNewSpaceToZero | if the block gets enlarged, this determines whether to clear the new section or just leave it uninitialised

See also
  setSize

Definition at line 148 of file juce_MemoryBlock.cpp.

Referenced by loadFromHexString(), juce::Uuid::operator=(), and juce::MemoryOutputStream::preallocate().

## ◆ fillWith()

void juce::MemoryBlock::fillWith | ( | uint8 | valueToUse | ) |
| noexcept

Fills the entire memory block with a repeated byte value. This is handy for clearing a block of memory to zero.

Definition at line 161 of file juce_MemoryBlock.cpp.

## ◆ fromBase64Encoding()

bool juce::MemoryBlock::fromBase64Encoding | ( | StringRef | encodedString | ) |

Takes a string created by MemoryBlock::toBase64Encoding() and extracts the original data.

The string passed in must have been created by to64BitEncoding(), and this block will be resized to recreate the original data block.

Note that these methods use a JUCE-specific (i.e. not standard!) 64-bit encoding system. You may prefer to use the Base64::convertFromBase64() method if you want to use the standard base-64 encoding.

See also
  toBase64Encoding, Base64::convertFromBase64

Definition at line 382 of file juce_MemoryBlock.cpp.

Referenced by juce::NamedValueSet::setFromXmlAttributes().

## ◆ getBitRange()

int juce::MemoryBlock::getBitRange | ( | size_t | bitRangeStart,
|  | size_t | numBitsToRead ) const
| noexcept

Reads a number of bits from the memory block, treating it as one long binary sequence

Definition at line 271 of file juce_MemoryBlock.cpp.

Referenced by toBase64Encoding().

## ◆ getData() [1/2]

const void * juce::MemoryBlock::getData | ( |  | ) | const
| inline noexcept

Returns a void pointer to the data.

Note that the pointer returned will probably become invalid when the block is resized.

Definition at line 98 of file juce_MemoryBlock.h.

## ◆ getData() [2/2]

void * juce::MemoryBlock::getData | ( |  | ) |
| inline noexcept

Returns a void pointer to the data.

Note that the pointer returned will probably become invalid when the block is resized.

Definition at line 91 of file juce_MemoryBlock.h.

Referenced by juce::MemoryOutputStream::getData(), juce::BigInteger::loadFromMemoryBlock(), juce::MACAddress::MACAddress(), juce::MemoryInputStream::MemoryInputStream(), juce::MemoryInputStream::MemoryInputStream(), juce::MemoryInputStream::MemoryInputStream(), juce::MidiFile::readFrom(), juce::var::readFromStream(), and juce::InterprocessConnection::sendMessage().

## ◆ getSize()

size_t juce::MemoryBlock::getSize | ( |  | ) | const
| inline noexcept

Returns the block's current allocated size, in bytes.

Definition at line 127 of file juce_MemoryBlock.h.

Referenced by juce::MemoryOutputStream::getData(), juce::BigInteger::loadFromMemoryBlock(), juce::MACAddress::MACAddress(), juce::MemoryInputStream::MemoryInputStream(), juce::MemoryOutputStream::MemoryOutputStream(), juce::MidiFile::readFrom(), and juce::InterprocessConnection::sendMessage().

## ◆ insert()

void juce::MemoryBlock::insert | ( | const void * | dataToInsert,
|  | size_t | numBytesToInsert,
|  | size_t | insertPosition )

Inserts some data into the block. The dataToInsert pointer must not be null. This block's size will be increased accordingly. If the insert position lies outside the valid range of the block, it will be clipped to within the range before being used.

Definition at line 190 of file juce_MemoryBlock.cpp.

## ◆ isEmpty()

bool juce::MemoryBlock::isEmpty | ( |  | ) | const
| inline noexcept

Returns true if the memory block has zero size.

Definition at line 124 of file juce_MemoryBlock.h.

## ◆ loadFromHexString()

void juce::MemoryBlock::loadFromHexString | ( | StringRef | sourceHexString | ) |

Parses a string of hexadecimal numbers and writes this data into the memory block.

The block will be resized to the number of valid bytes read from the string. Non-hex characters in the string will be ignored.

See also
  String::toHexString()

Definition at line 319 of file juce_MemoryBlock.cpp.

Referenced by juce::MACAddress::MACAddress(), and juce::Uuid::operator=().

## ◆ matches()

bool juce::MemoryBlock::matches | ( | const void * | data,
|  | size_t | dataSize ) const
| noexcept

Returns true if the data in this MemoryBlock matches the raw bytes passed-in.

Definition at line 107 of file juce_MemoryBlock.cpp.

## ◆ operator!=()

bool juce::MemoryBlock::operator!= | ( | const MemoryBlock & | other | ) | const
| noexcept

Compares two memory blocks.

Returns
  true if the two blocks are different sizes or have different contents.

Definition at line 102 of file juce_MemoryBlock.cpp.

## ◆ operator=() [1/2]

MemoryBlock & juce::MemoryBlock::operator= | ( | const MemoryBlock & | other | ) |

Copies another memory block onto this one. This block will be resized and copied to exactly match the other one.

Definition at line 72 of file juce_MemoryBlock.cpp.

## ◆ operator=() [2/2]

MemoryBlock & juce::MemoryBlock::operator= | ( | MemoryBlock && | other | ) |
| noexcept

Move assignment operator

Definition at line 89 of file juce_MemoryBlock.cpp.

## ◆ operator==()

bool juce::MemoryBlock::operator== | ( | const MemoryBlock & | other | ) | const
| noexcept

Compares two memory blocks.

Returns
  true only if the two blocks are the same size and have identical contents.

Definition at line 97 of file juce_MemoryBlock.cpp.

## ◆ operator[]() [1/2]

template<typename Type >

const char & juce::MemoryBlock::operator[] | ( | const Type | offset | ) | const
| inline noexcept

Returns a byte from the memory block.

Definition at line 108 of file juce_MemoryBlock.h.

## ◆ operator[]() [2/2]

template<typename Type >

char & juce::MemoryBlock::operator[] | ( | const Type | offset | ) |
| inline noexcept

Returns a byte from the memory block. This returns a reference, so you can also use it to set a byte.

Definition at line 104 of file juce_MemoryBlock.h.

## ◆ removeSection()

void juce::MemoryBlock::removeSection | ( | size_t | startByte,
|  | size_t | numBytesToRemove )

Chops out a section of the block.

This will remove a section of the memory block and close the gap around it, shifting any subsequent data downwards and reducing the size of the block.

If the range specified goes beyond the size of the block, it will be clipped.

Definition at line 208 of file juce_MemoryBlock.cpp.

## ◆ replaceAll()

void juce::MemoryBlock::replaceAll | ( | const void * | data,
|  | size_t | numBytes )

Resizes this block to the given size and fills its contents from the supplied buffer. The data pointer must not be null.

Definition at line 177 of file juce_MemoryBlock.cpp.

## ◆ replaceWith()

void juce::MemoryBlock::replaceWith | ( | const void * | srcData,
|  | size_t | numBytes )
| inline

Definition at line 274 of file juce_MemoryBlock.h.

## ◆ reset()

void juce::MemoryBlock::reset | ( |  | ) |

Frees all the blocks data, setting its size to 0.

Definition at line 142 of file juce_MemoryBlock.cpp.

Referenced by replaceAll(), and setSize().

## ◆ setBitRange()

void juce::MemoryBlock::setBitRange | ( | size_t | bitRangeStart,
|  | size_t | numBits,
|  | int | binaryNumberToApply )
| noexcept

Sets a number of bits in the memory block, treating it as a long binary sequence.

Definition at line 295 of file juce_MemoryBlock.cpp.

Referenced by fromBase64Encoding().

## ◆ setSize()

void juce::MemoryBlock::setSize | ( | size_t | newSize,
|  | bool | initialiseNewSpaceToZero = false )

Resizes the memory block.

Any data that is present in both the old and new sizes will be retained. When enlarging the block, the new space that is allocated at the end can either be cleared, or left uninitialised.

Parameters

  newSize | the new desired size for the block
  initialiseNewSpaceToZero | if the block gets enlarged, this determines whether to clear the new section or just leave it uninitialised

See also
  ensureSize

Definition at line 115 of file juce_MemoryBlock.cpp.

Referenced by append(), ensureSize(), fromBase64Encoding(), insert(), loadFromHexString(), juce::MemoryOutputStream::MemoryOutputStream(), operator=(), juce::var::readFromStream(), removeSection(), and replaceAll().

## ◆ swapWith()

void juce::MemoryBlock::swapWith | ( | MemoryBlock & | other | ) |
| noexcept

Exchanges the contents of this and another memory block. No actual copying is required for this, so it's very fast.

Definition at line 154 of file juce_MemoryBlock.cpp.

## ◆ toBase64Encoding()

String juce::MemoryBlock::toBase64Encoding | ( |  | ) | const

Returns a string of characters in a JUCE-specific text encoding that represents the binary contents of this block.

This uses a JUCE-specific (i.e. not standard!) 64-bit encoding system to convert binary data into a string of ASCII characters for purposes like storage in XML. Note that this proprietary format is mainly kept here for backwards-compatibility, and you may prefer to use the Base64::toBase64() method if you want to use the standard base-64 encoding.

See also
  fromBase64Encoding, Base64::toBase64, Base64::convertToBase64

Definition at line 356 of file juce_MemoryBlock.cpp.

## ◆ toString()

String juce::MemoryBlock::toString | ( |  | ) | const

Attempts to parse the contents of the block as a zero-terminated UTF8 string.

Definition at line 265 of file juce_MemoryBlock.cpp.

The documentation for this class was generated from the following files:

- juce_MemoryBlock.h
- juce_MemoryBlock.cpp