EntropyEngine::Core::SlotPool
EntropyEngine::Core::SlotPool
Section titled “EntropyEngine::Core::SlotPool”Slot-based pool with generation-based handle validation. More…
#include <SlotPool.h>
Public Classes
Section titled “Public Classes”| Name | |
|---|---|
| struct | Slot Internal slot structure combining generation tracking with user data. |
| struct | AllocResult Result of allocate() containing slot index and data reference. |
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| template <typename T > void | stamp(T & obj, uint32_t index) Stamps an EntropyObject with this pool’s identity. |
| template <typename T > void | release(T & obj, uint32_t index) Releases a slot back to the pool. |
| template <typename T > bool | isValid(const T * obj, uint32_t index) const Validates an object against its expected slot. |
| bool | isActive(uint32_t index) const Checks if a slot is currently active (allocated). |
| template <typename T > const SlotData * | getIfValid(const T * obj) const Validates an object and returns its slot data if valid. |
| uint32_t | generation(uint32_t index) const Gets a slot’s current generation. |
| size_t | freeCount() const |
| template <typename Fn > void | forEachActive(Fn && fn) Iterates over all active slots. |
| template <typename Fn > void | forEachActive(Fn && fn) const Iterates over all active slots (const). |
| size_t | capacity() const |
| SlotData & | at(uint32_t index) Gets a slot’s data by index (unsafe - no validation). |
| const SlotData & | at(uint32_t index) const Gets a slot’s data by index (const, unsafe - no validation). |
| std::optional< AllocResult > | allocate() Allocates a slot from the pool. |
| size_t | activeCount() const |
| SlotPool(size_t capacity) Constructs a pool with the given capacity. |
Detailed Description
Section titled “Detailed Description”template <typename SlotData >class EntropyEngine::Core::SlotPool;Slot-based pool with generation-based handle validation.
Template Parameters:
- SlotData User-defined data stored in each slot (will be default-constructed)
Thread Safety:
- All public methods are thread-safe (protected by internal mutex)
- SlotData must be safe to access under the returned lock guard
Public Functions Documentation
Section titled “Public Functions Documentation”function stamp
Section titled “function stamp”template <typename T >inline void stamp( T & obj, uint32_t index)Stamps an EntropyObject with this pool’s identity.
Parameters:
- obj Object to stamp
- index Slot index from allocate()
Template Parameters:
- T EntropyObject-derived type
Call this after allocate() to establish the object’s handle identity.
function release
Section titled “function release”template <typename T >inline void release( T & obj, uint32_t index)Releases a slot back to the pool.
Parameters:
- obj Object to release
- index Slot index
Template Parameters:
- T EntropyObject-derived type
Clears the object’s handle stamp and increments the slot’s generation to invalidate any stale references.
function isValid
Section titled “function isValid”template <typename T >inline bool isValid( const T * obj, uint32_t index) constValidates an object against its expected slot.
Parameters:
- obj Object to validate (may be null)
- index Expected slot index
Template Parameters:
- T EntropyObject-derived type
Return: true if object is valid for this slot
function isActive
Section titled “function isActive”inline bool isActive( uint32_t index) constChecks if a slot is currently active (allocated).
Parameters:
- index Slot index
Return: true if slot is active
function getIfValid
Section titled “function getIfValid”template <typename T >inline const SlotData * getIfValid( const T * obj) constValidates an object and returns its slot data if valid.
Parameters:
- obj Object to validate
Template Parameters:
- T EntropyObject-derived type
Return: Pointer to slot data, or nullptr if invalid
Convenience method that combines validation with data access.
function generation
Section titled “function generation”inline uint32_t generation( uint32_t index) constGets a slot’s current generation.
Parameters:
- index Slot index
Return: Current generation value
function freeCount
Section titled “function freeCount”inline size_t freeCount() constfunction forEachActive
Section titled “function forEachActive”template <typename Fn >inline void forEachActive( Fn && fn)Iterates over all active slots.
Parameters:
- fn Callback receiving (index, SlotData&) for each active slot
function forEachActive
Section titled “function forEachActive”template <typename Fn >inline void forEachActive( Fn && fn) constIterates over all active slots (const).
function capacity
Section titled “function capacity”inline size_t capacity() constfunction at
Section titled “function at”inline SlotData & at( uint32_t index)Gets a slot’s data by index (unsafe - no validation).
Parameters:
- index Slot index
Return: Reference to slot data
Use isValid() first, or prefer getIfValid() for safe access.
function at
Section titled “function at”inline const SlotData & at( uint32_t index) constGets a slot’s data by index (const, unsafe - no validation).
function allocate
Section titled “function allocate”inline std::optional< AllocResult > allocate()Allocates a slot from the pool.
Return: Optional containing (index, data reference), or nullopt if pool is full
function activeCount
Section titled “function activeCount”inline size_t activeCount() constfunction SlotPool
Section titled “function SlotPool”inline explicit SlotPool( size_t capacity)Constructs a pool with the given capacity.
Parameters:
- capacity Maximum number of slots
Slots are default-constructed immediately. Use init() for lazy initialization if SlotData requires external dependencies.
Updated on 2026-01-26 at 16:50:32 -0500