1 #ifndef ENTT_ENTITY_RUNTIME_VIEW_HPP
2 #define ENTT_ENTITY_RUNTIME_VIEW_HPP
10 #include "../config/config.h"
12 #include "sparse_set.hpp"
57 template<
typename Entity>
62 class view_iterator final {
63 [[nodiscard]]
bool valid()
const {
64 const auto entt = *it;
67 && std::all_of(pools->begin()++, pools->end(), [
entt](
const auto *curr) { return curr->contains(entt); })
68 && std::none_of(filter->cbegin(), filter->cend(), [
entt](
const auto *curr) { return curr && curr->contains(entt); });
72 using difference_type =
typename underlying_iterator::difference_type;
73 using value_type =
typename underlying_iterator::value_type;
74 using pointer =
typename underlying_iterator::pointer;
75 using reference =
typename underlying_iterator::reference;
76 using iterator_category = std::bidirectional_iterator_tag;
78 view_iterator() ENTT_NOEXCEPT =
default;
80 view_iterator(
const std::vector<const basic_common_type *> &cpools,
const std::vector<const basic_common_type *> &ignore, underlying_iterator curr) ENTT_NOEXCEPT
84 stable_storage{std::any_of(pools->cbegin(), pools->cend(), [](
const basic_common_type *cpool) { return (cpool->policy() == deletion_policy::in_place); })}
86 if(it != (*pools)[0]->
end() && !valid()) {
91 view_iterator & operator++() {
92 while(++it != (*pools)[0]->
end() && !valid());
96 view_iterator operator++(
int) {
97 view_iterator orig = *
this;
98 return ++(*this), orig;
101 view_iterator & operator--() ENTT_NOEXCEPT {
102 while(--it != (*pools)[0]->
begin() && !valid());
106 view_iterator operator--(
int) ENTT_NOEXCEPT {
107 view_iterator orig = *
this;
108 return operator--(), orig;
111 [[nodiscard]]
bool operator==(
const view_iterator &other)
const ENTT_NOEXCEPT {
112 return other.it == it;
115 [[nodiscard]]
bool operator!=(
const view_iterator &other)
const ENTT_NOEXCEPT {
116 return !(*
this == other);
119 [[nodiscard]] pointer operator->()
const {
120 return it.operator->();
123 [[nodiscard]] reference operator*()
const {
124 return *operator->();
128 const std::vector<const basic_common_type *> *pools;
129 const std::vector<const basic_common_type *> *filter;
130 underlying_iterator it;
134 [[nodiscard]]
bool valid()
const {
135 return !pools.empty() && pools.front();
157 basic_runtime_view(std::vector<const basic_common_type *> cpools, std::vector<const basic_common_type *> epools) ENTT_NOEXCEPT
158 : pools{std::move(cpools)},
159 filter{std::move(epools)}
162 std::rotate(pools.begin(), std::min_element(pools.begin(), pools.end(), [](
const auto *lhs,
const auto *rhs) {
163 return (!lhs && rhs) || (lhs && rhs && lhs->size() < rhs->size());
172 return valid() ? pools.front()->size() :
size_type{};
210 return valid() && std::all_of(pools.cbegin(), pools.cend(), [
entt](
const auto *curr) { return curr->contains(entt); })
211 && std::none_of(filter.cbegin(), filter.cend(), [
entt](
const auto *curr) { return curr && curr->contains(entt); });
229 template<
typename Func>
231 for(
const auto entity: *
this) {
237 std::vector<const basic_common_type *> pools;
238 std::vector<const basic_common_type *> filter;
basic_runtime_view()
Default constructor to use to create empty, invalid views.
basic_runtime_view(std::vector< const basic_common_type * > cpools, std::vector< const basic_common_type * > epools)
Constructs a runtime view from a set of storage classes.
iterator end() const
Returns an iterator that is past the last entity that has the given components.
void each(Func func) const
Iterates entities and applies the given function object to them.
Entity entity_type
Underlying entity identifier.
view_iterator iterator
Bidirectional iterator type.
iterator begin() const
Returns an iterator to the first entity that has the given components.
std::size_t size_type
Unsigned integer type.
bool contains(const entity_type entt) const
Checks if a view contains an entity.
size_type size_hint() const
Estimates the number of entities iterated by the view.
Basic sparse set implementation.
sparse_set_iterator iterator
Random access iterator type.
entity
Default entity identifier.
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.
constexpr bool operator==(const Entity entity, const null_t other)
Compares a null object and an entity identifier of any type.