HephAudio v3.0.6
A cross-platform C++ library for recording, playing, and processing audio on Windows, Android, Linux, iOS, and macOS.
Loading...
Searching...
No Matches
Heph::BufferBase< Tself, Tdata > Class Template Reference

base class for buffers. Provides basic buffer operations and methods. More...

#include <BufferBase.h>

Inheritance diagram for Heph::BufferBase< Tself, Tdata >:
Heph::ArithmeticBuffer< Tself, Tdata > Heph::SignedArithmeticBuffer< Tself, Tdata >

Public Member Functions

virtual ~BufferBase ()
 
virtual Tself operator<< (size_t rhs) const
 
virtual Tself & operator<<= (size_t rhs)
 
virtual Tself operator>> (size_t rhs) const
 
virtual Tself & operator>>= (size_t rhs)
 
virtual bool operator== (const Tself &rhs) const
 
virtual bool operator!= (const Tself &rhs) const
 
Tdata & operator[] (size_t index) const
 
size_t Size () const
 
size_t SizeAsByte () const
 
Tdata & At (size_t index) const
 
virtual bool IsEmpty () const
 
virtual void Reset ()
 
virtual void Release ()
 
virtual Tself SubBuffer (size_t index, size_t size) const
 
virtual void Prepend (const Tself &rhs)
 
virtual void Append (const Tself &rhs)
 
virtual void Insert (const Tself &rhs, size_t index)
 
virtual void Cut (size_t index, size_t size)
 
virtual void Replace (const Tself &rhs, size_t index)
 
virtual void Replace (const Tself &rhs, size_t index, size_t size)
 
virtual void Resize (size_t newSize)
 
virtual void Reverse ()
 
Tdata * begin () const
 
Tdata * end () const
 

Protected Member Functions

 BufferBase ()
 
 BufferBase (size_t size)
 
 BufferBase (size_t size, BufferFlags flags)
 
 BufferBase (const std::initializer_list< Tdata > &rhs)
 
 BufferBase (const BufferBase &rhs)
 
 BufferBase (BufferBase &&rhs) noexcept
 
Tself & operator= (const std::initializer_list< Tdata > &rhs)
 
Tself & operator= (const Tself &rhs)
 
Tself & operator= (Tself &&rhs) noexcept
 

Static Protected Member Functions

static size_t SizeAsByte (size_t size)
 
template<typename U = Tdata>
static std::enable_if< std::is_class< U >::value >::type Initialize (U *pData, U *pDataEnd)
 
template<typename U = Tdata>
static std::enable_if<!std::is_class< U >::value >::type Initialize (U *pData, U *pDataEnd)
 
static Tdata * Allocate (size_t size_byte)
 
static Tdata * AllocateUninitialized (size_t size_byte)
 
static Tdata * SubBuffer (Tdata *pThisData, size_t thisSize_byte, size_t index_byte, size_t subBufferSize_byte)
 
static Tdata * Prepend (Tdata *pThisData, size_t thisSize_byte, Tdata *pRhsData, size_t rhsSize_byte)
 
static Tdata * Append (Tdata *pThisData, size_t thisSize_byte, Tdata *pRhsData, size_t rhsSize_byte)
 
static Tdata * Insert (Tdata *pThisData, size_t thisSize_byte, Tdata *pRhsData, size_t rhsSize_byte, size_t index_byte)
 
static Tdata * Cut (Tdata *pThisData, size_t thisSize_byte, size_t index_byte, size_t &cutSize_byte)
 
static void Replace (Tdata *pThisData, size_t thisSize_byte, Tdata *pRhsData, size_t rhsSize_byte, size_t index_byte)
 

Protected Attributes

Tdata * pData
 
size_t size
 

Detailed Description

template<class Tself, typename Tdata>
class Heph::BufferBase< Tself, Tdata >

base class for buffers. Provides basic buffer operations and methods.

Template Parameters
TselfType of the final buffer that inherits from this class (CRTP).
TdataType of the data the buffer stores.

Constructor & Destructor Documentation

◆ BufferBase() [1/6]

template<class Tself , typename Tdata >
Heph::BufferBase< Tself, Tdata >::BufferBase ( )
inlineprotected

creates a new instance and initializes it with default values.

◆ BufferBase() [2/6]

template<class Tself , typename Tdata >
Heph::BufferBase< Tself, Tdata >::BufferBase ( size_t size)
inlineexplicitprotected

creates a new instance and initializes it with the provided values.

Parameters
sizenumber of elements the buffer will store.

◆ BufferBase() [3/6]

template<class Tself , typename Tdata >
Heph::BufferBase< Tself, Tdata >::BufferBase ( size_t size,
BufferFlags flags )
inlineprotected

