ECSTASY
All in the name
Loading...
Searching...
No Matches
AStorage.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_STORAGE_ASTORAGE_HPP_
13#define ECSTASY_STORAGE_ASTORAGE_HPP_
14
15#include <span>
16
17#include "ecstasy/config.hpp"
20#include "util/BitSet.hpp"
21
22namespace ecstasy
23{
24
33 template <typename C>
34 class AStorage : public IStorage {
35 public:
37 using Component = C;
38
40 using QueryData = C &;
42 using ConstQueryData = const C &;
43
57 virtual bool erase(Entity::Index index) = 0;
58
70 void erase(std::span<Entity> entities) override final
71 {
72 for (Entity entity : entities)
73 erase(entity.getIndex());
74 }
75
77 bool contains(Entity::Index index) const noexcept override final
78 {
79 return (index < getMask().size()) && getMask()[index];
80 }
81
94 [[nodiscard]] Component &at(Entity::Index index)
95 {
96 if (!contains(index)) [[unlikely]]
97 throw std::out_of_range("Entity doesn't have the component");
98 return (*this)[index];
99 }
100
113 [[nodiscard]] const Component &at(Entity::Index index) const
114 {
115 if (!contains(index)) [[unlikely]]
116 throw std::out_of_range("Entity doesn't have the component");
117 return (*this)[index];
118 }
119
133 [[nodiscard]] virtual Component &operator[](Entity::Index index) = 0;
134
139 {
140 return (*this)[index];
141 };
142
156 [[nodiscard]] virtual const Component &operator[](Entity::Index index) const = 0;
157
161 [[nodiscard]] ConstQueryData getQueryData(Entity::Index index) const
162 {
163 return (*this)[index];
164 };
165
167 [[nodiscard]] const std::type_info &getComponentTypeInfos() const noexcept override final
168 {
169 return typeid(Component);
170 }
171
183 [[nodiscard]] virtual Component &insert(Entity::Index index, Component &&c) = 0;
184 };
185
186} // namespace ecstasy
187
188#endif /* !ECSTASY_STORAGE_ASTORAGE_HPP_ */
Encapsulate an index to an entity.
Abstract class for all components storage.
Abstract class for all components storage.
Definition AStorage.hpp:34
C Component
IsStorage constraint.
Definition AStorage.hpp:37
virtual const Component & operator[](Entity::Index index) const =0
Retrieve the const Component instance associated to the given entity.
QueryData getQueryData(Entity::Index index)
Retrieve the Component instance associated to the given entity.
Definition AStorage.hpp:138
Component & at(Entity::Index index)
Retrieve the Component instance associated to the given entity and perform bound checking.
Definition AStorage.hpp:94
void erase(std::span< Entity > entities) override final
Erase multiple Component instances associated to the given entities.
Definition AStorage.hpp:70
const Component & at(Entity::Index index) const
Retrieve the Component instance associated to the given entity and perform bound checking.
Definition AStorage.hpp:113
bool contains(Entity::Index index) const noexcept override final
Test if the entity index match a Component instance.
Definition AStorage.hpp:77
ConstQueryData getQueryData(Entity::Index index) const
Retrieve the Component instance associated to the given entity.
Definition AStorage.hpp:161
C & QueryData
QueryableObject constraint.
Definition AStorage.hpp:40
const C & ConstQueryData
ConstQueryableObject constraint.
Definition AStorage.hpp:42
virtual Component & insert(Entity::Index index, Component &&c)=0
Insert a new Component instance associated to the given entity.
virtual Component & operator[](Entity::Index index)=0
Retrieve the Component instance associated to the given entity.
const std::type_info & getComponentTypeInfos() const noexcept override final
Get the Component stored type infos.
Definition AStorage.hpp:167
virtual bool erase(Entity::Index index)=0
Erase the Component instance associated to the given entity.
Encapsulate an index to an entity.
Definition Entity.hpp:35
size_t Index
The entity identifier type.
Definition Entity.hpp:38
Base class of all components storage.
Definition IStorage.hpp:44
virtual constexpr const util::BitSet & getMask() const noexcept=0
Get the Component Mask.
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30