Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Foundation::Core::Pool< K, V > Class Template Reference

Unbounded object pool with O(1) value mapping. More...

#include <Pool.hpp>

Public Member Functions

 Pool (Allocator *alloc)
 
bool Contains (K key) const
 Checks if the specified key exists and has a value.
 
VAt (K key) const
 Retrieves a reference to the value associated with the given key. NOTE: Calling this function with a key that's not retrieved from pop() is undefined behavior.
 
template<typename... Args>
K Pop (Args &&... args)
 Allocates a new key in the pool and constructs the object in-place.
 
template<typename Derived , typename... Args>
K PopBase (Args &&... args)
 Allocates a new key in the pool and constructs a derived object in-place.
 
void Free (K key)
 Frees the value associated with the specified key.
 

Private Member Functions

void Push (K key)
 Adds a key to the internal key container and resizes the value container if necessary.
 
void CheckContains (K key) const
 
K PopKey ()
 

Private Attributes

AllocatormAlloc
 
Vector< KmKeys
 
Vector< UniquePtr< V > > mValues
 
std::mutex mMutex
 
K mTop {}
 

Detailed Description

template<typename K, typename V>
class Foundation::Core::Pool< K, V >

Unbounded object pool with O(1) value mapping.

Template Parameters
KKey type. Should be an integral type.
VValue type.
Note
The values are allocated using the provided Allocator, and is guaranteed to have a stable address until freed.
An atomic, bounded version of this is provided by Foundation::Atomics::Pool

Constructor & Destructor Documentation

◆ Pool()

template<typename K , typename V >
Foundation::Core::Pool< K, V >::Pool ( Allocator alloc)
inline

Member Function Documentation

◆ At()

template<typename K , typename V >
V * Foundation::Core::Pool< K, V >::At ( K  key) const
inline

Retrieves a reference to the value associated with the given key. NOTE: Calling this function with a key that's not retrieved from pop() is undefined behavior.

◆ CheckContains()

template<typename K , typename V >
void Foundation::Core::Pool< K, V >::CheckContains ( K  key) const
inlineprivate

◆ Contains()

template<typename K , typename V >
bool Foundation::Core::Pool< K, V >::Contains ( K  key) const
inline

Checks if the specified key exists and has a value.

◆ Free()

template<typename K , typename V >
void Foundation::Core::Pool< K, V >::Free ( K  key)
inline

Frees the value associated with the specified key.

◆ Pop()

template<typename K , typename V >
template<typename... Args>
K Foundation::Core::Pool< K, V >::Pop ( Args &&...  args)
inline

Allocates a new key in the pool and constructs the object in-place.

◆ PopBase()

template<typename K , typename V >
template<typename Derived , typename... Args>
K Foundation::Core::Pool< K, V >::PopBase ( Args &&...  args)
inline

Allocates a new key in the pool and constructs a derived object in-place.

Template Parameters
DerivedThe derived type to construct, based on the base type V.

◆ PopKey()

template<typename K , typename V >
K Foundation::Core::Pool< K, V >::PopKey ( )
inlineprivate

◆ Push()

template<typename K , typename V >
void Foundation::Core::Pool< K, V >::Push ( K  key)
inlineprivate

Adds a key to the internal key container and resizes the value container if necessary.

Member Data Documentation

◆ mAlloc

template<typename K , typename V >
Allocator* Foundation::Core::Pool< K, V >::mAlloc
private

◆ mKeys

template<typename K , typename V >
Vector<K> Foundation::Core::Pool< K, V >::mKeys
private

◆ mMutex

template<typename K , typename V >
std::mutex Foundation::Core::Pool< K, V >::mMutex
mutableprivate

◆ mTop

template<typename K , typename V >
K Foundation::Core::Pool< K, V >::mTop {}
private

◆ mValues

template<typename K , typename V >
Vector<UniquePtr<V> > Foundation::Core::Pool< K, V >::mValues
mutableprivate

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