creates a new instance and initializes it with the provided values.

Parameters
sizenumber of elements the buffer will store.
flagsflags.

◆ BufferBase() [4/6]

template<class Tself , typename Tdata >
Heph::BufferBase< Tself, Tdata >::BufferBase ( const std::initializer_list< Tdata > & rhs)
inlineprotected

creates a new instance and initializes it with the provided values.

Parameters
rhsa list of elements the buffer will store.

◆ BufferBase() [5/6]

template<class Tself , typename Tdata >
Heph::BufferBase< Tself, Tdata >::BufferBase ( const BufferBase< Tself, Tdata > & rhs)
inlineprotected

creates a new instance and copies the rhs's data to it.

Parameters
rhsinstance whose data will be copied.

◆ BufferBase() [6/6]

template<class Tself , typename Tdata >
Heph::BufferBase< Tself, Tdata >::BufferBase ( BufferBase< Tself, Tdata > && rhs)
inlineprotectednoexcept

creates a new instance and moves the rhs's data to it.

Parameters
rhsinstance whose data will be moved.

◆ ~BufferBase()

template<class Tself , typename Tdata >
virtual Heph::BufferBase< Tself, Tdata >::~BufferBase ( )
inlinevirtual

releases the resources and destroys the instance.

Member Function Documentation

◆ operator<<()

template<class Tself , typename Tdata >
virtual Tself Heph::BufferBase< Tself, Tdata >::operator<< ( size_t rhs) const
inlinevirtual

creates a copy of the current buffer that is shifted to the left.

Parameters
rhsnumber of elements to shift.
Exceptions
InsufficientMemoryException

Reimplemented in HephAudio::AudioBuffer.

◆ operator<<=()

template<class Tself , typename Tdata >
virtual Tself & Heph::BufferBase< Tself, Tdata >::operator<<= ( size_t rhs)
inlinevirtual

shifts the current buffer to the left.

Parameters
rhsnumber of elements to shift.

Reimplemented in HephAudio::AudioBuffer.

◆ operator>>()

template<class Tself , typename Tdata >
virtual Tself Heph::BufferBase< Tself, Tdata >::operator>> ( size_t rhs) const
inlinevirtual

creates a copy of the current buffer that is shifted to the right.

Parameters
rhsnumber of elements to shift.
Exceptions
InsufficientMemoryException

Reimplemented in HephAudio::AudioBuffer.

◆ operator>>=()

template<class Tself , typename Tdata >
virtual Tself & Heph::BufferBase< Tself, Tdata >::operator>>= ( size_t rhs)
inlinevirtual

shifts the current buffer to the right.

Parameters
rhsnumber of elements to shift.

Reimplemented in HephAudio::AudioBuffer.

◆ operator[]()

template<class Tself , typename Tdata >
Tdata & Heph::BufferBase< Tself, Tdata >::operator[] ( size_t index) const
inline

gets the element at the provided index.

Note
this method does not check if the index is valid, use At method for error checking.

◆ Size()

template<class Tself , typename Tdata >
size_t Heph::BufferBase< Tself, Tdata >::Size ( ) const
inline

gets the number of elements stored.

◆ SizeAsByte() [1/2]

template<class Tself , typename Tdata >
size_t Heph::BufferBase< Tself, Tdata >::SizeAsByte ( ) const
inline

gets the size of the buffer in bytes.

◆ At()

template<class Tself , typename Tdata >
Tdata & Heph::BufferBase< Tself, Tdata >::At ( size_t index) const
inline

gets the element at the provided index.

Exceptions
InvalidArgumentException

◆ IsEmpty()

template<class Tself , typename Tdata >
virtual bool Heph::BufferBase< Tself, Tdata >::IsEmpty ( ) const
inlinevirtual

checks whether the buffer is empty.

Returns
true if the buffer is empty, otherwise false.

◆ Reset()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Reset ( )
inlinevirtual

sets all elements to their default value.

◆ Release()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Release ( )
inlinevirtual

◆ SubBuffer()

template<class Tself , typename Tdata >
virtual Tself Heph::BufferBase< Tself, Tdata >::SubBuffer ( size_t index,
size_t size ) const
inlinevirtual

gets the desired part of the buffer as a new instance.

Parameters
indexindex of the first element of the sub buffer.
sizenumber of elements the sub buffer will store.
Exceptions
InvalidArgumentException
InsufficientMemoryException

Reimplemented in HephAudio::AudioBuffer.

◆ Prepend()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Prepend ( const Tself & rhs)
inlinevirtual

adds the elements of the rhs to the start of the current buffer.

Parameters
rhsthe buffer whose elements will be added.
Exceptions
InvalidArgumentException
InsufficientMemoryException

◆ Append()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Append ( const Tself & rhs)
inlinevirtual

