fennec
Loading...
Searching...
No Matches
fennec::object_pool< TypeT, AllocT >

Struct which holds a pool of objects associated with ids. More...

#include <object_pool.h>

Detailed Description

template<typename TypeT, typename AllocT = allocator<TypeT>>
struct fennec::object_pool< TypeT, AllocT >
Template Parameters
TypeTThe value type
AllocTThe allocator type

Public Member Functions

Constructors & Destructor
constexpr object_pool ()
 Default Constructor, initializes an empty object pool.
 
constexpr ~object_pool ()=default
 Default Destructor, destructs objects then releases the allocation.
 
Properties
constexpr size_t size () const
 
constexpr size_t capacity () const
 
constexpr bool empty () const
 
constexpr size_t next_id () const
 Retrieve the next id i that would be assigned to an object o were it added to the object pool.
 
Access
constexpr value_t & operator[] (size_t i)
 Array Access Operator.
 
constexpr const value_t & operator[] (size_t i) const
 Array Const Access Operator.
 
Modifiers
constexpr size_t insert (value_t &&x)
 Move Insertion, inserts x into the pool.
 
constexpr size_t insert (const value_t &x)
 Move Insertion, inserts a copy of x into the pool.
 
template<typename... ArgsT>
constexpr size_t emplace (ArgsT &&...args)
 Emplacement, constructs a new object using args...
 
constexpr void erase (size_t i)
 Erase an object from the pool.
 
constexpr void clear ()
 Clear the object pool.
 

Member Function Documentation

◆ size()

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr size_t fennec::object_pool< TypeT, AllocT >::size ( ) const
inlineconstexpr
Returns
The number of active objects in the pool

◆ capacity()

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr size_t fennec::object_pool< TypeT, AllocT >::capacity ( ) const
inlineconstexpr
Returns
The capacity of the underlying allocation

◆ empty()

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr bool fennec::object_pool< TypeT, AllocT >::empty ( ) const
inlineconstexpr
Returns
true when there are no objects in the pool, false otherwise

◆ next_id()

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr size_t fennec::object_pool< TypeT, AllocT >::next_id ( ) const
inlineconstexpr

This can be useful if there are constant members that need to be assigned at construction.

Returns
The id of the next inserted node

◆ operator[]() [1/2]

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr value_t & fennec::object_pool< TypeT, AllocT >::operator[] ( size_t  i)
inlineconstexpr
Parameters
iid of the object
Returns
a reference to the object with id i

◆ operator[]() [2/2]

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr const value_t & fennec::object_pool< TypeT, AllocT >::operator[] ( size_t  i) const
inlineconstexpr
Parameters
iid of the object
Returns
a const-qualified reference to the object with id i

◆ insert() [1/2]

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr size_t fennec::object_pool< TypeT, AllocT >::insert ( value_t &&  x)
inlineconstexpr
Parameters
xthe object to move
Returns
An integer corresponding to the id of the node

◆ insert() [2/2]

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr size_t fennec::object_pool< TypeT, AllocT >::insert ( const value_t &  x)
inlineconstexpr
Parameters
xthe object to copy
Returns
An integer corresponding to the id of the node

◆ emplace()

template<typename TypeT , typename AllocT = allocator<TypeT>>
template<typename... ArgsT>
constexpr size_t fennec::object_pool< TypeT, AllocT >::emplace ( ArgsT &&...  args)
inlineconstexpr
Parameters
argsThe arguments to construct the new object with
Returns
An integer corresponding to the id of the node

◆ erase()

template<typename TypeT , typename AllocT = allocator<TypeT>>
constexpr void fennec::object_pool< TypeT, AllocT >::erase ( size_t  i)
inlineconstexpr
Parameters
iThe id of the object

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