OGLplus  (0.59.0) a C++ wrapper for rendering APIs

cmp_storage.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_ECS_CMP_STORAGE_HPP
9 #define EAGINE_ECS_CMP_STORAGE_HPP
10 
11 #include "../assert.hpp"
12 #include "../callable_ref.hpp"
13 #include "../interface.hpp"
14 #include "entity_traits.hpp"
15 #include "manipulator.hpp"
16 #include "storage_caps.hpp"
17 #include "storage_fwd.hpp"
18 #include <cassert>
19 
20 namespace eagine::ecs {
21 //------------------------------------------------------------------------------
22 template <typename Entity>
23 struct storage_iterator_intf<Entity, false>
24  : interface<storage_iterator_intf<Entity, false>> {
25 
26  virtual void reset() = 0;
27 
28  virtual auto done() -> bool = 0;
29 
30  virtual void next() = 0;
31 
32  virtual auto find(Entity) -> bool = 0;
33 
34  virtual auto current() -> Entity = 0;
35 };
36 //------------------------------------------------------------------------------
37 template <typename Entity>
38 class storage_iterator<Entity, false> {
39 private:
40  storage_iterator_intf<Entity, false>* _i{nullptr};
41 
42 public:
43  storage_iterator(storage_iterator_intf<Entity, false>* i) noexcept
44  : _i{i} {
45  EAGINE_ASSERT(_i);
46  }
47 
48  storage_iterator(storage_iterator&& tmp) noexcept
49  : _i{std::exchange(tmp._i, nullptr)} {}
50 
51  storage_iterator(const storage_iterator&) = delete;
52  auto operator=(storage_iterator&&) = delete;
53  auto operator=(const storage_iterator&) = delete;
54 
55  ~storage_iterator() noexcept {
56  EAGINE_ASSERT(_i == nullptr);
57  }
58 
59  auto release() -> storage_iterator_intf<Entity, false>* {
60  return std::exchange(_i, nullptr);
61  }
62 
63  auto ptr() noexcept -> storage_iterator_intf<Entity, false>* {
64  EAGINE_ASSERT(_i);
65  return _i;
66  }
67 
68  auto get() noexcept -> storage_iterator_intf<Entity, false>& {
69  EAGINE_ASSERT(_i);
70  return *_i;
71  }
72 
73  void reset() {
74  get().reset();
75  }
76 
77  auto done() -> bool {
78  return get().done();
79  }
80 
81  auto next() -> auto& {
82  get().next();
83  return *this;
84  }
85 
86  auto find(Entity e) -> bool {
87  return get().find(e);
88  }
89 
90  auto current() -> Entity {
91  return get().current();
92  }
93 };
94 //------------------------------------------------------------------------------
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>;
99 
100  virtual auto capabilities() -> storage_caps = 0;
101 
102  virtual auto new_iterator() -> iterator_t = 0;
103 
104  virtual void delete_iterator(iterator_t&&) = 0;
105 
106  virtual auto has(entity_param) -> bool = 0;
107 
108  virtual auto is_hidden(entity_param) -> bool = 0;
109 
110  virtual auto is_hidden(iterator_t&) -> bool = 0;
111 
112  virtual auto hide(entity_param) -> bool = 0;
113 
114  virtual void hide(iterator_t&) = 0;
115 
116  virtual auto show(entity_param) -> bool = 0;
117 
118  virtual auto show(iterator_t&) -> bool = 0;
119 
120  virtual auto copy(entity_param from, entity_param to) -> bool = 0;
121 
122  virtual auto swap(entity_param a, entity_param b) -> bool = 0;
123 
124  virtual auto remove(entity_param) -> bool = 0;
125 
126  virtual void remove(iterator_t&) = 0;
127 };
128 //------------------------------------------------------------------------------
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>;
133 
134  virtual auto store(entity_param, Component &&) -> bool = 0;
135 
136  virtual auto store(iterator_t&, entity_param, Component &&) -> bool = 0;
137 
138  virtual void for_single(
139  callable_ref<void(entity_param, manipulator<const Component>&)>,
140  entity_param) = 0;
141 
142  virtual void for_single(
143  callable_ref<void(entity_param, manipulator<const Component>&)>,
144  iterator_t&) = 0;
145 
146  virtual void for_single(
147  callable_ref<void(entity_param, manipulator<Component>&)>,
148  entity_param) = 0;
149 
150  virtual void for_single(
151  callable_ref<void(entity_param, manipulator<Component>&)>,
152  iterator_t&) = 0;
153 
154  virtual void for_each(
155  callable_ref<void(entity_param, manipulator<const Component>&)>) = 0;
156 
157  virtual void
158  for_each(callable_ref<void(entity_param, manipulator<Component>&)>) = 0;
159 };
160 //------------------------------------------------------------------------------
161 } // namespace eagine::ecs
162 
163 #endif // EAGINE_ECS_CMP_STORAGE_HPP
basic_callable_ref< Sig, is_noexcept_function_v< Sig > > callable_ref
Alias for callable object references.
Definition: callable_ref.hpp:191
static auto find(basic_span< T1, P1, S1 > where, basic_span< T2, P2, S2 > what) -> basic_span< T1, P1, S1 >
Finds the position of the last occurrence of what in a span.
Definition: span_algo.hpp:374

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).