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

rel_storage.hpp
Go to the documentation of this file.
1 #ifndef EAGINE_ECS_REL_STORAGE_HPP
9 #define EAGINE_ECS_REL_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 
19 namespace eagine::ecs {
20 
21 template <typename Entity>
22 struct storage_iterator_intf<Entity, true>
23  : interface<storage_iterator_intf<Entity, true>> {
24 
25  virtual auto reset() -> void = 0;
26 
27  virtual auto done() -> bool = 0;
28 
29  virtual void next() = 0;
30 
31  virtual auto subject() -> Entity = 0;
32 
33  virtual auto object() -> Entity = 0;
34 };
35 
36 template <typename Entity>
37 class storage_iterator<Entity, true> {
38 private:
39  storage_iterator_intf<Entity, true>* _i{nullptr};
40 
41 public:
42  storage_iterator(storage_iterator_intf<Entity, true>* i) noexcept
43  : _i(i) {
44  EAGINE_ASSERT(_i);
45  }
46 
47  storage_iterator(storage_iterator&& tmp) noexcept
48  : _i{std::exchange(tmp._i, nullptr)} {}
49  storage_iterator(const storage_iterator&) = delete;
50 
51  auto operator=(storage_iterator&&) = delete;
52  auto operator=(const storage_iterator&) = delete;
53 
54  ~storage_iterator() noexcept {
55  EAGINE_ASSERT(_i == nullptr);
56  }
57 
58  auto release() -> storage_iterator_intf<Entity, true>* {
59  return std::exchange(_i, nullptr);
60  }
61 
62  auto ptr() noexcept -> storage_iterator_intf<Entity, true>* {
63  EAGINE_ASSERT(_i);
64  return _i;
65  }
66 
67  auto get() noexcept -> storage_iterator_intf<Entity, true>& {
68  EAGINE_ASSERT(_i);
69  return *_i;
70  }
71 
72  void reset() {
73  get().reset();
74  }
75 
76  auto done() -> bool {
77  return get().done();
78  }
79 
80  void next() {
81  get().next();
82  }
83 
84  auto subject() -> Entity {
85  return get().subject();
86  }
87 
88  auto object() -> Entity {
89  return get().object();
90  }
91 };
92 
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>;
97 
98  virtual auto capabilities() -> storage_caps = 0;
99 
100  virtual auto new_iterator() -> iterator_t = 0;
101 
102  virtual void delete_iterator(iterator_t&&) = 0;
103 
104  virtual auto has(entity_param subject, entity_param object) -> bool = 0;
105 
106  virtual auto store(entity_param subject, entity_param object) -> bool = 0;
107 
108  virtual auto remove(entity_param subject, entity_param object) -> bool = 0;
109 
110  virtual void remove(iterator_t&) = 0;
111 
112  virtual void for_each(
113  callable_ref<void(entity_param, entity_param)>,
114  entity_param subject) = 0;
115 
116  virtual void for_each(callable_ref<void(entity_param, entity_param)>) = 0;
117 };
118 
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>;
123 
124  using base_storage<Entity, true>::store;
125 
126  virtual auto store(entity_param subject, entity_param object, Relation &&)
127  -> bool = 0;
128 
129  virtual void for_single(
130  callable_ref<
131  void(entity_param, entity_param, manipulator<const Relation>&)>,
132  entity_param subject,
133  entity_param object) = 0;
134 
135  virtual void for_single(
136  callable_ref<
137  void(entity_param, entity_param, manipulator<const Relation>&)>,
138  iterator_t&) = 0;
139 
140  virtual void for_single(
141  callable_ref<void(entity_param, entity_param, manipulator<Relation>&)>,
142  entity_param subject,
143  entity_param object) = 0;
144 
145  virtual void for_single(
146  callable_ref<void(entity_param, entity_param, manipulator<Relation>&)>,
147  iterator_t&) = 0;
148 
149  using base_storage<Entity, true>::for_each;
150 
151  virtual void for_each(
152  callable_ref<
153  void(entity_param, entity_param, manipulator<const Relation>&)>,
154  entity_param subject) = 0;
155 
156  virtual void for_each(
157  callable_ref<void(entity_param, entity_param, manipulator<Relation>&)>,
158  entity_param subject) = 0;
159 
160  virtual void for_each(
161  callable_ref<
162  void(entity_param, entity_param, manipulator<const Relation>&)>) = 0;
163 
164  virtual void for_each(
165  callable_ref<void(entity_param, entity_param, manipulator<Relation>&)>) = 0;
166 };
167 
168 } // namespace eagine::ecs
169 
170 #endif // EAGINE_ECS_REL_STORAGE_HPP
basic_callable_ref< Sig, is_noexcept_function_v< Sig > > callable_ref
Alias for callable object references.
Definition: callable_ref.hpp:191

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