Nebula
Loading...
Searching...
No Matches
Ids::IdAllocator< TYPES > Class Template Reference

#include <idallocator.h>

Detailed Description

template<class ... TYPES>
class Ids::IdAllocator< TYPES >

An ID allocator associates an id with a slice in an N number of arrays.

There are two versions of this type, an unsafe and a safe one. Both are implemented in the same way, providing a variadic list of types which is to be contained in the allocator and fetching each value by providing the index into the list of types, which means the members are nameless.

The thread safe allocator requires the Get-methods to be within an Enter/Leave lockstep phase.

Inherits Util::ArrayAllocator< TYPES... >.

Public Member Functions

 IdAllocator (uint32_t maxid=0xFFFFFFFF)
 constructor
 
Ids::Id32 Alloc ()
 Allocate an object.
 
void Dealloc (Ids::Id32 id)
 Deallocate an object. Just places it in freeids array for recycling.
 
template<int MEMBER>
void Set (const Ids::Id32 id, const Util::tuple_array_t< MEMBER, TYPES... > &type)
 Set element.
 
void Set (const Ids::Id32 id, TYPES... values)
 Set elements.
 
template<int MEMBER>
Util::tuple_array_t< MEMBER, TYPES... > & Get (const Ids::Id32 id)
 Get element.
 
template<int MEMBER>
const Util::tuple_array_t< MEMBER, TYPES... > & ConstGet (const Ids::Id32 id) const
 Const get element.
 
Util::Queue< Id32 > & FreeIds ()
 Get the free ids list from the pool.
 
const uint32_t Size () const
 return number of allocated ids
 
- Public Member Functions inherited from Util::ArrayAllocator< TYPES... >
 ArrayAllocator ()
 constructor
 
 ArrayAllocator (ArrayAllocator< TYPES... > &&rhs)
 move constructor
 
 ArrayAllocator (const ArrayAllocator< TYPES... > &rhs)
 copy constructor
 
 ~ArrayAllocator ()
 destructor
 
void operator= (const ArrayAllocator< TYPES... > &rhs)
 assign operator
 
void operator= (ArrayAllocator< TYPES... > &&rhs)
 move operator
 
uint32_t Alloc ()
 allocate a new resource
 
void EraseIndex (const uint32_t id)
 Erase element for each.
 
void EraseIndexSwap (const uint32_t id)
 Erase element for each.
 
void EraseRange (const uint32_t start, const uint32_t end)
 erase range
 
tuple_array_t< MEMBER, TYPES... > & Get (const uint32_t index)
 get single item from resource
 
const tuple_array_t< MEMBER, TYPES... > & ConstGet (const uint32_t index) const
 same as 32 bit get, but const
 
void Set (const uint32_t index, const tuple_array_t< MEMBER, TYPES... > &type)
 set single item
 
void Set (const uint32_t index, TYPES...)
 set for each in tuple
 
const Util::Array< tuple_array_t< MEMBER, TYPES... > > & GetArray () const
 get array const reference
 
Util::Array< tuple_array_t< MEMBER, TYPES... > > & GetArray ()
 get array
 
const uint32_t Size () const
 get number of used indices
 
void Reserve (uint32_t size)
 grow capacity of arrays to size
 
void SetSize (uint32_t size)
 set size of arrays to param size
 
void Clear ()
 clear entire allocator and start from scratch.
 
void UpdateSize ()
 Any reserve and direct array access might mess with the size.
 

Private Attributes

uint32_t maxId = 0xFFFFFFFF
 
Ids::IdGenerationPool pool
 

Additional Inherited Members

- Protected Attributes inherited from Util::ArrayAllocator< TYPES... >
uint32_t size
 
std::tuple< Util::Array< TYPES >... > objects
 

Constructor & Destructor Documentation

◆ IdAllocator()

template<class ... TYPES>
Ids::IdAllocator< TYPES >::IdAllocator ( uint32_t maxid = 0xFFFFFFFF)
inline

constructor

Member Function Documentation

◆ Alloc()

template<class ... TYPES>
Ids::Id32 Ids::IdAllocator< TYPES >::Alloc ( )
inline

Allocate an object.

Note
This purposefully hides the default allocation method and should definetly not be virtual!

◆ ConstGet()

template<class ... TYPES>
template<int MEMBER>
const Util::tuple_array_t< MEMBER, TYPES... > & Ids::IdAllocator< TYPES >::ConstGet ( const Ids::Id32 id) const
inline

Const get element.

◆ Dealloc()

template<class ... TYPES>
void Ids::IdAllocator< TYPES >::Dealloc ( Ids::Id32 id)
inline

Deallocate an object. Just places it in freeids array for recycling.

◆ FreeIds()

template<class ... TYPES>
Util::Queue< Id32 > & Ids::IdAllocator< TYPES >::FreeIds ( )
inline

Get the free ids list from the pool.

◆ Get()

template<class ... TYPES>
template<int MEMBER>
Util::tuple_array_t< MEMBER, TYPES... > & Ids::IdAllocator< TYPES >::Get ( const Ids::Id32 id)
inline

Get element.

◆ Set() [1/2]

template<class ... TYPES>
template<int MEMBER>
void Ids::IdAllocator< TYPES >::Set ( const Ids::Id32 id,
const Util::tuple_array_t< MEMBER, TYPES... > & type )
inline

Set element.

◆ Set() [2/2]

template<class ... TYPES>
void Ids::IdAllocator< TYPES >::Set ( const Ids::Id32 id,
TYPES... values )
inline

Set elements.

◆ Size()

template<class ... TYPES>
const uint32_t Ids::IdAllocator< TYPES >::Size ( ) const
inline

return number of allocated ids

Member Data Documentation

◆ maxId

template<class ... TYPES>
uint32_t Ids::IdAllocator< TYPES >::maxId = 0xFFFFFFFF
private

◆ pool

template<class ... TYPES>
Ids::IdGenerationPool Ids::IdAllocator< TYPES >::pool
private

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