Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
shkyera::EntityHierarchy Class Reference

#include <EntityHierarchy.hpp>

Inheritance diagram for shkyera::EntityHierarchy:
[legend]

Public Types

using Children = std::set< Entity >
 Alias for a set of child entities.
 

Public Member Functions

 EntityHierarchy ()=default
 Constructs a new EntityHierarchy object.
 
 ~EntityHierarchy ()=default
 Destroys the EntityHierarchy object.
 
void attributeChild (Entity parent, Entity child)
 Attributes a child entity to a parent entity.
 
void removeFromParent (Entity child)
 Removes a child entity from its parent.
 
std::optional< EntitygetParent (Entity child) const
 Gets the parent of a specified child entity.
 
const ChildrengetChildren (Entity parent) const
 Gets the children of a specified parent entity.
 
const autogetParentToChild () const
 

Private Member Functions

bool isAncestor (Entity entity, Entity ancestor) const
 Checks if an entity is an ancestor of another entity.
 

Private Attributes

std::map< Entity, Children_parentToChildren
 
std::map< Entity, Entity_childToParent
 

Detailed Description

This class provides functionalities to attribute child entities to parent entities, retrieve parent entities, retrieve children of a parent entity, and manage the removal of entities from their parents. It ensures a well-defined tree structure for entity relationships with NO cyclic relations.

Member Typedef Documentation

◆ Children

Alias for a set of child entities.

Constructor & Destructor Documentation

◆ EntityHierarchy()

shkyera::EntityHierarchy::EntityHierarchy ( )
default

Constructs a new EntityHierarchy object.

◆ ~EntityHierarchy()

shkyera::EntityHierarchy::~EntityHierarchy ( )
default

Destroys the EntityHierarchy object.

Member Function Documentation

◆ attributeChild()

void shkyera::EntityHierarchy::attributeChild ( Entity  parent,
Entity  child 
)

Attributes a child entity to a parent entity.

Establishes a parent-child relationship by associating the specified child with the specified parent.

Parameters
parentThe parent entity.
childThe child entity to be attributed to the parent.

◆ getChildren()

const EntityHierarchy::Children & shkyera::EntityHierarchy::getChildren ( Entity  parent) const

Gets the children of a specified parent entity.

Retrieves all entities that are attributed as children of the specified parent entity.

Parameters
parentThe parent entity whose children are to be retrieved.
Returns
A constant reference to a set of child entities.

◆ getParent()

std::optional< Entity > shkyera::EntityHierarchy::getParent ( Entity  child) const

Gets the parent of a specified child entity.

Retrieves the parent entity of the specified child, if a parent-child relationship exists.

Parameters
childThe child entity whose parent is to be retrieved.
Returns
An optional containing the parent entity if it exists, or std::nullopt otherwise.

◆ getParentToChild()

const auto & shkyera::EntityHierarchy::getParentToChild ( ) const
inline

◆ isAncestor()

bool shkyera::EntityHierarchy::isAncestor ( Entity  entity,
Entity  ancestor 
) const
private

Checks if an entity is an ancestor of another entity.

Determines if the specified ancestor entity is an ancestor of the specified entity in the hierarchy.

Parameters
entityThe entity to check.
ancestorThe potential ancestor entity.
Returns
True if the ancestor is an ancestor of the entity, false otherwise.

◆ removeFromParent()

void shkyera::EntityHierarchy::removeFromParent ( Entity  child)

Removes a child entity from its parent.

If the specified child entity has a parent, the parent-child association is removed.

Parameters
childThe child entity to be removed from its parent.

Member Data Documentation

◆ _childToParent

std::map<Entity, Entity> shkyera::EntityHierarchy::_childToParent
private

◆ _parentToChildren

std::map<Entity, Children> shkyera::EntityHierarchy::_parentToChildren
private

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