libecs-cpp 2.1.0
Entity Component System library in C++
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
ecs::Component Class Referenceabstract

Base class for the data attached to an entity. More...

#include <Component.hpp>

Public Member Functions

 Component ()=default
 Creates a component with an empty Type and EntityHandle.
 
 Component (const nlohmann::json &)
 Creates a component from a configuration, which the base class does not read.
 
virtual nlohmann::json Export () const =0
 Describes the component as JSON; every subclass implements it.
 
virtual ~Component ()=default
 Destroys the component.
 

Public Attributes

std::string Type
 The type name the component is stored and looked up under, for example "PositionComponent".
 
std::string EntityHandle
 The handle of the entity the component is attached to.
 

Detailed Description

Base class for the data attached to an entity.

A subclass sets Type in its constructor and implements Export(). A component has no handle of its own: it is addressed by its entity (EntityHandle) and its type name (Type). Attach it with Entity::Component() and look it up with Entity::ComponentGet() or Container::ComponentGet().

Thread: container thread only. A component lives in its container's tables, so it must be used and changed from the thread that drives the container (see Container).

Constructor & Destructor Documentation

◆ Component() [1/2]

ecs::Component::Component ( )
default

Creates a component with an empty Type and EntityHandle.

◆ Component() [2/2]

ecs::Component::Component ( const nlohmann::json &  )
inline

Creates a component from a configuration, which the base class does not read.

A subclass reads from it whatever it needs. The constructor is not explicit, so a component that forwards its configuration to the base compiles.

◆ ~Component()

virtual ecs::Component::~Component ( )
virtualdefault

Destroys the component.

Member Function Documentation

◆ Export()

virtual nlohmann::json ecs::Component::Export ( ) const
pure virtual

Describes the component as JSON; every subclass implements it.

Member Data Documentation

◆ EntityHandle

std::string ecs::Component::EntityHandle

The handle of the entity the component is attached to.

Entity::Component() sets it; Container::Component() reads it.

◆ Type

std::string ecs::Component::Type

The type name the component is stored and looked up under, for example "PositionComponent".

A subclass sets it in its constructor. A component with an empty Type is rejected when it is attached.


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