xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize > Class Template Referencefinal

A buffer that can be resized if buffer space runs out. More...

#include <xentara/utils/memory/ResizableBuffer.hpp>

+ Inheritance diagram for xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >:

Public Member Functions

 ResizableBuffer ()=default
 Default constructor.
 
 ResizableBuffer (SizeType minimumSize) noexcept
 Constructor that allocates data.
 
internal constexpr auto data () noexcept -> Element *
 Gets the data.
 
constexpr auto data () const noexcept -> const Element *
 Gets the data.
 
constexpr auto size () const noexcept -> SizeType
 Gets the size.
 
constexpr auto empty () const noexcept -> bool
 Checks if the buffer has size 0.
 
auto resize (SizeType minimumSize) -> void
 Resizes the buffer.
 
auto grow () -> void
 Grows the buffer geometrically.
 

Detailed Description

template<typename Element, std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
requires std::is_trivial_v<Element>
class xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >

A buffer that can be resized if buffer space runs out.

This class can be used to call functions that require a preallocated buffer. Such functions often return an error code like ERANGE or ERROR_INSUFFICIENT_BUFFER if the buffer is too small. This class then allows you to resize the buffer and try again.

This class can also optionally use short data optimization by spacifying a shortt data size in the kShortDataSize template parameter.

Template Parameters
ElementThe elements the buffer should hold
SizeTypeThe type to use for the size
kShortDataSizeThe short data size to use for short data optimization, or 0 to omit short data optimization

Constructor & Destructor Documentation

◆ ResizableBuffer() [1/2]

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::ResizableBuffer ( )
default

Default constructor.

This constructor constructs a buffer with a size of kShortDataSize.

◆ ResizableBuffer() [2/2]

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::ResizableBuffer ( SizeType  minimumSize)
noexcept

Constructor that allocates data.

This constructor constructs a buffer with a certain minimum size. The actual size will never be smaller than kShortDataSize, however.

Parameters
minimumSizeThe minimum size for the buffer

Member Function Documentation

◆ data() [1/2]

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
constexpr auto xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::data ( ) const -> const Element *
constexprnoexcept

Gets the data.

Returns
The buffer data, or nullptr if the buffer is empty

◆ data() [2/2]

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
internal constexpr auto xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::data ( ) -> Element *
constexprnoexcept

Gets the data.

Returns
The buffer data, or nullptr if the buffer is empty

◆ empty()

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
constexpr auto xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::empty ( ) const -> bool
constexprnoexcept

Checks if the buffer has size 0.

◆ grow()

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
auto xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::grow ( ) -> void

Grows the buffer geometrically.

This function resizes the buffer geometrically, destroying its content.

Attention
The data in the buffer is not preserved. All existing data in the buffer is lost.
Exceptions
std::length_errorThe buffer has already reached its maximum size
std::bad_allocMemory could not be allocated

◆ resize()

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
auto xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::resize ( SizeType  minimumSize) -> void

Resizes the buffer.

This function resizes the buffer, destroying its content. The size of the buffer is only ever increased, never decreased.

Attention
The data in the buffer is not preserved. All existing data in the buffer is lost if the buffer size increases.
Parameters
minimumSizeThe minimum size for the buffer
Exceptions
std::length_errorThe system does not support allocating the required number of elements
std::bad_allocMemory could not be allocated

◆ size()

template<typename Element , std::integral SizeType = std::size_t, SizeType kShortDataSize = SizeType(0)>
constexpr auto xentara::utils::memory::ResizableBuffer< Element, SizeType, kShortDataSize >::size ( ) const -> SizeType
constexprnoexcept

Gets the size.