1 #ifndef EAGINE_ECS_CMP_STORAGE_HPP
9 #define EAGINE_ECS_CMP_STORAGE_HPP
11 #include "../assert.hpp"
12 #include "../callable_ref.hpp"
13 #include "../interface.hpp"
20 namespace eagine::ecs {
22 template <
typename Entity>
23 struct storage_iterator_intf<Entity, false>
24 : interface<storage_iterator_intf<Entity, false>> {
26 virtual void reset() = 0;
28 virtual auto done() ->
bool = 0;
30 virtual void next() = 0;
32 virtual auto find(Entity) ->
bool = 0;
34 virtual auto current() -> Entity = 0;
37 template <
typename Entity>
38 class storage_iterator<Entity, false> {
40 storage_iterator_intf<Entity, false>* _i{
nullptr};
43 storage_iterator(storage_iterator_intf<Entity, false>* i) noexcept
48 storage_iterator(storage_iterator&& tmp) noexcept
49 : _i{std::exchange(tmp._i,
nullptr)} {}
51 storage_iterator(
const storage_iterator&) =
delete;
52 auto operator=(storage_iterator&&) =
delete;
53 auto operator=(
const storage_iterator&) =
delete;
55 ~storage_iterator() noexcept {
56 EAGINE_ASSERT(_i ==
nullptr);
59 auto release() -> storage_iterator_intf<Entity, false>* {
60 return std::exchange(_i,
nullptr);
63 auto ptr() noexcept -> storage_iterator_intf<Entity, false>* {
68 auto get() noexcept -> storage_iterator_intf<Entity, false>& {
81 auto next() ->
auto& {
86 auto find(Entity e) ->
bool {
90 auto current() -> Entity {
91 return get().current();
95 template <
typename Entity>
96 struct base_storage<Entity, false> : interface<base_storage<Entity, false>> {
97 using entity_param = entity_param_t<Entity>;
98 using iterator_t = storage_iterator<Entity, false>;
100 virtual auto capabilities() -> storage_caps = 0;
102 virtual auto new_iterator() -> iterator_t = 0;
104 virtual void delete_iterator(iterator_t&&) = 0;
106 virtual auto has(entity_param) ->
bool = 0;
108 virtual auto is_hidden(entity_param) ->
bool = 0;
110 virtual auto is_hidden(iterator_t&) ->
bool = 0;
112 virtual auto hide(entity_param) ->
bool = 0;
114 virtual void hide(iterator_t&) = 0;
116 virtual auto show(entity_param) ->
bool = 0;
118 virtual auto show(iterator_t&) ->
bool = 0;
120 virtual auto copy(entity_param from, entity_param to) ->
bool = 0;
122 virtual auto swap(entity_param a, entity_param b) ->
bool = 0;
124 virtual auto remove(entity_param) ->
bool = 0;
126 virtual void remove(iterator_t&) = 0;
129 template <
typename Entity,
typename Component>
130 struct storage<Entity, Component, false> : base_storage<Entity, false> {
131 using entity_param = entity_param_t<Entity>;
132 using iterator_t = storage_iterator<Entity, false>;
134 virtual auto store(entity_param, Component &&) ->
bool = 0;
136 virtual auto store(iterator_t&, entity_param, Component &&) ->
bool = 0;
138 virtual void for_single(
139 callable_ref<
void(entity_param, manipulator<const Component>&)>,
142 virtual void for_single(
143 callable_ref<
void(entity_param, manipulator<const Component>&)>,
146 virtual void for_single(
147 callable_ref<
void(entity_param, manipulator<Component>&)>,
150 virtual void for_single(
151 callable_ref<
void(entity_param, manipulator<Component>&)>,
154 virtual void for_each(
155 callable_ref<
void(entity_param, manipulator<const Component>&)>) = 0;
158 for_each(
callable_ref<
void(entity_param, manipulator<Component>&)>) = 0;
163 #endif // EAGINE_ECS_CMP_STORAGE_HPP