Gamedev Framework (gf) 1.2.0
A C++17 framework for 2D games
Classes | Public Member Functions | List of all members
gf::BlockAllocator< T > Class Template Reference

An allocator of objects referenced by an index. More...

#include <gf/BlockAllocator.h>

Public Member Functions

 BlockAllocator ()
 Default constructor. More...
 
std::size_t allocate ()
 Allocate an object. More...
 
void dispose (std::size_t index)
 Deallocate the object at the given index. More...
 
T & operator[] (std::size_t index)
 Access the object at a given index. More...
 
const T & operator[] (std::size_t index) const
 Access the object at a given index. More...
 
void clear ()
 Remove all objects at once. More...
 
std::size_t getAllocated () const
 Get the number of allocated objects. More...
 

Detailed Description

template<typename T>
class gf::BlockAllocator< T >

An allocator of objects referenced by an index.

Constructor & Destructor Documentation

◆ BlockAllocator()

template<typename T >
gf::BlockAllocator< T >::BlockAllocator ( )
inline

Default constructor.

Member Function Documentation

◆ allocate()

template<typename T >
std::size_t gf::BlockAllocator< T >::allocate ( )
inline

Allocate an object.

Returns
The index representing the object

◆ clear()

template<typename T >
void gf::BlockAllocator< T >::clear ( )
inline

Remove all objects at once.

◆ dispose()

template<typename T >
void gf::BlockAllocator< T >::dispose ( std::size_t  index)
inline

Deallocate the object at the given index.

After this function call, the index is not valid anymore.

Parameters
indexA valid index

◆ getAllocated()

template<typename T >
std::size_t gf::BlockAllocator< T >::getAllocated ( ) const
inline

Get the number of allocated objects.

Returns
The number of allocated objects

◆ operator[]() [1/2]

template<typename T >
T & gf::BlockAllocator< T >::operator[] ( std::size_t  index)
inline

Access the object at a given index.

Parameters
indexA valid index

◆ operator[]() [2/2]

template<typename T >
const T & gf::BlockAllocator< T >::operator[] ( std::size_t  index) const
inline

Access the object at a given index.

Parameters
indexA valid index