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

An entity that owns child entities: both an Entity and an EntityRegistry. More...

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

Inheritance diagram for guillaume::ecs::ParentEntity:
Collaboration diagram for guillaume::ecs::ParentEntity:

Protected Member Functions

std::vector< std::shared_ptr< Entity > > & accessDirectEntities (void) override
 Give access to the list of entities this entity owns directly.
const std::vector< std::shared_ptr< Entity > > & accessDirectEntities (void) const override
 Give read access to the list of entities this entity owns directly.
Protected Member Functions inherited from guillaume::ecs::Entity
void attachHierarchy (ComponentRegistry &componentRegistry)
 Give the entity a components::Hierarchy in a registry and add that component to its signature.
template<InheritFromComponent... ComponentTypes>
void setSignature (void)
 Replace the signature by the one made of the given component types.

Additional Inherited Members

Public Types inherited from guillaume::ecs::Entity
using Identifier = std::size_t
 The key under which an entity's components are stored. Systems and components refer to entities by this value.
using Signature = std::bitset<128>
 A set of component types, one bit per type (bit position given by ComponentTypeId, MaxComponentTypes bits).
Public Member Functions inherited from guillaume::ecs::Entity
 Entity (void)
 Create an entity with a fresh identifier, an empty signature, no parent and no component.
virtual ~Entity (void)=default
 Destroy the entity object.
Entity::Identifier getIdentifier (void) const noexcept
 Get the identifier of the entity.
Entity::Signature getSignature (void) const noexcept
 Get the set of component types the entity declares.
void setSignature (const Signature &signature)
 Replace the signature of the entity.
std::int32_t getLayer (void) const noexcept
 Get the depth of the entity in the tree.
Entity & setParent (std::shared_ptr< Entity > parent)
 Attach the entity under another one, or detach it.
std::vector< Identifier > releaseComponents (void)
 Drop the entity's place in the tree and all its components.
std::shared_ptr< Entity > getParent (void) const noexcept
 Get the parent entity.
Public Member Functions inherited from guillaume::ecs::EntityRegistry
 EntityRegistry (void)=default
 Create a registry.
virtual ~EntityRegistry (void)=default
 Virtual destructor.
void addEntity (std::shared_ptr< Entity > entity)
 Make this registry own an entity, so that it stays alive and systems visit it.
bool removeEntity (Entity::Identifier identifier)
 Remove an entity, with its children and all their components.
void clearEntities (void)
 Remove every entity owned by this registry, with everything they own and all their components.
const std::vector< std::shared_ptr< Entity > > & getEntities (void) const
 Get the entities this registry owns directly.
std::vector< std::shared_ptr< Entity > > getEntitiesBreadthFirst (void)
 List every entity of this registry and of the registries nested in it, level by level.
std::vector< std::shared_ptr< Entity > > getEntitiesBreadthFirst (void) const
 List every entity of this registry and of the registries nested in it, level by level (const overload).
template<InheritFromEntity EntityType>
std::shared_ptr< EntityType > getEntity (Entity::Identifier identifier)
 Find an entity owned directly by this registry, by identifier.
template<InheritFromEntity EntityType>
std::shared_ptr< const EntityType > getEntity (Entity::Identifier identifier) const
 Find an entity owned directly by this registry, by identifier (const overload).
std::vector< Entity::Identifier > getEntityWithSignature (Entity::Signature systemSignature) const
 List the entities that have every component type of a signature, from the root down.
std::vector< Entity::Identifier > getEntityWithSignature (Entity::Signature systemSignature, const EntityTreeTraveler &traveler) const
 List the entities that have every component type of a signature, in the order chosen by a traveler.
Static Public Member Functions inherited from guillaume::ecs::Entity
template<InheritFromComponent... ComponentTypes>
static Signature getSignatureFromTypes (void)
 Build the signature that has exactly the bits of the given component types.
Static Public Attributes inherited from guillaume::ecs::Entity
static constexpr Identifier InvalidIdentifier
 "No entity": never the identifier of a real entity

Detailed Description

An entity that owns child entities: both an Entity and an EntityRegistry.

Widgets with children (a card, a menu, a view) derive from it through ParentEntityFiller. The children it owns stay alive as long as it does and are reached by the systems through it; removing it with EntityRegistry::removeEntity removes them too.

child->setParent(parent); // parent is a shared_ptr<ParentEntity>
parent->addEntity(child);
Note
addEntity only records ownership. The parent link, the layer and components::Hierarchy are set by Entity::setParent, so call both.
See also
ParentEntityFiller
EntityRegistry

Definition at line 52 of file parent_entity.hpp.

Member Function Documentation

◆ accessDirectEntities() [1/2]

const std::vector< std::shared_ptr< Entity > > & guillaume::ecs::ParentEntity::accessDirectEntities ( void ) const
overrideprotectedvirtual

Give read access to the list of entities this entity owns directly.

Returns
Const reference to the list, in insertion order.

Implements guillaume::ecs::EntityRegistry.

Definition at line 34 of file parent_entity.cpp.

◆ accessDirectEntities() [2/2]

std::vector< std::shared_ptr< Entity > > & guillaume::ecs::ParentEntity::accessDirectEntities ( void )
overrideprotectedvirtual

Give access to the list of entities this entity owns directly.

Returns
Mutable reference to the list, in insertion order.

Implements guillaume::ecs::EntityRegistry.

Definition at line 28 of file parent_entity.cpp.


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