EnTT: src/entt/entity/storage.hpp Source File

EnTT 3.16.0

Loading...
Searching...
No Matches
storage.hpp
1#ifndef ENTT_ENTITY_STORAGE_HPP
2#define ENTT_ENTITY_STORAGE_HPP
3
4#include <cstddef>
5#include <iterator>
6#include <memory>
7#include <tuple>
8#include <type_traits>
9#include <utility>
10#include <vector>
11#include "../config/config.h"
12#include "../core/bit.hpp"
13#include "../core/iterator.hpp"
14#include "../core/memory.hpp"
15#include "../core/type_info.hpp"
16#include "component.hpp"
17#include "entity.hpp"
18#include "fwd.hpp"
19#include "sparse_set.hpp"
20
21namespace entt {
22
24namespace internal {
25
26template<typename Container, auto Page>
27class storage_iterator final {
28 friend storage_iterator<const Container, Page>;
29
30 using container_type = std::remove_const_t<Container>;
31 using alloc_traits = std::allocator_traits<typename container_type::allocator_type>;
32
33 using iterator_traits = std::iterator_traits<std::conditional_t<
34 std::is_const_v<Container>,
35 typename alloc_traits::template rebind_traits<typename std::pointer_traits<typename container_type::value_type>::element_type>::const_pointer,
36 typename alloc_traits::template rebind_traits<typename std::pointer_traits<typename container_type::value_type>::element_type>::pointer>>;
37
38public:
39 using value_type = typename iterator_traits::value_type;
40 using pointer = typename iterator_traits::pointer;
41 using reference = typename iterator_traits::reference;
42 using difference_type = typename iterator_traits::difference_type;
43 using iterator_category = std::random_access_iterator_tag;
44
45 constexpr storage_iterator() noexcept = default;
46
47 constexpr storage_iterator(Container *ref, const difference_type idx) noexcept
48 : payload{ref},
49 offset{idx} {}
50
51 template<bool Const = std::is_const_v<Container>, typename = std::enable_if_t<Const>>
52 constexpr storage_iterator(const storage_iterator<std::remove_const_t<Container>, Page> &other) noexcept
53 : storage_iterator{other.payload, other.offset} {}
54
55 constexpr storage_iterator &operator++() noexcept {
56 return --offset, *this;
57 }
58
59 constexpr storage_iterator operator++(int) noexcept {
60 const storage_iterator orig = *this;
61 return ++(*this), orig;
62 }
63
64 constexpr storage_iterator &operator--() noexcept {
65 return ++offset, *this;
66 }
67
68 constexpr storage_iterator operator--(int) noexcept {
69 const storage_iterator orig = *this;
70 return operator--(), orig;
71 }
72
73 constexpr storage_iterator &operator+=(const difference_type value) noexcept {
74 offset -= value;
75 return *this;
76 }
77
78 constexpr storage_iterator operator+(const difference_type value) const noexcept {
79 storage_iterator copy = *this;
80 return (copy += value);
81 }
82
83 constexpr storage_iterator &operator-=(const difference_type value) noexcept {
84 return (*this += -value);
85 }
86
87 constexpr storage_iterator operator-(const difference_type value) const noexcept {
88 return (*this + -value);
89 }
90
91 [[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept {
92 const auto pos = static_cast<typename Container::size_type>(index() - value);
93 return (*payload)[pos / Page][fast_mod(static_cast<std::size_t>(pos), Page)];
94 }
95
96 [[nodiscard]] constexpr pointer operator->() const noexcept {
97 return std::addressof(operator[](0));
98 }
99
100 [[nodiscard]] constexpr reference operator*() const noexcept {
101 return operator[](0);
102 }
103
104 [[nodiscard]] constexpr difference_type index() const noexcept {
105 return offset - 1;
106 }
107
108private:
109 Container *payload;
110 difference_type offset;
111};
112
113template<typename Lhs, typename Rhs, auto Page>
114[[nodiscard]] constexpr std::ptrdiff_t operator-(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
115 return rhs.index() - lhs.index();
116}
117
118template<typename Lhs, typename Rhs, auto Page>
119[[nodiscard]] constexpr bool operator==(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
120 return lhs.index() == rhs.index();
121}
122
123template<typename Lhs, typename Rhs, auto Page>
124[[nodiscard]] constexpr bool operator!=(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
125 return !(lhs == rhs);
126}
127
128template<typename Lhs, typename Rhs, auto Page>
129[[nodiscard]] constexpr bool operator<(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
130 return lhs.index() > rhs.index();
131}
132
133template<typename Lhs, typename Rhs, auto Page>
134[[nodiscard]] constexpr bool operator>(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
135 return rhs < lhs;
136}
137
138template<typename Lhs, typename Rhs, auto Page>
139[[nodiscard]] constexpr bool operator<=(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
140 return !(lhs > rhs);
141}
142
143template<typename Lhs, typename Rhs, auto Page>
144[[nodiscard]] constexpr bool operator>=(const storage_iterator<Lhs, Page> &lhs, const storage_iterator<Rhs, Page> &rhs) noexcept {
145 return !(lhs < rhs);
146}
147
148template<typename It, typename... Other>
149class extended_storage_iterator final {
150 template<typename Iter, typename... Args>
151 friend class extended_storage_iterator;
152
153public:
154 using iterator_type = It;
155 using value_type = decltype(std::tuple_cat(std::make_tuple(*std::declval<It>()), std::forward_as_tuple(*std::declval<Other>()...)));
156 using pointer = input_iterator_pointer<value_type>;
157 using reference = value_type;
158 using difference_type = std::ptrdiff_t;
159 using iterator_category = std::input_iterator_tag;
160 using iterator_concept = std::forward_iterator_tag;
161
162 constexpr extended_storage_iterator()
163 : it{} {}
164
165 constexpr extended_storage_iterator(iterator_type base, Other... other)
166 : it{base, other...} {}
167
168 template<typename... Args, typename = std::enable_if_t<(!std::is_same_v<Other, Args> && ...) && (std::is_constructible_v<Other, Args> && ...)>>
169 constexpr extended_storage_iterator(const extended_storage_iterator<It, Args...> &other)
170 : it{other.it} {}
171
172 constexpr extended_storage_iterator &operator++() noexcept {
173 return ++std::get<It>(it), (++std::get<Other>(it), ...), *this;
174 }
175
176 constexpr extended_storage_iterator operator++(int) noexcept {
177 const extended_storage_iterator orig = *this;
178 return ++(*this), orig;
179 }
180
181 [[nodiscard]] constexpr pointer operator->() const noexcept {
182 return operator*();
183 }
184
185 [[nodiscard]] constexpr reference operator*() const noexcept {
186 return {*std::get<It>(it), *std::get<Other>(it)...};
187 }
188
189 [[nodiscard]] constexpr iterator_type base() const noexcept {
190 return std::get<It>(it);
191 }
192
193 template<typename... Lhs, typename... Rhs>
194 friend constexpr bool operator==(const extended_storage_iterator<Lhs...> &, const extended_storage_iterator<Rhs...> &) noexcept;
195
196private:
197 std::tuple<It, Other...> it;
198};
199
200template<typename... Lhs, typename... Rhs>
201[[nodiscard]] constexpr bool operator==(const extended_storage_iterator<Lhs...> &lhs, const extended_storage_iterator<Rhs...> &rhs) noexcept {
202 return std::get<0>(lhs.it) == std::get<0>(rhs.it);
203}
204
205template<typename... Lhs, typename... Rhs>
206[[nodiscard]] constexpr bool operator!=(const extended_storage_iterator<Lhs...> &lhs, const extended_storage_iterator<Rhs...> &rhs) noexcept {
207 return !(lhs == rhs);
208}
209
210} // namespace internal
212
228template<typename Type, typename Entity, typename Allocator, typename>
229 class basic_storage: public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
230 using alloc_traits = std::allocator_traits<Allocator>;
231 static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
232 using container_type = std::vector<typename alloc_traits::pointer, typename alloc_traits::template rebind_alloc<typename alloc_traits::pointer>>;
233 using underlying_type = basic_sparse_set<Entity, typename alloc_traits::template rebind_alloc<Entity>>;
234 using underlying_iterator = typename underlying_type::basic_iterator;
235 using traits_type = component_traits<Type, Entity>;
236
237 [[nodiscard]] auto &element_at(const std::size_t pos) const {
238 return payload[pos / traits_type::page_size][fast_mod(pos, traits_type::page_size)];
239 }
240
241 auto assure_at_least(const std::size_t pos) {
242 const auto idx = pos / traits_type::page_size;
243
244 if(!(idx < payload.size())) {
245 auto curr = payload.size();
246 allocator_type allocator{get_allocator()};
247 payload.resize(idx + 1u, nullptr);
248
249 ENTT_TRY {
250 for(const auto last = payload.size(); curr < last; ++curr) {
251 payload[curr] = alloc_traits::allocate(allocator, traits_type::page_size);
252 }
253 }
254 ENTT_CATCH {
255 payload.resize(curr);
256 ENTT_THROW;
257 }
258 }
259
260 return payload[idx] + fast_mod(pos, traits_type::page_size);
261 }
262
263 template<typename... Args>
264 auto emplace_element(const Entity entt, const bool force_back, Args &&...args) {
265 const auto it = base_type::try_emplace(entt, force_back);
266
267 ENTT_TRY {
268 auto *elem = to_address(assure_at_least(static_cast<size_type>(it.index())));
269 entt::uninitialized_construct_using_allocator(elem, get_allocator(), std::forward<Args>(args)...);
270 }
271 ENTT_CATCH {
272 base_type::pop(it, it + 1u);
273 ENTT_THROW;
274 }
275
276 return it;
277 }
278
279 void shrink_to_size(const std::size_t sz) {
280 const auto from = (sz + traits_type::page_size - 1u) / traits_type::page_size;
281 allocator_type allocator{get_allocator()};
282
283 for(auto pos = sz, length = base_type::size(); pos < length; ++pos) {
284 if constexpr(traits_type::in_place_delete) {
285 if(base_type::data()[pos] != tombstone) {
286 alloc_traits::destroy(allocator, std::addressof(element_at(pos)));
287 }
288 } else {
289 alloc_traits::destroy(allocator, std::addressof(element_at(pos)));
290 }
291 }
292
293 for(auto pos = from, last = payload.size(); pos < last; ++pos) {
294 alloc_traits::deallocate(allocator, payload[pos], traits_type::page_size);
295 }
296
297 payload.resize(from);
298 payload.shrink_to_fit();
299 }
300
301 void swap_at(const std::size_t lhs, const std::size_t rhs) {
302 using std::swap;
303 swap(element_at(lhs), element_at(rhs));
304 }
305
306 void move_to(const std::size_t lhs, const std::size_t rhs) {
307 auto &elem = element_at(lhs);
308 allocator_type allocator{get_allocator()};
309 entt::uninitialized_construct_using_allocator(to_address(assure_at_least(rhs)), allocator, std::move(elem));
310 alloc_traits::destroy(allocator, std::addressof(elem));
311 }
312
313private:
314 [[nodiscard]] const void *get_at(const std::size_t pos) const final {
315 return std::addressof(element_at(pos));
316 }
317
318 void swap_or_move([[maybe_unused]] const std::size_t from, [[maybe_unused]] const std::size_t to) override {
319 static constexpr bool is_pinned_type = !(std::is_move_constructible_v<Type> && std::is_move_assignable_v<Type>);
320 // use a runtime value to avoid compile-time suppression that drives the code coverage tool crazy
321 ENTT_ASSERT((from + 1u) && !is_pinned_type, "Pinned type");
322
323 if constexpr(!is_pinned_type) {
324 if constexpr(traits_type::in_place_delete) {
325 (base_type::operator[](to) == tombstone) ? move_to(from, to) : swap_at(from, to);
326 } else {
327 swap_at(from, to);
328 }
329 }
330 }
331
332protected:
338 void pop(underlying_iterator first, underlying_iterator last) override {
339 for(allocator_type allocator{get_allocator()}; first != last; ++first) {
340 // cannot use first.index() because it would break with cross iterators
341 auto &elem = element_at(base_type::index(*first));
342
343 if constexpr(traits_type::in_place_delete) {
344 base_type::in_place_pop(first);
345 alloc_traits::destroy(allocator, std::addressof(elem));
346 } else {
347 auto &other = element_at(base_type::size() - 1u);
348 // destroying on exit allows reentrant destructors
349 [[maybe_unused]] auto unused = std::exchange(elem, std::move(other));
350 alloc_traits::destroy(allocator, std::addressof(other));
351 base_type::swap_and_pop(first);
352 }
353 }
354 }
355
357 void pop_all() override {
358 allocator_type allocator{get_allocator()};
359
360 for(auto first = base_type::begin(); !(first.index() < 0); ++first) {
361 if constexpr(traits_type::in_place_delete) {
362 if(*first != tombstone) {
363 base_type::in_place_pop(first);
364 alloc_traits::destroy(allocator, std::addressof(element_at(static_cast<size_type>(first.index()))));
365 }
366 } else {
367 base_type::swap_and_pop(first);
368 alloc_traits::destroy(allocator, std::addressof(element_at(static_cast<size_type>(first.index()))));
369 }
370 }
371 }
372
380 underlying_iterator try_emplace([[maybe_unused]] const Entity entt, [[maybe_unused]] const bool force_back, const void *value) override {
381 if(value != nullptr) {
382 if constexpr(std::is_copy_constructible_v<element_type>) {
383 return emplace_element(entt, force_back, *static_cast<const element_type *>(value));
384 } else {
385 return base_type::end();
386 }
387 } else {
388 if constexpr(std::is_default_constructible_v<element_type>) {
389 return emplace_element(entt, force_back);
390 } else {
391 return base_type::end();
392 }
393 }
394 }
395
396public:
398 using allocator_type = Allocator;
400 using base_type = underlying_type;
402 using element_type = Type;
404 using value_type = element_type;
406 using entity_type = Entity;
408 using size_type = std::size_t;
410 using difference_type = std::ptrdiff_t;
412 using pointer = typename container_type::pointer;
414 using const_pointer = typename alloc_traits::template rebind_traits<typename alloc_traits::const_pointer>::const_pointer;
416 using iterator = internal::storage_iterator<container_type, traits_type::page_size>;
418 using const_iterator = internal::storage_iterator<const container_type, traits_type::page_size>;
420 using reverse_iterator = std::reverse_iterator<iterator>;
422 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
424 using iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::iterator, iterator>>;
426 using const_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::const_iterator, const_iterator>>;
428 using reverse_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::reverse_iterator, reverse_iterator>>;
430 using const_reverse_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::const_reverse_iterator, const_reverse_iterator>>;
432 static constexpr deletion_policy storage_policy{traits_type::in_place_delete};
433
435 basic_storage()
436 : basic_storage{allocator_type{}} {}
437
442 explicit basic_storage(const allocator_type &allocator)
443 : base_type{type_id<element_type>(), storage_policy, allocator},
444 payload{allocator} {}
445
447 basic_storage(const basic_storage &) = delete;
448
453 basic_storage(basic_storage &&other) noexcept
454 : base_type{static_cast<base_type &&>(other)},
455 payload{std::move(other.payload)} {}
456
462 basic_storage(basic_storage &&other, const allocator_type &allocator)
463 : base_type{static_cast<base_type &&>(other), allocator},
464 payload{std::move(other.payload), allocator} {
465 ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a storage is not allowed");
466 }
467
469 // NOLINTNEXTLINE(bugprone-exception-escape)
470 ~basic_storage() override {
471 shrink_to_size(0u);
472 }
473
478 basic_storage &operator=(const basic_storage &) = delete;
479
485 basic_storage &operator=(basic_storage &&other) noexcept {
486 ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a storage is not allowed");
487 swap(other);
488 return *this;
489 }
490
495 void swap(basic_storage &other) noexcept {
496 using std::swap;
497 swap(payload, other.payload);
498 base_type::swap(other);
499 }
500
505 [[nodiscard]] constexpr allocator_type get_allocator() const noexcept {
506 return payload.get_allocator();
507 }
508
517 void reserve(const size_type cap) override {
518 if(cap != 0u) {
519 base_type::reserve(cap);
520 assure_at_least(cap - 1u);
521 }
522 }
523
529 [[nodiscard]] size_type capacity() const noexcept override {
530 return payload.size() * traits_type::page_size;
531 }
532
534 void shrink_to_fit() override {
535 base_type::shrink_to_fit();
536 shrink_to_size(base_type::size());
537 }
538
543 [[nodiscard]] const_pointer raw() const noexcept {
544 return payload.data();
545 }
546
548 [[nodiscard]] pointer raw() noexcept {
549 return payload.data();
550 }
551
559 [[nodiscard]] const_iterator cbegin() const noexcept {
560 const auto pos = static_cast<difference_type>(base_type::size());
561 return const_iterator{&payload, pos};
562 }
563
565 [[nodiscard]] const_iterator begin() const noexcept {
566 return cbegin();
567 }
568
570 [[nodiscard]] iterator begin() noexcept {
571 const auto pos = static_cast<difference_type>(base_type::size());
572 return iterator{&payload, pos};
573 }
574
580 [[nodiscard]] const_iterator cend() const noexcept {
581 return const_iterator{&payload, {}};
582 }
583
585 [[nodiscard]] const_iterator end() const noexcept {
586 return cend();
587 }
588
590 [[nodiscard]] iterator end() noexcept {
591 return iterator{&payload, {}};
592 }
593
601 [[nodiscard]] const_reverse_iterator crbegin() const noexcept {
602 return std::make_reverse_iterator(cend());
603 }
604
606 [[nodiscard]] const_reverse_iterator rbegin() const noexcept {
607 return crbegin();
608 }
609
611 [[nodiscard]] reverse_iterator rbegin() noexcept {
612 return std::make_reverse_iterator(end());
613 }
614
620 [[nodiscard]] const_reverse_iterator crend() const noexcept {
621 return std::make_reverse_iterator(cbegin());
622 }
623
625 [[nodiscard]] const_reverse_iterator rend() const noexcept {
626 return crend();
627 }
628
630 [[nodiscard]] reverse_iterator rend() noexcept {
631 return std::make_reverse_iterator(begin());
632 }
633
644 [[nodiscard]] const value_type &get(const entity_type entt) const noexcept {
645 return element_at(base_type::index(entt));
646 }
647
649 [[nodiscard]] value_type &get(const entity_type entt) noexcept {
650 return const_cast<value_type &>(std::as_const(*this).get(entt));
651 }
652
658 [[nodiscard]] std::tuple<const value_type &> get_as_tuple(const entity_type entt) const noexcept {
659 return std::forward_as_tuple(get(entt));
660 }
661
663 [[nodiscard]] std::tuple<value_type &> get_as_tuple(const entity_type entt) noexcept {
664 return std::forward_as_tuple(get(entt));
665 }
666
679 template<typename... Args>
680 value_type &emplace(const entity_type entt, Args &&...args) {
681 if constexpr(std::is_aggregate_v<value_type> && (sizeof...(Args) != 0u || !std::is_default_constructible_v<value_type>)) {
682 const auto it = emplace_element(entt, false, Type{std::forward<Args>(args)...});
683 return element_at(static_cast<size_type>(it.index()));
684 } else {
685 const auto it = emplace_element(entt, false, std::forward<Args>(args)...);
686 return element_at(static_cast<size_type>(it.index()));
687 }
688 }
689
697 template<typename... Func>
698 value_type &patch(const entity_type entt, Func &&...func) {
699 const auto idx = base_type::index(entt);
700 auto &elem = element_at(idx);
701 (std::forward<Func>(func)(elem), ...);
702 return elem;
703 }
704
719 template<typename It>
720 iterator insert(It first, It last, const value_type &value = {}) {
721 for(; first != last; ++first) {
722 emplace_element(*first, true, value);
723 }
724
725 return begin();
726 }
727
741 template<typename EIt, typename CIt, typename = std::enable_if_t<std::is_same_v<typename std::iterator_traits<CIt>::value_type, value_type>>>
742 iterator insert(EIt first, EIt last, CIt from) {
743 for(; first != last; ++first, ++from) {
744 emplace_element(*first, true, *from);
745 }
746
747 return begin();
748 }
749
758 [[nodiscard]] iterable each() noexcept {
759 return iterable{{base_type::begin(), begin()}, {base_type::end(), end()}};
760 }
761
763 [[nodiscard]] const_iterable each() const noexcept {
764 return const_iterable{{base_type::cbegin(), cbegin()}, {base_type::cend(), cend()}};
765 }
766
774 [[nodiscard]] reverse_iterable reach() noexcept {
775 return reverse_iterable{{base_type::rbegin(), rbegin()}, {base_type::rend(), rend()}};
776 }
777
779 [[nodiscard]] const_reverse_iterable reach() const noexcept {
780 return const_reverse_iterable{{base_type::crbegin(), crbegin()}, {base_type::crend(), crend()}};
781 }
782
783private:
784 container_type payload;
785};
786
788template<typename Type, typename Entity, typename Allocator>
789 class basic_storage<Type, Entity, Allocator, std::enable_if_t<component_traits<Type, Entity>::page_size == 0u>>
790 : public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
791 using alloc_traits = std::allocator_traits<Allocator>;
792 static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
793 using traits_type = component_traits<Type, Entity>;
794
795public:
797 using allocator_type = Allocator;
799 using base_type = basic_sparse_set<Entity, typename alloc_traits::template rebind_alloc<Entity>>;
801 using element_type = Type;
803 using value_type = void;
805 using entity_type = Entity;
807 using size_type = std::size_t;
809 using difference_type = std::ptrdiff_t;
811 using iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::iterator>>;
813 using const_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::const_iterator>>;
815 using reverse_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::reverse_iterator>>;
817 using const_reverse_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::const_reverse_iterator>>;
819 static constexpr deletion_policy storage_policy{traits_type::in_place_delete};
820
822 basic_storage()
823 : basic_storage{allocator_type{}} {}
824
829 explicit basic_storage(const allocator_type &allocator)
830 : base_type{type_id<element_type>(), storage_policy, allocator} {}
831
833 basic_storage(const basic_storage &) = delete;
834
839 basic_storage(basic_storage &&other) noexcept = default;
840
846 basic_storage(basic_storage &&other, const allocator_type &allocator)
847 : base_type{std::move(other), allocator} {}
848
850 ~basic_storage() override = default;
851
856 basic_storage &operator=(const basic_storage &) = delete;
857
863 basic_storage &operator=(basic_storage &&other) noexcept = default;
864
869 [[nodiscard]] constexpr allocator_type get_allocator() const noexcept {
870 // std::allocator<void> has no cross constructors (waiting for C++20)
871 if constexpr(std::is_void_v<element_type> && !std::is_constructible_v<allocator_type, typename base_type::allocator_type>) {
872 return allocator_type{};
873 } else {
874 return allocator_type{base_type::get_allocator()};
875 }
876 }
877
887 void get([[maybe_unused]] const entity_type entt) const noexcept {
888 ENTT_ASSERT(base_type::contains(entt), "Invalid entity");
889 }
890
896 [[nodiscard]] std::tuple<> get_as_tuple([[maybe_unused]] const entity_type entt) const noexcept {
897 ENTT_ASSERT(base_type::contains(entt), "Invalid entity");
898 return std::tuple{};
899 }
900
910 void emplace(const entity_type entt) {
911 base_type::try_emplace(entt, false);
912 }
913
920 template<typename... Func>
921 void patch([[maybe_unused]] const entity_type entt, Func &&...func) {
922 ENTT_ASSERT(base_type::contains(entt), "Invalid entity");
923 (std::forward<Func>(func)(), ...);
924 }
925
932 template<typename It>
933 void insert(It first, It last) {
934 for(; first != last; ++first) {
935 base_type::try_emplace(*first, true);
936 }
937 }
938
946 [[nodiscard]] iterable each() noexcept {
947 return iterable{base_type::begin(), base_type::end()};
948 }
949
951 [[nodiscard]] const_iterable each() const noexcept {
952 return const_iterable{base_type::cbegin(), base_type::cend()};
953 }
954
962 [[nodiscard]] reverse_iterable reach() noexcept {
963 return reverse_iterable{{base_type::rbegin()}, {base_type::rend()}};
964 }
965
967 [[nodiscard]] const_reverse_iterable reach() const noexcept {
968 return const_reverse_iterable{{base_type::crbegin()}, {base_type::crend()}};
969 }
970};
971
977template<typename Entity, typename Allocator>
978 class basic_storage<Entity, Entity, Allocator>
979 : public basic_sparse_set<Entity, Allocator> {
980 using alloc_traits = std::allocator_traits<Allocator>;
981 static_assert(std::is_same_v<typename alloc_traits::value_type, Entity>, "Invalid value type");
982 using underlying_iterator = typename basic_sparse_set<Entity, Allocator>::basic_iterator;
983 using traits_type = entt_traits<Entity>;
984
985 auto from_placeholder() noexcept {
986 const auto entt = traits_type::combine(static_cast<typename traits_type::entity_type>(placeholder), {});
987 ENTT_ASSERT(entt != null, "No more entities available");
988 placeholder += static_cast<size_type>(entt != null);
989 return entt;
990 }
991
992 auto next() noexcept {
993 entity_type entt = from_placeholder();
994
995 while(base_type::current(entt) != traits_type::to_version(tombstone) && entt != null) {
996 entt = from_placeholder();
997 }
998
999 return entt;
1000 }
1001
1002protected:
1004 void pop_all() override {
1005 base_type::pop_all();
1006 placeholder = {};
1007 }
1008
1014 underlying_iterator try_emplace(const Entity hint, const bool, const void *) override {
1015 return base_type::find(generate(hint));
1016 }
1017
1018public:
1020 using allocator_type = Allocator;
1022 using base_type = basic_sparse_set<Entity, Allocator>;
1024 using element_type = Entity;
1026 using value_type = void;
1028 using entity_type = Entity;
1030 using size_type = std::size_t;
1032 using difference_type = std::ptrdiff_t;
1034 using iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::iterator>>;
1036 using const_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::const_iterator>>;
1038 using reverse_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::reverse_iterator>>;
1040 using const_reverse_iterable = iterable_adaptor<internal::extended_storage_iterator<typename base_type::const_reverse_iterator>>;
1042 static constexpr deletion_policy storage_policy = deletion_policy::swap_only;
1043
1045 basic_storage()
1046 : basic_storage{allocator_type{}} {
1047 }
1048
1053 explicit basic_storage(const allocator_type &allocator)
1054 : base_type{type_id<void>(), storage_policy, allocator} {}
1055
1057 basic_storage(const basic_storage &) = delete;
1058
1063 // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
1064 basic_storage(basic_storage &&other) noexcept
1065 : base_type{static_cast<base_type &&>(other)},
1066 placeholder{other.placeholder} {}
1067
1073 // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
1074 basic_storage(basic_storage &&other, const allocator_type &allocator)
1075 : base_type{static_cast<base_type &&>(other), allocator},
1076 placeholder{other.placeholder} {}
1077
1079 ~basic_storage() override = default;
1080
1085 basic_storage &operator=(const basic_storage &) = delete;
1086
1092 basic_storage &operator=(basic_storage &&other) noexcept {
1093 placeholder = other.placeholder;
1094 base_type::operator=(std::move(other));
1095 return *this;
1096 }
1097
1102 void swap(basic_storage &other) noexcept {
1103 using std::swap;
1104 swap(placeholder, other.placeholder);
1105 base_type::swap(other);
1106 }
1107
1117 void get([[maybe_unused]] const entity_type entt) const noexcept {
1118 ENTT_ASSERT(base_type::index(entt) < base_type::free_list(), "The requested entity is not a live one");
1119 }
1120
1126 [[nodiscard]] std::tuple<> get_as_tuple([[maybe_unused]] const entity_type entt) const noexcept {
1127 ENTT_ASSERT(base_type::index(entt) < base_type::free_list(), "The requested entity is not a live one");
1128 return std::tuple{};
1129 }
1130
1135 entity_type generate() {
1136 const auto len = base_type::free_list();
1137 const auto entt = (len == base_type::size()) ? next() : base_type::data()[len];
1138 return *base_type::try_emplace(entt, true);
1139 }
1140
1150 entity_type generate(const entity_type hint) {
1151 if(hint != null && hint != tombstone) {
1152 if(const auto curr = traits_type::construct(traits_type::to_entity(hint), base_type::current(hint)); curr == tombstone || !(base_type::index(curr) < base_type::free_list())) {
1153 return *base_type::try_emplace(hint, true);
1154 }
1155 }
1156
1157 return generate();
1158 }
1159
1166 template<typename It>
1167 void generate(It first, It last) {
1168 for(const auto sz = base_type::size(); first != last && base_type::free_list() != sz; ++first) {
1169 *first = *base_type::try_emplace(base_type::data()[base_type::free_list()], true);
1170 }
1171
1172 for(; first != last; ++first) {
1173 *first = *base_type::try_emplace(next(), true);
1174 }
1175 }
1176
1183 template<typename... Func>
1184 void patch([[maybe_unused]] const entity_type entt, Func &&...func) {
1185 ENTT_ASSERT(base_type::index(entt) < base_type::free_list(), "The requested entity is not a live one");
1186 (std::forward<Func>(func)(), ...);
1187 }
1188
1196 [[nodiscard]] iterable each() noexcept {
1197 return std::as_const(*this).each();
1198 }
1199
1201 [[nodiscard]] const_iterable each() const noexcept {
1202 const auto it = base_type::cend();
1203 const auto offset = static_cast<difference_type>(base_type::free_list());
1204 return const_iterable{it - offset, it};
1205 }
1206
1214 [[nodiscard]] reverse_iterable reach() noexcept {
1215 return std::as_const(*this).reach();
1216 }
1217
1219 [[nodiscard]] const_reverse_iterable reach() const noexcept {
1220 const auto it = base_type::crbegin();
1221 const auto offset = static_cast<difference_type>(base_type::free_list());
1222 return const_reverse_iterable{it, it + offset};
1223 }
1224
1232 void start_from(const entity_type hint) {
1233 placeholder = static_cast<size_type>(traits_type::to_entity(hint));
1234 }
1235
1236private:
1237 size_type placeholder{};
1238};
1239
1240} // namespace entt
1241
1242#endif
entt::basic_entt_traits::entity_type
typename Traits::entity_type entity_type
Underlying entity type.
Definition entity.hpp:71
entt::basic_entt_traits::construct
static constexpr value_type construct(const entity_type entity, const version_type version) noexcept
Constructs an identifier from its parts.
Definition entity.hpp:131
entt::basic_entt_traits::to_entity
static constexpr entity_type to_entity(const value_type value) noexcept
Returns the entity part once converted to the underlying type.
Definition entity.hpp:94
entt::basic_entt_traits::combine
static constexpr value_type combine(const entity_type lhs, const entity_type rhs) noexcept
Combines two identifiers in a single one.
Definition entity.hpp:149
entt::basic_entt_traits::to_version
static constexpr version_type to_version(const value_type value) noexcept
Returns the version part once converted to the underlying type.
Definition entity.hpp:103
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::begin
iterator begin() const noexcept
Definition sparse_set.hpp:650
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::cbegin
const_iterator cbegin() const noexcept
Definition sparse_set.hpp:656
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::try_emplace
virtual basic_iterator try_emplace(const Entity entt, const bool force_back, const void *=nullptr)
Definition sparse_set.hpp:344
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::pop_all
virtual void pop_all()
Definition sparse_set.hpp:314
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::swap_and_pop
void swap_and_pop(const basic_iterator it)
Definition sparse_set.hpp:264
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::end
iterator end() const noexcept
Definition sparse_set.hpp:665
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::rend
reverse_iterator rend() const noexcept
Definition sparse_set.hpp:697
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::data
pointer data() const noexcept
Definition sparse_set.hpp:638
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::reserve
virtual void reserve(const size_type cap)
Definition sparse_set.hpp:546
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::size
size_type size() const noexcept
Definition sparse_set.hpp:614
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::operator=
basic_sparse_set & operator=(const basic_sparse_set &)=delete
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::shrink_to_fit
virtual void shrink_to_fit()
Definition sparse_set.hpp:560
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::swap
void swap(basic_sparse_set &other) noexcept
Definition sparse_set.hpp:496
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::find
const_iterator find(const entity_type entt) const noexcept
Definition sparse_set.hpp:712
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::pop
virtual void pop(basic_iterator first, basic_iterator last)
Definition sparse_set.hpp:293
entt::basic_sparse_set::current
version_type current(const entity_type entt) const noexcept
Returns the contained version for an identifier.
Definition sparse_set.hpp:735
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::contains
bool contains(const entity_type entt) const noexcept
Definition sparse_set.hpp:721
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::cend
const_iterator cend() const noexcept
Definition sparse_set.hpp:670
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::in_place_pop
void in_place_pop(const basic_iterator it)
Definition sparse_set.hpp:282
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::crend
const_reverse_iterator crend() const noexcept
Definition sparse_set.hpp:702
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::get_allocator
constexpr allocator_type get_allocator() const noexcept
Definition sparse_set.hpp:509
entt::basic_sparse_set< Entity, std::allocator_traits< Allocator >::template rebind_alloc< Entity > >::value
const void * value(const entity_type entt) const noexcept
Definition sparse_set.hpp:776
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::rbegin
reverse_iterator rbegin() const noexcept
Definition sparse_set.hpp:683
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::operator[]
entity_type operator[](const size_type pos) const noexcept
Definition sparse_set.hpp:761
entt::basic_sparse_set::free_list
size_type free_list() const noexcept
Returns data on the free list whose meaning depends on the mode.
Definition sparse_set.hpp:525
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::basic_iterator
internal::sparse_set_iterator< packed_container_type > basic_iterator
Definition sparse_set.hpp:247
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::crbegin
const_reverse_iterator crbegin() const noexcept
Definition sparse_set.hpp:688
entt::basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > >::index
size_type index(const entity_type entt) const noexcept
Definition sparse_set.hpp:751
entt::basic_sparse_set< Entity, std::allocator_traits< Allocator >::template rebind_alloc< Entity > >::basic_sparse_set
basic_sparse_set()
Definition sparse_set.hpp:408
entt::basic_storage< Entity, Entity, Allocator >::reach
const_reverse_iterable reach() const noexcept
Returns a reverse iterable object to use to visit a storage.
Definition storage.hpp:1219
entt::basic_storage< Entity, Entity, Allocator >::size_type
std::size_t size_type
Unsigned integer type.
Definition storage.hpp:1030
entt::basic_storage< Entity, Entity, Allocator >::reverse_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::reverse_iterator > > reverse_iterable
Extended reverse iterable storage proxy.
Definition storage.hpp:1038
entt::basic_storage< Entity, Entity, Allocator >::storage_policy
static constexpr deletion_policy storage_policy
Storage deletion policy.
Definition storage.hpp:1042
entt::basic_storage< Entity, Entity, Allocator >::get
void get(const entity_type entt) const noexcept
Returns the object assigned to an entity, that is void.
Definition storage.hpp:1117
entt::basic_storage< Entity, Entity, Allocator >::value_type
void value_type
Type of the objects assigned to entities.
Definition storage.hpp:1026
entt::basic_storage< Entity, Entity, Allocator >::generate
entity_type generate(const entity_type hint)
Creates a new identifier or recycles a destroyed one.
Definition storage.hpp:1150
entt::basic_storage< Entity, Entity, Allocator >::const_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::const_iterator > > const_iterable
Constant extended iterable storage proxy.
Definition storage.hpp:1036
entt::basic_storage< Entity, Entity, Allocator >::entity_type
Entity entity_type
Underlying entity identifier.
Definition storage.hpp:1028
entt::basic_storage< Entity, Entity, Allocator >::pop_all
void pop_all() override
Erases all entities of a storage.
Definition storage.hpp:1004
entt::basic_storage< Entity, Entity, Allocator >::~basic_storage
~basic_storage() override=default
Default destructor.
entt::basic_storage< Entity, Entity, Allocator >::try_emplace
underlying_iterator try_emplace(const Entity hint, const bool, const void *) override
Assigns an entity to a storage.
Definition storage.hpp:1014
entt::basic_storage< Entity, Entity, Allocator >::operator=
basic_storage & operator=(basic_storage &&other) noexcept
Move assignment operator.
Definition storage.hpp:1092
entt::basic_storage< Entity, Entity, Allocator >::generate
entity_type generate()
Creates a new identifier or recycles a destroyed one.
Definition storage.hpp:1135
entt::basic_storage< Entity, Entity, Allocator >::reach
reverse_iterable reach() noexcept
Returns a reverse iterable object to use to visit a storage.
Definition storage.hpp:1214
entt::basic_storage< Entity, Entity, Allocator >::basic_storage
basic_storage(basic_storage &&other, const allocator_type &allocator)
Allocator-extended move constructor.
Definition storage.hpp:1074
entt::basic_storage< Entity, Entity, Allocator >::difference_type
std::ptrdiff_t difference_type
Signed integer type.
Definition storage.hpp:1032
entt::basic_storage< Entity, Entity, Allocator >::swap
void swap(basic_storage &other) noexcept
Exchanges the contents with those of a given storage.
Definition storage.hpp:1102
entt::basic_storage< Entity, Entity, Allocator >::element_type
Entity element_type
Element type.
Definition storage.hpp:1024
entt::basic_storage< Entity, Entity, Allocator >::each
const_iterable each() const noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:1201
entt::basic_storage< Entity, Entity, Allocator >::basic_storage
basic_storage(const allocator_type &allocator)
Constructs an empty container with a given allocator.
Definition storage.hpp:1053
entt::basic_storage< Entity, Entity, Allocator >::generate
void generate(It first, It last)
Assigns each element in a range an identifier.
Definition storage.hpp:1167
entt::basic_storage< Entity, Entity, Allocator >::allocator_type
Allocator allocator_type
Allocator type.
Definition storage.hpp:1020
entt::basic_storage< Entity, Entity, Allocator >::const_reverse_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::const_reverse_iterator > > const_reverse_iterable
Constant extended reverse iterable storage proxy.
Definition storage.hpp:1040
entt::basic_storage< Entity, Entity, Allocator >::iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::iterator > > iterable
Extended iterable storage proxy.
Definition storage.hpp:1034
entt::basic_storage< Entity, Entity, Allocator >::base_type
basic_sparse_set< Entity, Allocator > base_type
Base type.
Definition storage.hpp:1022
entt::basic_storage< Entity, Entity, Allocator >::basic_storage
basic_storage(basic_storage &&other) noexcept
Move constructor.
Definition storage.hpp:1064
entt::basic_storage< Entity, Entity, Allocator >::each
iterable each() noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:1196
entt::basic_storage< Entity, Entity, Allocator >::basic_storage
basic_storage(const basic_storage &)=delete
Default copy constructor, deleted on purpose.
entt::basic_storage< Entity, Entity, Allocator >::patch
void patch(const entity_type entt, Func &&...func)
Updates a given identifier.
Definition storage.hpp:1184
entt::basic_storage< Entity, Entity, Allocator >::basic_storage
basic_storage()
Default constructor.
Definition storage.hpp:1045
entt::basic_storage< Entity, Entity, Allocator >::start_from
void start_from(const entity_type hint)
Sets the starting identifier for generation.
Definition storage.hpp:1232
entt::basic_storage< Entity, Entity, Allocator >::operator=
basic_storage & operator=(const basic_storage &)=delete
Default copy assignment operator, deleted on purpose.
entt::basic_storage< Entity, Entity, Allocator >::get_as_tuple
std::tuple get_as_tuple(const entity_type entt) const noexcept
Returns an empty tuple.
Definition storage.hpp:1126
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::~basic_storage
~basic_storage() override=default
Default destructor.
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::value_type
void value_type
Type of the objects assigned to entities.
Definition storage.hpp:803
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::operator=
basic_storage & operator=(const basic_storage &)=delete
Default copy assignment operator, deleted on purpose.
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::get_allocator
constexpr allocator_type get_allocator() const noexcept
Returns the associated allocator.
Definition storage.hpp:869
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::base_type
basic_sparse_set< Entity, typename alloc_traits::template rebind_alloc< Entity > > base_type
Base type.
Definition storage.hpp:799
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::insert
void insert(It first, It last)
Assigns entities to a storage.
Definition storage.hpp:933
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::element_type
Type element_type
Element type.
Definition storage.hpp:801
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::emplace
void emplace(const entity_type entt)
Assigns an entity to a storage and constructs its object.
Definition storage.hpp:910
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::storage_policy
static constexpr deletion_policy storage_policy
Storage deletion policy.
Definition storage.hpp:819
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::get_as_tuple
std::tuple get_as_tuple(const entity_type entt) const noexcept
Returns an empty tuple.
Definition storage.hpp:896
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::patch
void patch(const entity_type entt, Func &&...func)
Updates the instance assigned to a given entity in-place.
Definition storage.hpp:921
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::reach
reverse_iterable reach() noexcept
Returns a reverse iterable object to use to visit a storage.
Definition storage.hpp:962
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::basic_storage
basic_storage()
Default constructor.
Definition storage.hpp:822
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::basic_storage
basic_storage(const allocator_type &allocator)
Constructs an empty container with a given allocator.
Definition storage.hpp:829
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::basic_storage
basic_storage(basic_storage &&other, const allocator_type &allocator)
Allocator-extended move constructor.
Definition storage.hpp:846
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::iterator > > iterable
Extended iterable storage proxy.
Definition storage.hpp:811
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::reverse_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::reverse_iterator > > reverse_iterable
Extended reverse iterable storage proxy.
Definition storage.hpp:815
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::basic_storage
basic_storage(basic_storage &&other) noexcept=default
Move constructor.
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::const_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::const_iterator > > const_iterable
Constant extended iterable storage proxy.
Definition storage.hpp:813
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::basic_storage
basic_storage(const basic_storage &)=delete
Default copy constructor, deleted on purpose.
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::get
void get(const entity_type entt) const noexcept
Returns the object assigned to an entity, that is void.
Definition storage.hpp:887
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::size_type
std::size_t size_type
Unsigned integer type.
Definition storage.hpp:807
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::difference_type
std::ptrdiff_t difference_type
Signed integer type.
Definition storage.hpp:809
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::each
const_iterable each() const noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:951
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::reach
const_reverse_iterable reach() const noexcept
Returns a reverse iterable object to use to visit a storage.
Definition storage.hpp:967
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::operator=
basic_storage & operator=(basic_storage &&other) noexcept=default
Move assignment operator.
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::const_reverse_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::const_reverse_iterator > > const_reverse_iterable
Constant extended reverse iterable storage proxy.
Definition storage.hpp:817
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::allocator_type
Allocator allocator_type
Allocator type.
Definition storage.hpp:797
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::each
iterable each() noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:946
entt::basic_storage< Type, Entity, Allocator, std::enable_if_t< component_traits< Type, Entity >::page_size==0u > >::entity_type
Entity entity_type
Underlying entity identifier.
Definition storage.hpp:805
entt::basic_storage::end
iterator end() noexcept
Returns an iterator to the end.
Definition storage.hpp:590
entt::basic_storage::~basic_storage
~basic_storage() override
Default destructor.
Definition storage.hpp:470
entt::basic_storage::basic_storage
basic_storage()
Default constructor.
Definition storage.hpp:435
entt::basic_storage::insert
iterator insert(EIt first, EIt last, CIt from)
Assigns one or more entities to a storage and constructs their objects from a given range.
Definition storage.hpp:742
entt::basic_storage::rbegin
const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the beginning.
Definition storage.hpp:606
entt::basic_storage::end
const_iterator end() const noexcept
Returns an iterator to the end.
Definition storage.hpp:585
entt::basic_storage::raw
const_pointer raw() const noexcept
Direct access to the array of objects.
Definition storage.hpp:543
entt::basic_storage::pop_all
void pop_all() override
Erases all entities of a storage.
Definition storage.hpp:357
entt::basic_storage::basic_storage
basic_storage(basic_storage &&other) noexcept
Move constructor.
Definition storage.hpp:453
entt::basic_storage::get
const value_type & get(const entity_type entt) const noexcept
Returns the object assigned to an entity.
Definition storage.hpp:644
entt::basic_storage::cend
const_iterator cend() const noexcept
Returns an iterator to the end.
Definition storage.hpp:580
entt::basic_storage::capacity
size_type capacity() const noexcept override
Returns the number of elements that a storage has currently allocated space for.
Definition storage.hpp:529
entt::basic_storage< Type >::const_reverse_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::const_reverse_iterator, const_reverse_iterator > > const_reverse_iterable
Definition storage.hpp:430
entt::basic_storage::get_allocator
constexpr allocator_type get_allocator() const noexcept
Returns the associated allocator.
Definition storage.hpp:505
entt::basic_storage< Type >::const_pointer
typename alloc_traits::template rebind_traits< typename alloc_traits::const_pointer >::const_pointer const_pointer
Definition storage.hpp:414
entt::basic_storage::each
const_iterable each() const noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:763
entt::basic_storage::swap
void swap(basic_storage &other) noexcept
Exchanges the contents with those of a given storage.
Definition storage.hpp:495
entt::basic_storage< Type >::value_type
element_type value_type
Definition storage.hpp:404
entt::basic_storage::rbegin
reverse_iterator rbegin() noexcept
Returns a reverse iterator to the beginning.
Definition storage.hpp:611
entt::basic_storage< Type >::iterator
internal::storage_iterator< container_type, traits_type::page_size > iterator
Definition storage.hpp:416
entt::basic_storage::begin
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition storage.hpp:565
entt::basic_storage< Type >::base_type
underlying_type base_type
Definition storage.hpp:400
entt::basic_storage::rend
reverse_iterator rend() noexcept
Returns a reverse iterator to the end.
Definition storage.hpp:630
entt::basic_storage::operator=
basic_storage & operator=(basic_storage &&other) noexcept
Move assignment operator.
Definition storage.hpp:485
entt::basic_storage< Type >::entity_type
Entity entity_type
Definition storage.hpp:406
entt::basic_storage::rend
const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the end.
Definition storage.hpp:625
entt::basic_storage::try_emplace
underlying_iterator try_emplace(const Entity entt, const bool force_back, const void *value) override
Assigns an entity to a storage.
Definition storage.hpp:380
entt::basic_storage::cbegin
const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
Definition storage.hpp:559
entt::basic_storage< Type >::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition storage.hpp:422
entt::basic_storage::patch
value_type & patch(const entity_type entt, Func &&...func)
Updates the instance assigned to a given entity in-place.
Definition storage.hpp:698
entt::basic_storage< Type >::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Definition storage.hpp:420
entt::basic_storage::size_type
std::size_t size_type
Unsigned integer type.
Definition storage.hpp:408
entt::basic_storage::insert
iterator insert(It first, It last, const value_type &value={})
Assigns one or more entities to a storage and constructs their objects from a given instance.
Definition storage.hpp:720
entt::basic_storage::pop
void pop(underlying_iterator first, underlying_iterator last) override
Erases entities from a storage.
Definition storage.hpp:338
entt::basic_storage< Type >::pointer
typename container_type::pointer pointer
Definition storage.hpp:412
entt::basic_storage::reach
reverse_iterable reach() noexcept
Returns a reverse iterable object to use to visit a storage.
Definition storage.hpp:774
entt::basic_storage< Type >::reverse_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::reverse_iterator, reverse_iterator > > reverse_iterable
Definition storage.hpp:428
entt::basic_storage< Type >::iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::iterator, iterator > > iterable
Definition storage.hpp:424
entt::basic_storage::raw
pointer raw() noexcept
Direct access to the array of objects.
Definition storage.hpp:548
entt::basic_storage::get_as_tuple
std::tuple< value_type & > get_as_tuple(const entity_type entt) noexcept
Returns the object assigned to an entity as a tuple.
Definition storage.hpp:663
entt::basic_storage< Type >::difference_type
std::ptrdiff_t difference_type
Definition storage.hpp:410
entt::basic_storage::get
value_type & get(const entity_type entt) noexcept
Returns the object assigned to an entity.
Definition storage.hpp:649
entt::basic_storage::crend
const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the end.
Definition storage.hpp:620
entt::basic_storage::reach
const_reverse_iterable reach() const noexcept
Returns a reverse iterable object to use to visit a storage.
Definition storage.hpp:779
entt::basic_storage::each
iterable each() noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:758
entt::basic_storage::operator=
basic_storage & operator=(const basic_storage &)=delete
Default copy assignment operator, deleted on purpose.
entt::basic_storage< Type >::element_type
Type element_type
Definition storage.hpp:402
entt::basic_storage::reserve
void reserve(const size_type cap) override
Increases the capacity of a storage.
Definition storage.hpp:517
entt::basic_storage::basic_storage
basic_storage(const allocator_type &allocator)
Constructs an empty storage with a given allocator.
Definition storage.hpp:442
entt::basic_storage::emplace
value_type & emplace(const entity_type entt, Args &&...args)
Assigns an entity to a storage and constructs its object.
Definition storage.hpp:680
entt::basic_storage::get_as_tuple
std::tuple< const value_type & > get_as_tuple(const entity_type entt) const noexcept
Returns the object assigned to an entity as a tuple.
Definition storage.hpp:658
entt::basic_storage::shrink_to_fit
void shrink_to_fit() override
Requests the removal of unused capacity.
Definition storage.hpp:534
entt::basic_storage::crbegin
const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the beginning.
Definition storage.hpp:601
entt::basic_storage< Type >::const_iterator
internal::storage_iterator< const container_type, traits_type::page_size > const_iterator
Definition storage.hpp:418
entt::basic_storage::basic_storage
basic_storage(basic_storage &&other, const allocator_type &allocator)
Allocator-extended move constructor.
Definition storage.hpp:462
entt::basic_storage< Type >::const_iterable
iterable_adaptor< internal::extended_storage_iterator< typename base_type::const_iterator, const_iterator > > const_iterable
Definition storage.hpp:426
entt::basic_storage::basic_storage
basic_storage(const basic_storage &)=delete
Default copy constructor, deleted on purpose.
entt::basic_storage::begin
iterator begin() noexcept
Returns an iterator to the beginning.
Definition storage.hpp:570
entt::basic_storage< Type >::storage_policy
static constexpr deletion_policy storage_policy
Definition storage.hpp:432
entt::basic_storage::allocator_type
Allocator allocator_type
Allocator type.
Definition storage.hpp:398
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::fast_mod
constexpr std::enable_if_t< std::is_unsigned_v< Type >, Type > fast_mod(const Type value, const std::size_t mod) noexcept
Fast module utility function (powers of two only).
Definition bit.hpp:63
entt::null
constexpr null_t null
Compile-time constant for null entities.
Definition entity.hpp:375
entt::tombstone
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
Definition entity.hpp:384
entt::uninitialized_construct_using_allocator
constexpr Type * uninitialized_construct_using_allocator(Type *value, const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:238
entt::get
constexpr get_t< Type... > get
Variable template for lists of observed elements.
Definition fwd.hpp:167
entt::operator<=
constexpr bool operator<=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:263
entt::operator<
constexpr bool operator<(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:250
entt::operator+
constexpr type_list< Type..., Other... > operator+(type_list< Type... >, type_list< Other... >)
Concatenates multiple type lists.
Definition type_traits.hpp:210
entt::deletion_policy
deletion_policy
Storage deletion policy.
Definition fwd.hpp:17
entt::deletion_policy::swap_only
@ swap_only
Swap-only deletion policy.
Definition fwd.hpp:23
entt::operator!=
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:238
entt::operator>=
constexpr bool operator>=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:289
entt::type_id
const type_info & type_id() noexcept
Returns the type info object associated to a given type.
Definition type_info.hpp:259
entt::any_policy::ref
@ ref
Aliasing mode, non-const reference.
Definition fwd.hpp:19
entt::operator>
constexpr bool operator>(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:276
entt::to_address
constexpr auto to_address(Type &&ptr) noexcept
Unwraps fancy pointers, does nothing otherwise (waiting for C++20).
Definition memory.hpp:20
entt::operator==
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Definition hashed_string.hpp:226
entt::component_traits
Common way to access various properties of components.
Definition component.hpp:43
entt::component_traits< Type, Entity >::in_place_delete
static constexpr bool in_place_delete
Definition component.hpp:52
entt::component_traits< Type, Entity >::page_size
static constexpr std::size_t page_size
Definition component.hpp:54
entt::entt_traits
Entity traits.
Definition entity.hpp:163
entt::iterable_adaptor
Utility class to create an iterable object from a pair of iterators.
Definition iterator.hpp:141