EnTT 3.13.0
Loading...
Searching...
No Matches
view.hpp
1#ifndef ENTT_ENTITY_VIEW_HPP
2#define ENTT_ENTITY_VIEW_HPP
3
4#include <array>
5#include <iterator>
6#include <tuple>
7#include <type_traits>
8#include <utility>
9#include "../config/config.h"
10#include "../core/iterator.hpp"
11#include "../core/type_traits.hpp"
12#include "entity.hpp"
13#include "fwd.hpp"
14
15namespace entt {
16
18namespace internal {
19
20template<typename Type, typename Entity>
21[[nodiscard]] bool all_of_but(const std::size_t index, const Type *const *it, const std::size_t len, const Entity entt) noexcept {
22 std::size_t pos{};
23 for(; (pos != index) && it[pos]->contains(entt); ++pos) {}
24
25 if(pos == index) {
26 for(++pos; (pos != len) && it[pos]->contains(entt); ++pos) {}
27 }
28
29 return pos == len;
30}
31
32template<typename Type, typename Entity>
33[[nodiscard]] bool none_of(const Type *const *it, const std::size_t len, const Entity entt) noexcept {
34 std::size_t pos{};
35 for(; (pos != len) && !(it[pos] && it[pos]->contains(entt)); ++pos) {}
36 return pos == len;
37}
38
39template<typename Type>
40[[nodiscard]] bool fully_initialized(const Type *const *it, const std::size_t len) noexcept {
41 std::size_t pos{};
42 for(; (pos != len) && it[pos]; ++pos) {}
43 return pos == len;
44}
45
46template<typename Result, typename View, typename Other, std::size_t... VGet, std::size_t... VExclude, std::size_t... OGet, std::size_t... OExclude>
47[[nodiscard]] Result view_pack(const View &view, const Other &other, std::index_sequence<VGet...>, std::index_sequence<VExclude...>, std::index_sequence<OGet...>, std::index_sequence<OExclude...>) {
48 Result elem{};
49 // friend-initialization, avoid multiple calls to refresh
50 elem.pools = {view.template storage<VGet>()..., other.template storage<OGet>()...};
51 elem.filter = {view.template storage<sizeof...(VGet) + VExclude>()..., other.template storage<sizeof...(OGet) + OExclude>()...};
52 elem.refresh();
53 return elem;
54}
55
56template<typename Type, std::size_t Get, std::size_t Exclude>
57class view_iterator final {
58 using iterator_type = typename Type::const_iterator;
59
60 [[nodiscard]] bool valid(const typename iterator_type::value_type entt) const noexcept {
61 return ((Get != 1u) || (entt != tombstone)) && all_of_but(index, pools.data(), Get, entt) && none_of(filter.data(), Exclude, entt);
62 }
63
64public:
65 using value_type = typename iterator_type::value_type;
66 using pointer = typename iterator_type::pointer;
67 using reference = typename iterator_type::reference;
68 using difference_type = typename iterator_type::difference_type;
69 using iterator_category = std::forward_iterator_tag;
70
71 constexpr view_iterator() noexcept
72 : it{},
73 last{},
74 pools{},
75 filter{},
76 index{} {}
77
78 view_iterator(iterator_type curr, iterator_type to, std::array<const Type *, Get> value, std::array<const Type *, Exclude> excl, const std::size_t idx) noexcept
79 : it{curr},
80 last{to},
81 pools{value},
82 filter{excl},
83 index{idx} {
84 while(it != last && !valid(*it)) {
85 ++it;
86 }
87 }
88
89 view_iterator &operator++() noexcept {
90 while(++it != last && !valid(*it)) {}
91 return *this;
92 }
93
94 view_iterator operator++(int) noexcept {
95 view_iterator orig = *this;
96 return ++(*this), orig;
97 }
98
99 [[nodiscard]] pointer operator->() const noexcept {
100 return &*it;
101 }
102
103 [[nodiscard]] reference operator*() const noexcept {
104 return *operator->();
105 }
106
107 template<typename LhsType, auto... LhsArgs, typename RhsType, auto... RhsArgs>
108 friend constexpr bool operator==(const view_iterator<LhsType, LhsArgs...> &, const view_iterator<RhsType, RhsArgs...> &) noexcept;
109
110private:
111 iterator_type it;
112 iterator_type last;
113 std::array<const Type *, Get> pools;
114 std::array<const Type *, Exclude> filter;
115 std::size_t index;
116};
117
118template<typename LhsType, auto... LhsArgs, typename RhsType, auto... RhsArgs>
119[[nodiscard]] constexpr bool operator==(const view_iterator<LhsType, LhsArgs...> &lhs, const view_iterator<RhsType, RhsArgs...> &rhs) noexcept {
120 return lhs.it == rhs.it;
121}
122
123template<typename LhsType, auto... LhsArgs, typename RhsType, auto... RhsArgs>
124[[nodiscard]] constexpr bool operator!=(const view_iterator<LhsType, LhsArgs...> &lhs, const view_iterator<RhsType, RhsArgs...> &rhs) noexcept {
125 return !(lhs == rhs);
126}
127
128template<typename It, typename... Type>
129struct extended_view_iterator final {
130 using iterator_type = It;
131 using difference_type = std::ptrdiff_t;
132 using value_type = decltype(std::tuple_cat(std::make_tuple(*std::declval<It>()), std::declval<Type>().get_as_tuple({})...));
133 using pointer = input_iterator_pointer<value_type>;
134 using reference = value_type;
135 using iterator_category = std::input_iterator_tag;
136 using iterator_concept = std::forward_iterator_tag;
137
138 constexpr extended_view_iterator()
139 : it{},
140 pools{} {}
141
142 extended_view_iterator(iterator_type from, std::tuple<Type *...> value)
143 : it{from},
144 pools{value} {}
145
146 extended_view_iterator &operator++() noexcept {
147 return ++it, *this;
148 }
149
150 extended_view_iterator operator++(int) noexcept {
151 extended_view_iterator orig = *this;
152 return ++(*this), orig;
153 }
154
155 [[nodiscard]] reference operator*() const noexcept {
156 return std::apply([entt = *it](auto *...curr) { return std::tuple_cat(std::make_tuple(entt), curr->get_as_tuple(entt)...); }, pools);
157 }
158
159 [[nodiscard]] pointer operator->() const noexcept {
160 return operator*();
161 }
162
163 [[nodiscard]] constexpr iterator_type base() const noexcept {
164 return it;
165 }
166
167 template<typename... Lhs, typename... Rhs>
168 friend bool constexpr operator==(const extended_view_iterator<Lhs...> &, const extended_view_iterator<Rhs...> &) noexcept;
169
170private:
171 It it;
172 std::tuple<Type *...> pools;
173};
174
175template<typename... Lhs, typename... Rhs>
176[[nodiscard]] constexpr bool operator==(const extended_view_iterator<Lhs...> &lhs, const extended_view_iterator<Rhs...> &rhs) noexcept {
177 return lhs.it == rhs.it;
178}
179
180template<typename... Lhs, typename... Rhs>
181[[nodiscard]] constexpr bool operator!=(const extended_view_iterator<Lhs...> &lhs, const extended_view_iterator<Rhs...> &rhs) noexcept {
182 return !(lhs == rhs);
183}
184
185} // namespace internal
206template<typename, typename, typename>
207class basic_view;
208
216template<typename Type, std::size_t Get, std::size_t Exclude>
218 template<typename Return, typename View, typename Other, std::size_t... VGet, std::size_t... VExclude, std::size_t... OGet, std::size_t... OExclude>
219 friend Return internal::view_pack(const View &, const Other &, std::index_sequence<VGet...>, std::index_sequence<VExclude...>, std::index_sequence<OGet...>, std::index_sequence<OExclude...>);
220
221protected:
223 basic_common_view() noexcept = default;
224
225 basic_common_view(std::array<const Type *, Get> value, std::array<const Type *, Exclude> excl) noexcept
226 : pools{value},
227 filter{excl},
228 leading{},
229 index{Get} {
230 unchecked_refresh();
231 }
232
233 void use(const std::size_t pos) noexcept {
234 if(leading) {
235 index = pos;
236 leading = pools[index];
237 }
238 }
239
240 void unchecked_refresh() noexcept {
241 index = 0u;
242
243 for(size_type pos{1u}; pos < Get; ++pos) {
244 if(pools[pos]->size() < pools[index]->size()) {
245 index = pos;
246 }
247 }
248
249 leading = pools[index];
250 }
253public:
255 using common_type = Type;
257 using entity_type = typename Type::entity_type;
259 using size_type = std::size_t;
261 using iterator = internal::view_iterator<common_type, Get, Exclude>;
262
264 void refresh() noexcept {
265 size_type pos = (leading != nullptr) * Get;
266 for(; pos < Get && pools[pos] != nullptr; ++pos) {}
267
268 if(pos == Get) {
269 unchecked_refresh();
270 }
271 }
272
277 [[nodiscard]] const common_type *handle() const noexcept {
278 return leading;
279 }
280
285 [[nodiscard]] size_type size_hint() const noexcept {
286 return leading ? leading->size() : size_type{};
287 }
288
296 [[nodiscard]] iterator begin() const noexcept {
297 return leading ? iterator{leading->begin(0), leading->end(0), pools, filter, index} : iterator{};
298 }
299
304 [[nodiscard]] iterator end() const noexcept {
305 return leading ? iterator{leading->end(0), leading->end(0), pools, filter, index} : iterator{};
306 }
307
313 [[nodiscard]] entity_type front() const noexcept {
314 const auto it = begin();
315 return it != end() ? *it : null;
316 }
317
323 [[nodiscard]] entity_type back() const noexcept {
324 if(leading) {
325 auto it = leading->rbegin(0);
326 const auto last = leading->rend(0);
327 for(; it != last && !contains(*it); ++it) {}
328 return it == last ? null : *it;
329 }
330
331 return null;
332 }
333
340 [[nodiscard]] iterator find(const entity_type entt) const noexcept {
341 return contains(entt) ? iterator{leading->find(entt), leading->end(), pools, filter, index} : end();
342 }
343
348 [[nodiscard]] explicit operator bool() const noexcept {
349 return leading && internal::fully_initialized(filter.data(), Exclude);
350 }
351
357 [[nodiscard]] bool contains(const entity_type entt) const noexcept {
358 if(leading) {
359 const auto idx = leading->find(entt).index();
360 return (!(idx < 0 || idx > leading->begin(0).index())) && internal::all_of_but(index, pools.data(), Get, entt) && internal::none_of(filter.data(), Exclude, entt);
361 }
362
363 return false;
364 }
365
366protected:
368 std::array<const common_type *, Get> pools{};
369 std::array<const common_type *, Exclude> filter{};
370 const common_type *leading{};
371 size_type index{Get};
373};
374
387template<typename... Get, typename... Exclude>
388class basic_view<get_t<Get...>, exclude_t<Exclude...>>: public basic_common_view<std::common_type_t<typename Get::base_type..., typename Exclude::base_type...>, sizeof...(Get), sizeof...(Exclude)> {
389 using base_type = basic_common_view<std::common_type_t<typename Get::base_type..., typename Exclude::base_type...>, sizeof...(Get), sizeof...(Exclude)>;
390
391 template<typename Type>
392 static constexpr std::size_t index_of = type_list_index_v<std::remove_const_t<Type>, type_list<typename Get::value_type..., typename Exclude::value_type...>>;
393
394 template<std::size_t... Index>
395 auto storage(std::index_sequence<Index...>) const noexcept {
396 return std::make_tuple(storage<Index>()...);
397 }
398
399 template<std::size_t Curr, std::size_t Other, typename... Args>
400 [[nodiscard]] auto dispatch_get(const std::tuple<typename base_type::entity_type, Args...> &curr) const {
401 if constexpr(Curr == Other) {
402 return std::forward_as_tuple(std::get<Args>(curr)...);
403 } else {
404 return storage<Other>()->get_as_tuple(std::get<0>(curr));
405 }
406 }
407
408 template<std::size_t Curr, typename Func, std::size_t... Index>
409 void each(Func &func, std::index_sequence<Index...>) const {
410 for(const auto curr: storage<Curr>()->each()) {
411 if(const auto entt = std::get<0>(curr); ((sizeof...(Get) != 1u) || (entt != tombstone)) && internal::all_of_but(this->index, this->pools.data(), sizeof...(Get), entt) && internal::none_of(this->filter.data(), sizeof...(Exclude), entt)) {
412 if constexpr(is_applicable_v<Func, decltype(std::tuple_cat(std::tuple<entity_type>{}, std::declval<basic_view>().get({})))>) {
413 std::apply(func, std::tuple_cat(std::make_tuple(entt), dispatch_get<Curr, Index>(curr)...));
414 } else {
415 std::apply(func, std::tuple_cat(dispatch_get<Curr, Index>(curr)...));
416 }
417 }
418 }
419 }
420
421 template<typename Func, std::size_t... Index>
422 void pick_and_each(Func &func, std::index_sequence<Index...> seq) const {
423 ((storage<Index>() == base_type::handle() ? each<Index>(func, seq) : void()), ...);
424 }
425
426public:
436 using iterable = iterable_adaptor<internal::extended_view_iterator<iterator, Get...>>;
437
439 basic_view() noexcept
440 : base_type{} {}
441
447 basic_view(Get &...value, Exclude &...excl) noexcept
448 : base_type{{&value...}, {&excl...}} {
449 }
450
456 basic_view(std::tuple<Get &...> value, std::tuple<Exclude &...> excl = {}) noexcept
457 : basic_view{std::make_from_tuple<basic_view>(std::tuple_cat(value, excl))} {}
458
463 template<typename Type>
464 void use() noexcept {
465 use<index_of<Type>>();
466 }
467
472 template<std::size_t Index>
473 void use() noexcept {
474 base_type::use(Index);
475 }
476
482 template<typename Type>
483 [[nodiscard]] auto *storage() const noexcept {
484 return storage<index_of<Type>>();
485 }
486
492 template<std::size_t Index>
493 [[nodiscard]] auto *storage() const noexcept {
494 using type = type_list_element_t<Index, type_list<Get..., Exclude...>>;
495
496 if constexpr(Index < sizeof...(Get)) {
497 return static_cast<type *>(const_cast<constness_as_t<common_type, type> *>(this->pools[Index]));
498 } else {
499 return static_cast<type *>(const_cast<constness_as_t<common_type, type> *>(this->filter[Index - sizeof...(Get)]));
500 }
501 }
502
508 template<typename Type>
509 void storage(Type &elem) noexcept {
511 }
512
519 template<std::size_t Index, typename Type>
520 void storage(Type &elem) noexcept {
521 static_assert(std::is_convertible_v<Type &, type_list_element_t<Index, type_list<Get..., Exclude...>> &>, "Unexpected type");
522
523 if constexpr(Index < sizeof...(Get)) {
524 this->pools[Index] = &elem;
525 base_type::refresh();
526 } else {
527 this->filter[Index - sizeof...(Get)] = &elem;
528 }
529 }
530
536 [[nodiscard]] decltype(auto) operator[](const entity_type entt) const {
537 return get(entt);
538 }
539
547 template<typename Type, typename... Other>
548 [[nodiscard]] decltype(auto) get(const entity_type entt) const {
549 return get<index_of<Type>, index_of<Other>...>(entt);
550 }
551
558 template<std::size_t... Index>
559 [[nodiscard]] decltype(auto) get(const entity_type entt) const {
560 if constexpr(sizeof...(Index) == 0) {
561 return std::apply([entt](auto *...curr) { return std::tuple_cat(curr->get_as_tuple(entt)...); }, storage(std::index_sequence_for<Get...>{}));
562 } else if constexpr(sizeof...(Index) == 1) {
563 return (storage<Index>()->get(entt), ...);
564 } else {
565 return std::tuple_cat(storage<Index>()->get_as_tuple(entt)...);
566 }
567 }
568
584 template<typename Func>
585 void each(Func func) const {
586 if(base_type::handle() != nullptr) {
587 pick_and_each(func, std::index_sequence_for<Get...>{});
588 }
589 }
590
600 [[nodiscard]] iterable each() const noexcept {
601 const auto as_pools = storage(std::index_sequence_for<Get...>{});
602 return {internal::extended_view_iterator{base_type::begin(), as_pools}, internal::extended_view_iterator{base_type::end(), as_pools}};
603 }
604
612 template<typename... OGet, typename... OExclude>
613 [[nodiscard]] auto operator|(const basic_view<get_t<OGet...>, exclude_t<OExclude...>> &other) const noexcept {
614 return internal::view_pack<basic_view<get_t<Get..., OGet...>, exclude_t<Exclude..., OExclude...>>>(
615 *this, other, std::index_sequence_for<Get...>{}, std::index_sequence_for<Exclude...>{}, std::index_sequence_for<OGet...>{}, std::index_sequence_for<OExclude...>{});
616 }
617};
618
624template<typename Type>
626protected:
628 basic_storage_view() noexcept = default;
629
630 basic_storage_view(const Type *value) noexcept
631 : leading{value} {}
634public:
636 using common_type = Type;
638 using entity_type = typename common_type::entity_type;
640 using size_type = std::size_t;
642 using iterator = typename common_type::iterator;
644 using reverse_iterator = typename common_type::reverse_iterator;
645
650 [[nodiscard]] const common_type *handle() const noexcept {
651 return leading;
652 }
653
658 [[nodiscard]] size_type size() const noexcept {
659 return leading ? leading->size() : size_type{};
660 }
661
666 [[nodiscard]] bool empty() const noexcept {
667 return !leading || leading->empty();
668 }
669
677 [[nodiscard]] iterator begin() const noexcept {
678 return leading ? leading->begin() : iterator{};
679 }
680
685 [[nodiscard]] iterator end() const noexcept {
686 return leading ? leading->end() : iterator{};
687 }
688
696 [[nodiscard]] reverse_iterator rbegin() const noexcept {
697 return leading ? leading->rbegin() : reverse_iterator{};
698 }
699
706 [[nodiscard]] reverse_iterator rend() const noexcept {
707 return leading ? leading->rend() : reverse_iterator{};
708 }
709
715 [[nodiscard]] entity_type front() const noexcept {
716 return empty() ? null : *leading->begin();
717 }
718
724 [[nodiscard]] entity_type back() const noexcept {
725 return empty() ? null : *leading->rbegin();
726 }
727
734 [[nodiscard]] iterator find(const entity_type entt) const noexcept {
735 return leading ? leading->find(entt) : iterator{};
736 }
737
742 [[nodiscard]] explicit operator bool() const noexcept {
743 return (leading != nullptr);
744 }
745
751 [[nodiscard]] bool contains(const entity_type entt) const noexcept {
752 return leading && leading->contains(entt);
753 }
754
755protected:
757 const common_type *leading{};
759};
760
771template<typename Get>
772class basic_view<get_t<Get>, exclude_t<>, std::void_t<std::enable_if_t<!Get::traits_type::in_place_delete>>>: public basic_storage_view<typename Get::base_type> {
774
775public:
787 using iterable = decltype(std::declval<Get>().each());
788
790 basic_view() noexcept
791 : base_type{} {}
792
797 basic_view(Get &value) noexcept
798 : base_type{&value} {
799 }
800
805 basic_view(std::tuple<Get &> value, std::tuple<> = {}) noexcept
806 : basic_view{std::get<0>(value)} {}
807
813 template<typename Type = typename Get::value_type>
814 [[nodiscard]] auto *storage() const noexcept {
815 static_assert(std::is_same_v<std::remove_const_t<Type>, typename Get::value_type>, "Invalid component type");
816 return storage<0>();
817 }
818
824 template<std::size_t Index>
825 [[nodiscard]] auto *storage() const noexcept {
826 static_assert(Index == 0u, "Index out of bounds");
827 return static_cast<Get *>(const_cast<constness_as_t<common_type, Get> *>(this->leading));
828 }
829
834 void storage(Get &elem) noexcept {
835 storage<0>(elem);
836 }
837
843 template<std::size_t Index>
844 void storage(Get &elem) noexcept {
845 static_assert(Index == 0u, "Index out of bounds");
846 this->leading = &elem;
847 }
848
854 [[nodiscard]] decltype(auto) operator[](const entity_type entt) const {
855 return storage()->get(entt);
856 }
857
863 [[deprecated("use .begin()[pos] instead")]] [[nodiscard]] entity_type operator[](const size_type pos) const {
864 return base_type::begin()[pos];
865 }
866
873 template<typename Elem>
874 [[nodiscard]] decltype(auto) get(const entity_type entt) const {
875 static_assert(std::is_same_v<std::remove_const_t<Elem>, typename Get::value_type>, "Invalid component type");
876 return get<0>(entt);
877 }
878
885 template<std::size_t... Index>
886 [[nodiscard]] decltype(auto) get(const entity_type entt) const {
887 if constexpr(sizeof...(Index) == 0) {
888 return storage()->get_as_tuple(entt);
889 } else {
890 return storage<Index...>()->get(entt);
891 }
892 }
893
909 template<typename Func>
910 void each(Func func) const {
911 if(auto *elem = storage(); elem) {
912 if constexpr(is_applicable_v<Func, decltype(*elem->each().begin())>) {
913 for(const auto pack: elem->each()) {
914 std::apply(func, pack);
915 }
916 } else if constexpr(std::is_invocable_v<Func, decltype(*elem->begin())>) {
917 for(auto &&component: *elem) {
918 func(component);
919 }
920 } else {
921 for(size_type pos = elem->size(); pos; --pos) {
922 func();
923 }
924 }
925 }
926 }
927
937 [[nodiscard]] iterable each() const noexcept {
938 auto *elem = storage();
939 return elem ? elem->each() : iterable{};
940 }
941
949 template<typename... OGet, typename... OExclude>
950 [[nodiscard]] auto operator|(const basic_view<get_t<OGet...>, exclude_t<OExclude...>> &other) const noexcept {
951 return internal::view_pack<basic_view<get_t<Get, OGet...>, exclude_t<OExclude...>>>(
952 *this, other, std::index_sequence_for<Get>{}, std::index_sequence_for<>{}, std::index_sequence_for<OGet...>{}, std::index_sequence_for<OExclude...>{});
953 }
954};
955
961template<typename... Type>
963
969template<typename... Get, typename... Exclude>
970basic_view(std::tuple<Get &...>, std::tuple<Exclude &...> = {}) -> basic_view<get_t<Get...>, exclude_t<Exclude...>>;
971
972} // namespace entt
973
974#endif
Basic storage view implementation.
Definition view.hpp:217
size_type size_hint() const noexcept
Estimates the number of entities iterated by the view.
Definition view.hpp:285
void refresh() noexcept
Updates the internal leading view if required.
Definition view.hpp:264
Type common_type
Common type among all storage types.
Definition view.hpp:255
const common_type * handle() const noexcept
Returns the leading storage of a view, if any.
Definition view.hpp:277
bool contains(const entity_type entt) const noexcept
Checks if a view contains an entity.
Definition view.hpp:357
iterator begin() const noexcept
Returns an iterator to the first entity of the view.
Definition view.hpp:296
entity_type back() const noexcept
Returns the last entity of the view, if any.
Definition view.hpp:323
entity_type front() const noexcept
Returns the first entity of the view, if any.
Definition view.hpp:313
std::size_t size_type
Unsigned integer type.
Definition view.hpp:259
iterator end() const noexcept
Returns an iterator that is past the last entity of the view.
Definition view.hpp:304
iterator find(const entity_type entt) const noexcept
Finds an entity.
Definition view.hpp:340
internal::view_iterator< common_type, Get, Exclude > iterator
Bidirectional iterator type.
Definition view.hpp:261
typename Type::entity_type entity_type
Underlying entity identifier.
Definition view.hpp:257
Basic storage view implementation.
Definition view.hpp:625
reverse_iterator rbegin() const noexcept
Returns an iterator to the first entity of the reversed view.
Definition view.hpp:696
iterator begin() const noexcept
Returns an iterator to the first entity of the view.
Definition view.hpp:677
reverse_iterator rend() const noexcept
Returns an iterator that is past the last entity of the reversed view.
Definition view.hpp:706
typename common_type::entity_type entity_type
Underlying entity identifier.
Definition view.hpp:638
typename common_type::reverse_iterator reverse_iterator
Reversed iterator type.
Definition view.hpp:644
iterator find(const entity_type entt) const noexcept
Finds an entity.
Definition view.hpp:734
bool contains(const entity_type entt) const noexcept
Checks if a view contains an entity.
Definition view.hpp:751
entity_type back() const noexcept
Returns the last entity of the view, if any.
Definition view.hpp:724
std::size_t size_type
Unsigned integer type.
Definition view.hpp:640
iterator end() const noexcept
Returns an iterator that is past the last entity of the view.
Definition view.hpp:685
size_type size() const noexcept
Returns the number of entities that have the given component.
Definition view.hpp:658
const common_type * handle() const noexcept
Returns the leading storage of a view, if any.
Definition view.hpp:650
entity_type front() const noexcept
Returns the first entity of the view, if any.
Definition view.hpp:715
typename common_type::iterator iterator
Random access iterator type.
Definition view.hpp:642
Type common_type
Common type among all storage types.
Definition view.hpp:636
bool empty() const noexcept
Checks whether a view is empty.
Definition view.hpp:666
Basic storage implementation.
Definition storage.hpp:229
const value_type & get(const entity_type entt) const noexcept
Returns the object assigned to an entity.
Definition storage.hpp:627
iterable each() noexcept
Returns an iterable object to use to visit a storage.
Definition storage.hpp:741
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:641
iterable each() const noexcept
Returns an iterable object to use to visit a view.
Definition view.hpp:937
void each(Func func) const
Iterates entities and components and applies the given function object to them.
Definition view.hpp:910
auto operator|(const basic_view< get_t< OGet... >, exclude_t< OExclude... > > &other) const noexcept
Combines two views in a more specific one.
Definition view.hpp:950
decltype(auto) get(const entity_type entt) const
Returns the component assigned to the given entity.
Definition view.hpp:874
basic_view(std::tuple< Get & > value, std::tuple<>={}) noexcept
Constructs a view from a storage class.
Definition view.hpp:805
auto * storage() const noexcept
Returns the storage for a given component type, if any.
Definition view.hpp:814
entity_type operator[](const size_type pos) const
Returns the identifier that occupies the given position.
Definition view.hpp:863
decltype(auto) get(const entity_type entt) const
Returns the components assigned to the given entity.
Definition view.hpp:548
basic_view(Get &...value, Exclude &...excl) noexcept
Constructs a view from a set of storage classes.
Definition view.hpp:447
typename base_type::iterator iterator
Bidirectional iterator type.
Definition view.hpp:434
void use() noexcept
Forces a view to use a given component to drive iterations.
Definition view.hpp:464
void storage(Type &elem) noexcept
Assigns a storage to a view.
Definition view.hpp:520
typename base_type::size_type size_type
Unsigned integer type.
Definition view.hpp:432
auto * storage() const noexcept
Returns the storage for a given component type, if any.
Definition view.hpp:483
iterable each() const noexcept
Returns an iterable object to use to visit a view.
Definition view.hpp:600
void each(Func func) const
Iterates entities and components and applies the given function object to them.
Definition view.hpp:585
basic_view(std::tuple< Get &... > value, std::tuple< Exclude &... > excl={}) noexcept
Constructs a view from a set of storage classes.
Definition view.hpp:456
void storage(Type &elem) noexcept
Assigns a storage to a view.
Definition view.hpp:509
typename base_type::common_type common_type
Common type among all storage types.
Definition view.hpp:428
typename base_type::entity_type entity_type
Underlying entity identifier.
Definition view.hpp:430
auto operator|(const basic_view< get_t< OGet... >, exclude_t< OExclude... > > &other) const noexcept
Combines two views in a more specific one.
Definition view.hpp:613
basic_view() noexcept
Default constructor to use to create empty, invalid views.
Definition view.hpp:439
decltype(auto) get(const entity_type entt) const
Returns the components assigned to the given entity.
Definition view.hpp:559
View implementation.
Definition fwd.hpp:38
EnTT default namespace.
Definition dense_map.hpp:21
basic_view(Type &...storage) -> basic_view< get_t< Type... >, exclude_t<> >
Deduction guide.
constexpr null_t null
Compile-time constant for null entities.
Definition entity.hpp:363
basic_view< type_list_transform_t< Get, storage_for >, type_list_transform_t< Exclude, storage_for > > view
Alias declaration for the most common use case.
Definition fwd.hpp:253
constexpr bool is_applicable_v
Helper variable template.
basic_storage< Type > storage
Alias declaration for the most common use case.
Definition fwd.hpp:72
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
Definition entity.hpp:372
typename constness_as< To, From >::type constness_as_t
Alias template to facilitate the transcription of the constness.
constexpr get_t< Type... > get
Variable template for lists of observed components.
Definition fwd.hpp:157
typename type_list_element< Index, List >::type type_list_element_t
Helper type.
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
Alias for exclusion lists.
Definition fwd.hpp:130
Alias for lists of observed components.
Definition fwd.hpp:147
Utility class to create an iterable object from a pair of iterators.
Definition iterator.hpp:141
A class to use to push around lists of types, nothing more.