DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches
Deki::Vector< T > Class Template Reference

Growable array of T whose growth can fail. More...

#include <deki/providers/Vector.h>

Public Member Functions

 Vector (Memory::Region region, AllocContext ctx={})
 Takes the memory region the storage lives in.
 Vector ()=delete
 ~Vector ()=default
 Vector (Vector &&other) noexcept
Vector & operator= (Vector &&other) noexcept
 Vector (const Vector &)=delete
Vector & operator= (const Vector &)=delete
bool Reserve (size_t count)
 Makes room for at least count elements in the constructor's region.
bool PushBack (const T &value)
 Appends a copy of value, growing if needed.
bool PopBack ()
 Drops the last element. False when there was none.
bool RemoveUnordered (size_t index)
 Removes the element at index and moves the last one into its place.
void Clear ()
 Empties the vector and keeps the memory, for refilling every frame.
void Reset ()
 Empties the vector and frees the memory.
size_t Size () const
size_t Capacity () const
bool Empty () const
T * Data ()
const T * Data () 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
T & Back ()
 The last element. The vector must not be empty.
const T & Back () const

Detailed Description

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

Growable array of T whose growth can fail.

Move-only, like Buffer: copying needs a second allocation that can fail, and a copy constructor cannot report that.

T must be trivially copyable and trivially destructible, which Buffer enforces. Growth moves elements with memcpy and destruction just frees the block, so these are lists of plain structs and handles.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename T>
Deki::Vector< T >::Vector ( Memory::Region region,
AllocContext ctx = {} )
inlineexplicit

Takes the memory region the storage lives in.

Required: the engine does not pick a region, so the declaration says what memory this list uses.

◆ Vector() [2/4]

template<typename T>
Deki::Vector< T >::Vector ( )
delete

◆ ~Vector()

template<typename T>
Deki::Vector< T >::~Vector ( )
default

◆ Vector() [3/4]

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

◆ Vector() [4/4]

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

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Reserve()

template<typename T>
bool Deki::Vector< T >::Reserve ( size_t count)
inline

Makes room for at least count elements in the constructor's region.

Call it once up front, where a failure is easy to handle; the PushBack calls within that capacity then cannot fail. Never shrinks. Returns true when the capacity is already enough.

◆ PushBack()

template<typename T>
bool Deki::Vector< T >::PushBack ( const T & value)
inline

Appends a copy of value, growing if needed.

Returns false when it could not grow; the vector is then unchanged.

Growth doubles (amortised O(1)) from a first block of 4. The first block is small because a device project has many short lists.

◆ PopBack()

template<typename T>
bool Deki::Vector< T >::PopBack ( )
inline

Drops the last element. False when there was none.

◆ RemoveUnordered()

template<typename T>
bool Deki::Vector< T >::RemoveUnordered ( size_t index)
inline

Removes the element at index and moves the last one into its place.

O(1) but changes the order, like ParticlePool's KillSwap. Returns false when index is out of range. To keep the order, rebuild the list.

◆ Clear()

template<typename T>
void Deki::Vector< T >::Clear ( )
inline

Empties the vector and keeps the memory, for refilling every frame.

◆ Reset()

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

Empties the vector and frees the memory.

◆ Size()

template<typename T>
size_t Deki::Vector< T >::Size ( ) const
inline

◆ Capacity()

template<typename T>
size_t Deki::Vector< T >::Capacity ( ) const
inline

◆ Empty()

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

◆ Data() [1/2]

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

◆ Data() [2/2]

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

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

◆ begin() [1/2]

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

◆ end() [1/2]

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

◆ begin() [2/2]

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

◆ end() [2/2]

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

◆ Back() [1/2]

template<typename T>
T & Deki::Vector< T >::Back ( )
inline

The last element. The vector must not be empty.

◆ Back() [2/2]

template<typename T>
const T & Deki::Vector< T >::Back ( ) const
inline

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