MxEngine
Classes | Public Types | Public Member Functions | List of all members
MxEngine::VectorPool< T, Container > Class Template Reference

#include <VectorPool.h>

Classes

class  PoolIterator
 

Public Types

using Allocator = PoolAllocator< T >
 
using Block = typename Allocator::Block
 

Public Member Functions

 VectorPool ()=default
 
 VectorPool (size_t count)
 
void Resize (size_t count)
 
size_t Allocated () const
 
size_t Capacity () const
 
T & operator[] (size_t index)
 
const T & operator[] (size_t index) const
 
void Clear ()
 
bool IsAllocated (size_t index)
 
void Deallocate (size_t index)
 
void Deallocate (const PoolIterator &it)
 
template<typename... Args>
size_t Allocate (Args &&... args)
 
size_t IndexOf (const T &obj)
 
PoolIterator begin ()
 
const PoolIterator begin () const
 
PoolIterator end ()
 
const PoolIterator end () const
 

Detailed Description

template<typename T, template< typename > typename Container = MxVector>
class MxEngine::VectorPool< T, Container >

VectorPool is an object Pool class which is used for fast allocations/deallocations of objects of type T objects are accessed by index in array and references should not be stored (as any allocation can potentially invalidate them) to check if object is allocated before access, use IsAllocated(index). To allocate use Allocate(args), to deallocate - Deallocate(index)

Constructor & Destructor Documentation

§ VectorPool() [1/2]

template<typename T, template< typename > typename Container = MxVector>
MxEngine::VectorPool< T, Container >::VectorPool ( )
default

constructs default vector Pool with zero capacity (no memory request to inner container)

§ VectorPool() [2/2]

template<typename T, template< typename > typename Container = MxVector>
MxEngine::VectorPool< T, Container >::VectorPool ( size_t  count)
inline

constructs vector Pool with count elements as capacity number of preallocated elements (not constructed)

Member Function Documentation

§ Allocate()

template<typename T, template< typename > typename Container = MxVector>
template<typename... Args>
size_t MxEngine::VectorPool< T, Container >::Allocate ( Args &&...  args)
inline

constructs element in vector Pool. If it has not enough space - Resize(bigger size) is called

Parameters
argsarguments for element constructor
Returns
index of element in vector Pool

§ Allocated()

template<typename T, template< typename > typename Container = MxVector>
size_t MxEngine::VectorPool< T, Container >::Allocated ( ) const
inline

gets how many elements are in use (constructed)

Returns
count of currently allocated elements

§ begin() [1/2]

template<typename T, template< typename > typename Container = MxVector>
PoolIterator MxEngine::VectorPool< T, Container >::begin ( )
inline

begin of vector Pool container

Returns
iterator to first allocated element or end iterator

§ begin() [2/2]

template<typename T, template< typename > typename Container = MxVector>
const PoolIterator MxEngine::VectorPool< T, Container >::begin ( ) const
inline

begin of vector Pool container

Returns
const iterator to first allocated element or const end iterator

§ Capacity()

template<typename T, template< typename > typename Container = MxVector>
size_t MxEngine::VectorPool< T, Container >::Capacity ( ) const
inline

gets total number of elements in the container

Returns
how many elements can potentially be stored in vector Pool

§ Clear()

template<typename T, template< typename > typename Container = MxVector>
void MxEngine::VectorPool< T, Container >::Clear ( )
inline

clears container. All constructed elements are destroyed

§ Deallocate()

template<typename T, template< typename > typename Container = MxVector>
void MxEngine::VectorPool< T, Container >::Deallocate ( size_t  index)
inline

destroys element in vector Pool

Parameters
indexindex of element to destroy

§ end() [1/2]

template<typename T, template< typename > typename Container = MxVector>
PoolIterator MxEngine::VectorPool< T, Container >::end ( )
inline

end of vector Pool container

Returns
iterator to the end of vector container

§ end() [2/2]

template<typename T, template< typename > typename Container = MxVector>
const PoolIterator MxEngine::VectorPool< T, Container >::end ( ) const
inline

end of vector Pool container

Returns
const iterator to the end of vector container

§ IndexOf()

template<typename T, template< typename > typename Container = MxVector>
size_t MxEngine::VectorPool< T, Container >::IndexOf ( const T &  obj)
inline

retrieves index of element in vector Pool by reference

Parameters
objelement of vector Pool
Returns
index of element in vector Pool
Warning
behaviour is undefined if Allocate() or Resize() were called between reference construction and IndexOf() call

§ IsAllocated()

template<typename T, template< typename > typename Container = MxVector>
bool MxEngine::VectorPool< T, Container >::IsAllocated ( size_t  index)
inline

checks if element is constructed

Parameters
indexindex of element in vector Pool
Returns
true if element is constructed, false either

§ operator[]() [1/2]

template<typename T, template< typename > typename Container = MxVector>
T& MxEngine::VectorPool< T, Container >::operator[] ( size_t  index)
inline

reference getter for element. Element must be contructed before call

Returns
reference to element in vector Pool

§ operator[]() [2/2]

template<typename T, template< typename > typename Container = MxVector>
const T& MxEngine::VectorPool< T, Container >::operator[] ( size_t  index) const
inline

const reference getter for element. Element must be contructed before call

Returns
const reference to element in vector Pool

§ Resize()

template<typename T, template< typename > typename Container = MxVector>
void MxEngine::VectorPool< T, Container >::Resize ( size_t  count)
inline

increases container size. If new count is less or equal than current, request is ignored

Parameters
newnumber of preallocated elements in container (not constructed)

The documentation for this class was generated from the following file: