1 #ifndef EAGINE_ECS_REL_STORAGE_HPP
9 #define EAGINE_ECS_REL_STORAGE_HPP
11 #include "../assert.hpp"
12 #include "../callable_ref.hpp"
13 #include "../interface.hpp"
19 namespace eagine::ecs {
21 template <
typename Entity>
22 struct storage_iterator_intf<Entity, true>
23 : interface<storage_iterator_intf<Entity, true>> {
25 virtual auto reset() ->
void = 0;
27 virtual auto done() ->
bool = 0;
29 virtual void next() = 0;
31 virtual auto subject() -> Entity = 0;
33 virtual auto object() -> Entity = 0;
36 template <
typename Entity>
37 class storage_iterator<Entity, true> {
39 storage_iterator_intf<Entity, true>* _i{
nullptr};
42 storage_iterator(storage_iterator_intf<Entity, true>* i) noexcept
47 storage_iterator(storage_iterator&& tmp) noexcept
48 : _i{std::exchange(tmp._i,
nullptr)} {}
49 storage_iterator(
const storage_iterator&) =
delete;
51 auto operator=(storage_iterator&&) =
delete;
52 auto operator=(
const storage_iterator&) =
delete;
54 ~storage_iterator() noexcept {
55 EAGINE_ASSERT(_i ==
nullptr);
58 auto release() -> storage_iterator_intf<Entity, true>* {
59 return std::exchange(_i,
nullptr);
62 auto ptr() noexcept -> storage_iterator_intf<Entity, true>* {
67 auto get() noexcept -> storage_iterator_intf<Entity, true>& {
84 auto subject() -> Entity {
85 return get().subject();
88 auto object() -> Entity {
89 return get().object();
93 template <
typename Entity>
94 struct base_storage<Entity, true> : interface<base_storage<Entity, true>> {
95 using entity_param = entity_param_t<Entity>;
96 using iterator_t = storage_iterator<Entity, true>;
98 virtual auto capabilities() -> storage_caps = 0;
100 virtual auto new_iterator() -> iterator_t = 0;
102 virtual void delete_iterator(iterator_t&&) = 0;
104 virtual auto has(entity_param subject, entity_param
object) ->
bool = 0;
106 virtual auto store(entity_param subject, entity_param
object) ->
bool = 0;
108 virtual auto remove(entity_param subject, entity_param
object) ->
bool = 0;
110 virtual void remove(iterator_t&) = 0;
112 virtual void for_each(
114 entity_param subject) = 0;
116 virtual void for_each(
callable_ref<
void(entity_param, entity_param)>) = 0;
119 template <
typename Entity,
typename Relation>
120 struct storage<Entity, Relation, true> : base_storage<Entity, true> {
121 using entity_param = entity_param_t<Entity>;
122 using iterator_t = storage_iterator<Entity, true>;
124 using base_storage<Entity, true>::store;
126 virtual auto store(entity_param subject, entity_param
object, Relation &&)
129 virtual void for_single(
131 void(entity_param, entity_param, manipulator<const Relation>&)>,
132 entity_param subject,
133 entity_param
object) = 0;
135 virtual void for_single(
137 void(entity_param, entity_param, manipulator<const Relation>&)>,
140 virtual void for_single(
141 callable_ref<
void(entity_param, entity_param, manipulator<Relation>&)>,
142 entity_param subject,
143 entity_param
object) = 0;
145 virtual void for_single(
146 callable_ref<
void(entity_param, entity_param, manipulator<Relation>&)>,
149 using base_storage<Entity, true>::for_each;
151 virtual void for_each(
153 void(entity_param, entity_param, manipulator<const Relation>&)>,
154 entity_param subject) = 0;
156 virtual void for_each(
157 callable_ref<
void(entity_param, entity_param, manipulator<Relation>&)>,
158 entity_param subject) = 0;
160 virtual void for_each(
162 void(entity_param, entity_param, manipulator<const Relation>&)>) = 0;
164 virtual void for_each(
165 callable_ref<
void(entity_param, entity_param, manipulator<Relation>&)>) = 0;
170 #endif // EAGINE_ECS_REL_STORAGE_HPP