adds the elements of the rhs to the end of the current buffer.

Parameters
rhsthe buffer whose elements will be added.
Exceptions
InvalidArgumentException
InsufficientMemoryException

◆ Insert()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Insert ( const Tself & rhs,
size_t index )
inlinevirtual

adds the elements of the rhs to the provided position of the current buffer.

Parameters
rhsthe buffer whose elements will be added.
Exceptions
InvalidArgumentException
InsufficientMemoryException

◆ Cut()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Cut ( size_t index,
size_t size )
inlinevirtual

removes the desired portion of the buffer.

Parameters
indexindex of the first element that will be removed.
sizenumber of elements to remove.
Exceptions
InvalidArgumentException

Reimplemented in HephAudio::AudioBuffer.

◆ Replace() [1/2]

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Replace ( const Tself & rhs,
size_t index )
inlinevirtual

replaces the desired portion of the buffer with the contents of the rhs.

Parameters
rhsthe buffer whose elements will be used to replace the current buffer's elements.
indexindex of the first element that will be replaced.
Exceptions
InvalidArgumentException

◆ Replace() [2/2]

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Replace ( const Tself & rhs,
size_t index,
size_t size )
inlinevirtual

replaces the desired portion of the buffer with the contents of the rhs.

Parameters
rhsthe buffer whose elements will be used to replace the current buffer's elements.
indexindex of the first element that will be replaced.
sizenumber of elements to replace.
Exceptions
InvalidArgumentException

◆ Resize()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Resize ( size_t newSize)
inlinevirtual

changes the size of the buffer.
if new size is less than the old, excess elements from the end will be removed.

Exceptions
InsufficientMemoryException

Reimplemented in HephAudio::AudioBuffer.

◆ Reverse()

template<class Tself , typename Tdata >
virtual void Heph::BufferBase< Tself, Tdata >::Reverse ( )
inlinevirtual

reverses the buffer (first element to last and vice versa).

Reimplemented in HephAudio::AudioBuffer.

◆ begin()

template<class Tself , typename Tdata >
Tdata * Heph::BufferBase< Tself, Tdata >::begin ( ) const
inline

gets the pointer to the first element if buffer is not empty, otherwise nullptr.

◆ end()

template<class Tself , typename Tdata >
Tdata * Heph::BufferBase< Tself, Tdata >::end ( ) const
inline

gets the pointer to the end of the buffer (not the last element!) if buffer is not empty, otherwise nullptr.

◆ SizeAsByte() [2/2]

template<class Tself , typename Tdata >
static size_t Heph::BufferBase< Tself, Tdata >::SizeAsByte ( size_t size)
inlinestaticprotected

calculates the size in bytes.

Parameters
sizenumber of elements.

◆ Initialize() [1/2]

template<class Tself , typename Tdata >
template<typename U = Tdata>
static std::enable_if< std::is_class< U >::value >::type Heph::BufferBase< Tself, Tdata >::Initialize ( U * pData,
U * pDataEnd )
inlinestaticprotected

initializes the provided memory region.

Note
this will be used for the classes and structs.
Parameters
pDatastart of the memory region.
pDataEndend of the memory region.

◆ Initialize() [2/2]

template<class Tself , typename Tdata >
template<typename U = Tdata>
static std::enable_if<!std::is_class< U >::value >::type Heph::BufferBase< Tself, Tdata >::Initialize ( U * pData,
U * pDataEnd )
inlinestaticprotected

initializes the provided memory region.

Note
this will be used for the primitive types (int, float, enum...).
Parameters
pDatastart of the memory region.
pDataEndend of the memory region.

◆ Allocate()

template<class Tself , typename Tdata >
static Tdata * Heph::BufferBase< Tself, Tdata >::Allocate ( size_t size_byte)
inlinestaticprotected

allocates memory and initializes it.

Parameters
size_bytenumber of bytes to allocate.
Returns
pointer to the allocated memory.
Exceptions
InsufficientMemoryException

◆ AllocateUninitialized()

template<class Tself , typename Tdata >
static Tdata * Heph::BufferBase< Tself, Tdata >::AllocateUninitialized ( size_t size_byte)
inlinestaticprotected

allocates memory but does not initialize it.

Parameters
size_bytenumber of bytes to allocate.
Returns
pointer to the allocated memory.
Exceptions
InsufficientMemoryException

Member Data Documentation

◆ pData

template<class Tself , typename Tdata >
Tdata* Heph::BufferBase< Tself, Tdata >::pData
protected

pointer to the first element of the buffer, or nullptr if the buffer is empty.

◆ size

template<class Tself , typename Tdata >
size_t Heph::BufferBase< Tself, Tdata >::size
protected

number of elements the buffer stores.