guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::ecs::ComponentStorage< ComponentType > Class Template Reference

Holds every component of one type, indexed by entity identifier. More...

#include <headers/guillaume/ecs/component_storage.hpp>

Inheritance diagram for guillaume::ecs::ComponentStorage< ComponentType >:
Collaboration diagram for guillaume::ecs::ComponentStorage< ComponentType >:

Public Types

using Storage = std::unordered_map<Entity::Identifier, ComponentType>
 The container: one component per entity identifier.

Public Member Functions

 ComponentStorage (void)=default
 Create an empty storage.
 ~ComponentStorage (void) override=default
 Destroy the storage and every component it holds.
template<typename... Args>
ComponentType & emplace (const Entity::Identifier &entityIdentifier, Args &&...args)
 Construct a component for an entity, replacing the one it already has, if any.
ComponentType * find (const Entity::Identifier &entityIdentifier)
 Look up the component of an entity.
const ComponentType * find (const Entity::Identifier &entityIdentifier) const
 Look up the component of an entity, read-only.
void remove (const Entity::Identifier &entityIdentifier) override
 Delete the component stored for an entity. Does nothing when the entity has none.
bool has (const Entity::Identifier &entityIdentifier) const override
 Tell whether a component is stored for an entity.
bool hasChanged (const Entity::Identifier &entityIdentifier) const override
 Tell whether the component stored for an entity is marked as changed.
void resetChangedFlags (void) override
 Mark every component of this storage as unchanged.
Public Member Functions inherited from guillaume::ecs::IComponentStorage
virtual ~IComponentStorage (void)=default
 Virtual destructor.

Detailed Description

template<InheritFromComponent ComponentType>
class guillaume::ecs::ComponentStorage< ComponentType >

Holds every component of one type, indexed by entity identifier.

ComponentRegistry creates one storage per component type the first time that type is used. Application code goes through the registry and does not use this class directly.

Note
Pointers and references to a stored component stay valid until that component is removed or replaced; adding components for other entities does not move it.
Template Parameters
ComponentTypeThe component type stored.
See also
ComponentRegistry

Definition at line 94 of file component_storage.hpp.

Member Typedef Documentation

◆ Storage

template<InheritFromComponent ComponentType>
using guillaume::ecs::ComponentStorage< ComponentType >::Storage = std::unordered_map<Entity::Identifier, ComponentType>

The container: one component per entity identifier.

Definition at line 101 of file component_storage.hpp.

Member Function Documentation

◆ emplace()

template<InheritFromComponent ComponentType>
template<typename... Args>
ComponentType & guillaume::ecs::ComponentStorage< ComponentType >::emplace ( const Entity::Identifier & entityIdentifier,
Args &&... args )

Construct a component for an entity, replacing the one it already has, if any.

Template Parameters
ArgsThe types of the constructor arguments.
Parameters
entityIdentifierThe identifier of the entity.
argsArguments forwarded to the constructor of ComponentType; none builds a default component.
Returns
Reference to the stored component.
Note
When the entity already has a component, a new one is constructed and assigned over it: the previous values are lost.

◆ find() [1/2]

template<InheritFromComponent ComponentType>
ComponentType * guillaume::ecs::ComponentStorage< ComponentType >::find ( const Entity::Identifier & entityIdentifier)

Look up the component of an entity.

Parameters
entityIdentifierThe identifier of the entity.
Returns
Pointer to the component, or nullptr when the entity has none.

◆ find() [2/2]

template<InheritFromComponent ComponentType>
const ComponentType * guillaume::ecs::ComponentStorage< ComponentType >::find ( const Entity::Identifier & entityIdentifier) const

Look up the component of an entity, read-only.

Parameters
entityIdentifierThe identifier of the entity.
Returns
Pointer to the component, or nullptr when the entity has none.

◆ has()

template<InheritFromComponent ComponentType>
bool guillaume::ecs::ComponentStorage< ComponentType >::has ( const Entity::Identifier & entityIdentifier) const
overridevirtual

Tell whether a component is stored for an entity.

Parameters
entityIdentifierThe identifier of the entity.
Returns
True when the entity has a component in this storage.

Implements guillaume::ecs::IComponentStorage.

◆ hasChanged()

template<InheritFromComponent ComponentType>
bool guillaume::ecs::ComponentStorage< ComponentType >::hasChanged ( const Entity::Identifier & entityIdentifier) const
overridevirtual

Tell whether the component stored for an entity is marked as changed.

Parameters
entityIdentifierThe identifier of the entity.
Returns
True when the component exists and is marked as changed; false when it is unchanged or the entity has none.

Implements guillaume::ecs::IComponentStorage.

◆ remove()

template<InheritFromComponent ComponentType>
void guillaume::ecs::ComponentStorage< ComponentType >::remove ( const Entity::Identifier & entityIdentifier)
overridevirtual

Delete the component stored for an entity. Does nothing when the entity has none.

Parameters
entityIdentifierThe identifier of the entity.

Implements guillaume::ecs::IComponentStorage.

◆ resetChangedFlags()

template<InheritFromComponent ComponentType>
void guillaume::ecs::ComponentStorage< ComponentType >::resetChangedFlags ( void )
overridevirtual

Mark every component of this storage as unchanged.

Implements guillaume::ecs::IComponentStorage.


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