DEKI/ENGINE docs
manual api reference
Deki 0.40.1
Modular C++ engine with a visual editor, for 2D and 3D
Loading...
Searching...
No Matches
Deki::Buffer< T > Class Template Reference

Owning array of T, freed when it goes out of scope. More...

#include <deki/providers/Buffer.h>

Public Member Functions

 Buffer ()=default
 Buffer (Buffer &&other) noexcept
 Buffer (const Buffer &)=delete
 Buffer (size_t count, Memory::Region region, AllocContext ctx={})
 Allocates count elements. Check the result with if (!buffer).
 ~Buffer ()
bool Allocate (size_t count, Memory::Region region, AllocContext ctx={})
 Allocates count elements, replacing what it held.
T * begin ()
const T * begin () const
size_t Bytes () const
size_t Count () const
 Elements, not bytes.
T * Data ()
const T * Data () const
bool Empty () const
T * end ()
const T * end () const
 operator bool () const
 True when this holds memory. The only check a caller needs.
Buffer & operator= (Buffer &&other) noexcept
Buffer & operator= (const Buffer &)=delete
T & operator[] (size_t i)
const T & operator[] (size_t i) const
T * Release ()
 Gives up ownership and returns the raw pointer, for handing the memory to something that frees it itself or outlives this object.
void Reset ()
 Frees now rather than at scope exit.

Detailed Description

template<typename T>
class Deki::Buffer< T >

Owning array of T, freed when it goes out of scope.

Move-only: a copy would need a second allocation that could fail, which a copy constructor cannot report.

For raw pixel, glyph and sample data handed to blitters and drivers. It never constructs or destroys elements (Memory returns them zeroed), so T must be trivially copyable and destructible; the static_asserts enforce it.

Constructor & Destructor Documentation

◆ Buffer() [1/4]

template<typename T>
Deki::Buffer< T >::Buffer ( )
default

◆ Buffer() [2/4]

template<typename T>
Deki::Buffer< T >::Buffer ( size_t count,
Memory::Region region,
AllocContext ctx = {} )
inline

Allocates count elements. Check the result with if (!buffer).

◆ ~Buffer()

template<typename T>
Deki::Buffer< T >::~Buffer ( )
inline

◆ Buffer() [3/4]

template<typename T>
Deki::Buffer< T >::Buffer ( Buffer< T > && other)
inlinenoexcept

◆ Buffer() [4/4]

template<typename T>
Deki::Buffer< T >::Buffer ( const Buffer< T > & )
delete

Member Function Documentation

◆ Allocate()

template<typename T>
bool Deki::Buffer< T >::Allocate ( size_t count,
Memory::Region region,
AllocContext ctx = {} )
inline

Allocates count elements, replacing what it held.

Returns false on failure.

The old contents are freed first, not copied: callers overwrite the buffer right away, and a copy would need both allocations at once. An unchanged count keeps the existing memory, so calling this every frame from a render path is cheap.

◆ begin() [1/2]

template<typename T>
T * Deki::Buffer< T >::begin ( )
inline

◆ begin() [2/2]

template<typename T>
const T * Deki::Buffer< T >::begin ( ) const
inline

◆ Bytes()

template<typename T>
size_t Deki::Buffer< T >::Bytes ( ) const
inline

◆ Count()

template<typename T>
size_t Deki::Buffer< T >::Count ( ) const
inline

Elements, not bytes.

◆ Data() [1/2]

template<typename T>
T * Deki::Buffer< T >::Data ( )
inline

◆ Data() [2/2]

template<typename T>
const T * Deki::Buffer< T >::Data ( ) const
inline

◆ Empty()

template<typename T>
bool Deki::Buffer< T >::Empty ( ) const
inline

◆ end() [1/2]

template<typename T>
T * Deki::Buffer< T >::end ( )
inline

◆ end() [2/2]

template<typename T>
const T * Deki::Buffer< T >::end ( ) const
inline

◆ operator bool()

template<typename T>
Deki::Buffer< T >::operator bool ( ) const
inlineexplicit

True when this holds memory. The only check a caller needs.

◆ operator=() [1/2]

template<typename T>
Buffer & Deki::Buffer< T >::operator= ( Buffer< T > && other)
inlinenoexcept

◆ operator=() [2/2]

template<typename T>
Buffer & Deki::Buffer< T >::operator= ( const Buffer< T > & )
delete

◆ operator[]() [1/2]

template<typename T>
T & Deki::Buffer< T >::operator[] ( size_t i)
inline

◆ operator[]() [2/2]

template<typename T>
const T & Deki::Buffer< T >::operator[] ( size_t i) const
inline

◆ Release()

template<typename T>
T * Deki::Buffer< T >::Release ( )
inline

Gives up ownership and returns the raw pointer, for handing the memory to something that frees it itself or outlives this object.

The caller must then call Deki::Memory::Free. Rarely needed.

◆ Reset()

template<typename T>
void Deki::Buffer< T >::Reset ( )
inline

Frees now rather than at scope exit.


The documentation for this class was generated from the following file:
  • deki-engine/include/deki/providers/Buffer.h