DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
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 (size_t count, Memory::Region region, AllocContext ctx={})
 Allocates count elements. Check the result with if (!buffer).
 ~Buffer ()
 Buffer (Buffer &&other) noexcept
Buffer & operator= (Buffer &&other) noexcept
 Buffer (const Buffer &)=delete
Buffer & operator= (const Buffer &)=delete
bool Allocate (size_t count, Memory::Region region, AllocContext ctx={})
 Allocates count elements, replacing what it held.
void Reset ()
 Frees now rather than at scope exit.
T * Release ()
 Gives up ownership and returns the raw pointer, for handing the memory to something that frees it itself or outlives this object.
 operator bool () const
 True when this holds memory. The only check a caller needs.
T * Data ()
const T * Data () const
size_t Count () const
 Elements, not bytes.
size_t Bytes () const
bool Empty () const
T & operator[] (size_t i)
const T & operator[] (size_t i) const
T * begin ()
T * end ()
const T * begin () const
const T * end () const

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

◆ 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

◆ 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.

◆ Reset()

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

Frees now rather than at scope exit.

◆ 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.

◆ operator bool()

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

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

◆ 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

◆ Count()

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

Elements, not bytes.

◆ Bytes()

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

◆ Empty()

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

◆ 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

◆ begin() [1/2]

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

◆ end() [1/2]

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

◆ begin() [2/2]

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

◆ end() [2/2]

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

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