libecs-cpp 2.1.0
Entity Component System library in C++
Loading...
Searching...
No Matches
Component.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4#include <string>
5#include <memory>
6#include <libecs-cpp/json.hpp>
7
8namespace ecs
9{
19 {
20 public:
22 Component() = default;
23
27 Component(const nlohmann::json &) {}
28
30 virtual nlohmann::json Export() const = 0;
34 std::string Type;
37 std::string EntityHandle;
39 virtual ~Component() = default;
40 };
41
43 typedef std::unordered_map<std::string, std::shared_ptr<ecs::Component>> EntityComponentList;
44
48 typedef std::unordered_map<std::string, ecs::EntityComponentList> TypeEntityComponentList;
49}
Base class for the data attached to an entity.
Definition Component.hpp:19
Component()=default
Creates a component with an empty Type and EntityHandle.
virtual ~Component()=default
Destroys the component.
std::string Type
The type name the component is stored and looked up under, for example "PositionComponent".
Definition Component.hpp:34
Component(const nlohmann::json &)
Creates a component from a configuration, which the base class does not read.
Definition Component.hpp:27
std::string EntityHandle
The handle of the entity the component is attached to.
Definition Component.hpp:37
virtual nlohmann::json Export() const =0
Describes the component as JSON; every subclass implements it.
Definition Clock.hpp:10
std::unordered_map< std::string, std::shared_ptr< ecs::Component > > EntityComponentList
The components of one type, by entity handle.
Definition Component.hpp:43
std::unordered_map< std::string, ecs::EntityComponentList > TypeEntityComponentList
The components of a container, by type name and then by entity handle.
Definition Component.hpp:48