1#ifndef ENTT_ENTITY_RUNTIME_VIEW_HPP
2#define ENTT_ENTITY_RUNTIME_VIEW_HPP
18class runtime_view_iterator final {
19 using iterator_type =
typename Set::iterator;
20 using iterator_traits = std::iterator_traits<iterator_type>;
22 [[nodiscard]]
bool valid()
const {
23 return (!tombstone_check || *it != tombstone)
24 && std::all_of(++pools->begin(), pools->end(), [
entt = *it](
const auto *curr) { return curr->contains(entt); })
25 && std::none_of(filter->cbegin(), filter->cend(), [
entt = *it](
const auto *curr) { return curr && curr->contains(entt); });
29 using value_type =
typename iterator_traits::value_type;
30 using pointer =
typename iterator_traits::pointer;
31 using reference =
typename iterator_traits::reference;
32 using difference_type =
typename iterator_traits::difference_type;
33 using iterator_category = std::bidirectional_iterator_tag;
35 constexpr runtime_view_iterator() noexcept
42 runtime_view_iterator(
const std::vector<Set *> &cpools,
const std::vector<Set *> &ignore, iterator_type curr) noexcept
46 tombstone_check{pools->size() == 1u && (*pools)[0u]->policy() == deletion_policy::in_place} {
47 if(it != (*pools)[0]->end() && !valid()) {
52 runtime_view_iterator &operator++() {
54 for(
const auto last = (*pools)[0]->end(); it != last && !valid(); ++it) {}
58 runtime_view_iterator operator++(
int) {
59 runtime_view_iterator orig = *
this;
60 return ++(*this), orig;
63 runtime_view_iterator &operator--() {
65 for(
const auto first = (*pools)[0]->begin(); it != first && !valid(); --it) {}
69 runtime_view_iterator operator--(
int) {
70 runtime_view_iterator orig = *
this;
71 return operator--(), orig;
74 [[nodiscard]] pointer operator->() const noexcept {
75 return it.operator->();
78 [[nodiscard]] reference operator*() const noexcept {
82 [[nodiscard]]
constexpr bool operator==(
const runtime_view_iterator &other)
const noexcept {
83 return it == other.it;
86 [[nodiscard]]
constexpr bool operator!=(
const runtime_view_iterator &other)
const noexcept {
87 return !(*
this == other);
91 const std::vector<Set *> *pools;
92 const std::vector<Set *> *filter;
123template<
typename Type,
typename Allocator>
125 using alloc_traits = std::allocator_traits<Allocator>;
126 static_assert(std::is_same_v<typename alloc_traits::value_type, Type *>,
"Invalid value type");
127 using container_type = std::vector<Type *, Allocator>;
139 using iterator = internal::runtime_view_iterator<common_type>;
207 return pools.get_allocator();
222 if(pools.empty() || !(base.size() < pools[0
u]->size())) {
223 pools.push_back(&base);
225 pools.push_back(std::exchange(pools[0
u], &base));
237 filter.push_back(&base);
246 return pools.empty() ?
size_type{} : pools.front()->size();
258 return pools.empty() ?
iterator{} :
iterator{pools, filter, pools[0]->begin()};
268 return pools.empty() ?
iterator{} :
iterator{pools, filter, pools[0]->end()};
276 return !(pools.empty() && filter.empty());
285 return !pools.empty()
286 && std::all_of(pools.cbegin(), pools.cend(), [
entt](
const auto *
curr) { return curr->contains(entt); })
287 && std::none_of(filter.cbegin(), filter.cend(), [
entt](
const auto *
curr) { return curr && curr->contains(entt); });
304 template<
typename Func>
306 for(
const auto entity: *
this) {
312 container_type pools;
313 container_type filter;
basic_runtime_view(const basic_runtime_view &)=default
Default copy constructor.
iterator begin() const
Returns an iterator to the first entity that has the given elements.
basic_runtime_view() noexcept
Default constructor to use to create empty, invalid views.
basic_runtime_view(const allocator_type &allocator)
Constructs an empty, invalid view with a given allocator.
internal::runtime_view_iterator< common_type > iterator
Bidirectional iterator type.
basic_runtime_view & operator=(const basic_runtime_view &)=default
Default copy assignment operator.
constexpr allocator_type get_allocator() const noexcept
Returns the associated allocator.
~basic_runtime_view()=default
Default destructor.
bool contains(const entity_type entt) const
Checks if a view contains an entity.
void each(Func func) const
Iterates entities and applies the given function object to them.
basic_runtime_view & exclude(common_type &base)
Adds an opaque storage object as a filter of a runtime view.
Allocator allocator_type
Allocator type.
void clear()
Clears the view.
typename Type::entity_type entity_type
Underlying entity identifier.
iterator end() const
Returns an iterator that is past the last entity that has the given elements.
basic_runtime_view & operator=(basic_runtime_view &&) noexcept=default
Default move assignment operator.
size_type size_hint() const
Estimates the number of entities iterated by the view.
Type common_type
Common type among all storage types.
basic_runtime_view(const basic_runtime_view &other, const allocator_type &allocator)
Allocator-extended copy constructor.
void swap(basic_runtime_view &other) noexcept
Exchanges the contents with those of a given view.
basic_runtime_view & iterate(common_type &base)
Appends an opaque storage object to a runtime view.
std::size_t size_type
Unsigned integer type.
basic_runtime_view(basic_runtime_view &&) noexcept=default
Default move constructor.
entity
Default entity identifier.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
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.