← API Reference Class

template<typename T, std::size_t Nc = asge::ecs::kMaxEntities, std::size_t Ne = asge::ecs::kMaxEntities> asge::ecs::ComponentPool final

Fixed-capacity sparse-set storage of one component type per Entity.

#include <ComponentPool.hpp>

Inherits from asge::ecs::IComponentPool.

Inheritance

classDiagram
    class N1["asge::ecs::ComponentPool"]
    class N2["asge::ecs::IComponentPool"]
    N2 <|-- N1
    click N1 href "classasge_1_1ecs_1_1ComponentPool.html"
    click N2 href "classasge_1_1ecs_1_1IComponentPool.html"

Collaboration

classDiagram
    class N1["asge::ecs::ComponentPool"]
    class N2["asge::ecs::IComponentPool"]
    N2 <|-- N1
    click N1 href "classasge_1_1ecs_1_1ComponentPool.html"
    click N2 href "classasge_1_1ecs_1_1IComponentPool.html"

Maps each entity index to a densely-packed component array, so Insert, Get, Remove and Contains are all O(1) and iteration only ever touches live components. Removal is swap-and-pop, so iteration order can change after a Remove() call.

Warning

Components are tracked by entity index alone, not generation: this pool is never notified when an entity is destroyed, so a recycled index will alias its previous occupant's component unless the caller removes it first.

Template Parameters
T

Component type; must be default-constructible and move-assignable.

Ne

Number of distinct entity indices this pool can address.

Nc

Maximum number of components concurrently stored.

Public Types

#using iterator = _Iterator
#using component_ref = std::reference_wrapper< T >
#using const_component_ref = std::reference_wrapper< T const >

Private Attributes

#std::array< std::size_t, Ne > m_Sparse {}private
#std::array< Entity, Nc > m_DenseEntity {}private
#std::array< T, Nc > m_DenseComponent {}private
#std::size_t m_FreeComponentHead {0}private

Public Member Functions

#ComponentPool()
#ComponentPool(ComponentPool const &)=delete
#ComponentPool(ComponentPool &&)=default
#ComponentPool & operator=(ComponentPool const &)=delete
#ComponentPool & operator=(ComponentPool &&)=default
#Result< component_ref > Insert(Entity inEntity, T inComponent)

Attaches inEntity's component, replacing it if one already exists.

Reuses the entity's existing slot if it already has a component here, otherwise claims a fresh one.

Returns

A reference to the stored component, or an error if inEntity's index is out of range or the pool is full.

#virtual bool Contains(Entity inEntity) const noexcept override

Checks whether inEntity currently has a component in this pool.

Overrides Contains
#Result< const_component_ref > Get(Entity inEntity) const noexcept

Looks up inEntity's component (read-only).

Returns

A const reference to the component, or an error if inEntity has none.

#Result< component_ref > Get(Entity inEntity) noexcept

Looks up inEntity's component.

Implemented in terms of the const overload above (then const_cast-ing the result back to mutable) rather than duplicating the lookup logic — safe here because *this is genuinely non-const at the call site.

Returns

A reference to the component, or an error if inEntity has none.

#virtual BoolResult Remove(Entity inEntity) noexcept override

Detaches inEntity's component, if any.

Swaps the removed slot with the last dense component to keep storage packed, so iteration order may change after this call.

Returns

Ok on success, or an error if inEntity has no component here.

Overrides Remove
#virtual std::size_t Size() const noexcept override

Returns the total number of components associated with entities.

Overrides Size
#virtual std::span< Entity const > Entities() const noexcept override

Returns a view over all entities in the pool.

Overrides Entities
#iterator begin()

Iterates all (Entity, T&) pairs currently stored, in dense order.

#iterator end()