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::Vector< T > Class Template Reference

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

#include <deki/providers/Vector.h>

Public Member Functions

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

◆ 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

◆ begin() [1/2]

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

◆ begin() [2/2]

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

◆ Capacity()

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

◆ Clear()

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

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

◆ 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

◆ Empty()

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

◆ end() [1/2]

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

◆ end() [2/2]

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ 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

◆ PopBack()

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

Drops the last element. False when there was none.

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

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

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

◆ 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

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