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

Place of an entity in the entity tree: its parent, its direct children and its depth. More...

#include <headers/guillaume/components/hierarchy.hpp>

Inheritance diagram for guillaume::components::Hierarchy:
Collaboration diagram for guillaume::components::Hierarchy:

Public Member Functions

 Hierarchy (void)=default
 Construct the hierarchy of a root entity without children.
 ~Hierarchy (void)=default
 Default destructor.
ecs::Entity::Identifier getParentIdentifier (void) const noexcept
 Get the identifier of the parent entity.
Hierarchy & setParentIdentifier (ecs::Entity::Identifier identifier)
 Store the identifier of the parent entity.
bool hasParent (void) const noexcept
 Check whether the entity has a parent.
const std::vector< ecs::Entity::Identifier > & getChildIdentifiers (void) const noexcept
 Get the direct children, in the order they were attached.
bool hasChild (ecs::Entity::Identifier identifier) const noexcept
 Check whether an entity is a direct child of this one.
bool addChild (ecs::Entity::Identifier identifier)
 Append an entity to the direct children.
bool removeChild (ecs::Entity::Identifier identifier)
 Remove an entity from the direct children.
std::int32_t getLayer (void) const noexcept
 Get the depth of the entity in the tree.
Hierarchy & setLayer (std::int32_t layer)
 Store the depth of the entity in the tree.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

Place of an entity in the entity tree: its parent, its direct children and its depth.

It lets a system walk the tree from identifiers alone, without entity objects. Every entity built on a component registry has one. ecs::Entity::setParent writes it: it updates the parent identifier of the entity, the child lists of the previous and of the new parent, and the layer of the entity and of all its descendants. Removing an entity unlinks it from its parent and resets the parent of its children. Systems read it: systems::Layout::layerOf returns the layer, which stacks content in front of its container, and systems::Selection takes the members of a selection group from the child list.

const auto &hierarchy =
registry.getComponent<components::Hierarchy>(identifier);
for (const auto child: hierarchy.getChildIdentifiers()) { ... }
Place of an entity in the entity tree: its parent, its direct children and its depth.
Definition hierarchy.hpp:61

Treat it as read-only outside ecs::Entity. Each setter changes this component only: setParentIdentifier() does not touch the child list of the parent, and addChild() does not set the parent or the layer of the child.

See also
ecs::Entity::setParent, systems::Layout::layerOf

Definition at line 60 of file hierarchy.hpp.

Member Function Documentation

◆ addChild()

bool guillaume::components::Hierarchy::addChild ( ecs::Entity::Identifier identifier)

Append an entity to the direct children.

Called by ecs::Entity::setParent. Marks the component changed when the child is added.

Parameters
identifierThe child identifier.
Returns
True when added, false when it was already a child.

Definition at line 61 of file hierarchy.cpp.

Here is the call graph for this function:

◆ getChildIdentifiers()

const std::vector< ecs::Entity::Identifier > & guillaume::components::Hierarchy::getChildIdentifiers ( void ) const
noexcept

Get the direct children, in the order they were attached.

Returns
The child identifiers; empty for a leaf entity.

Definition at line 49 of file hierarchy.cpp.

◆ getLayer()

std::int32_t guillaume::components::Hierarchy::getLayer ( void ) const
noexcept

Get the depth of the entity in the tree.

Returns
The layer: 0 for a root entity, the layer of the parent plus 1 otherwise.

Definition at line 83 of file hierarchy.cpp.

Here is the caller graph for this function:

◆ getParentIdentifier()

ecs::Entity::Identifier guillaume::components::Hierarchy::getParentIdentifier ( void ) const
noexcept

Get the identifier of the parent entity.

Returns
The parent identifier, or ecs::Entity::InvalidIdentifier for a root entity.

Definition at line 28 of file hierarchy.cpp.

◆ hasChild()

bool guillaume::components::Hierarchy::hasChild ( ecs::Entity::Identifier identifier) const
noexcept

Check whether an entity is a direct child of this one.

Parameters
identifierThe identifier to look for.
Returns
True for a direct child; false for a deeper descendant.

Definition at line 54 of file hierarchy.cpp.

Here is the caller graph for this function:

◆ hasParent()

bool guillaume::components::Hierarchy::hasParent ( void ) const
noexcept

Check whether the entity has a parent.

Returns
False for a root entity.

Definition at line 43 of file hierarchy.cpp.

◆ removeChild()

bool guillaume::components::Hierarchy::removeChild ( ecs::Entity::Identifier identifier)

Remove an entity from the direct children.

The order of the remaining children is kept. Marks the component changed when the child is removed.

Parameters
identifierThe child identifier.
Returns
True when removed, false when it was not a child.

Definition at line 71 of file hierarchy.cpp.

Here is the call graph for this function:

◆ setLayer()

Hierarchy & guillaume::components::Hierarchy::setLayer ( std::int32_t layer)

Store the depth of the entity in the tree.

Called by ecs::Entity::setParent for the entity and each of its descendants. Marks the component changed only when the layer differs.

Parameters
layerThe depth: 0 for a root entity.
Returns
This component, to chain calls.

Definition at line 88 of file hierarchy.cpp.

Here is the call graph for this function:

◆ setParentIdentifier()

Hierarchy & guillaume::components::Hierarchy::setParentIdentifier ( ecs::Entity::Identifier identifier)

Store the identifier of the parent entity.

Called by ecs::Entity::setParent. Marks the component changed only when the identifier differs.

Parameters
identifierThe parent identifier, or ecs::Entity::InvalidIdentifier to make the entity a root.
Returns
This component, to chain calls.

Definition at line 34 of file hierarchy.cpp.

Here is the call graph for this function:

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