From e6cac7d5fbd85df6268fda958ba3f933ea55fa22 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 20 Jul 2021 14:20:30 +0200 Subject: [PATCH] group/view: remove references to basic_sparse_set --- src/entt/entity/group.hpp | 8 ++--- src/entt/entity/storage.hpp | 72 +++++++++++++++++++------------------ src/entt/entity/view.hpp | 30 ++++++++-------- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index fae351c9d..a97d7eea4 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -68,11 +68,11 @@ class basic_group, get_t> final { /*! @brief A registry is allowed to create groups. */ friend class basic_registry; - using basic_common_type = basic_sparse_set; - template using storage_type = constness_as_t>::storage_type, Component>; + using basic_common_type = std::common_type_t::base_type...>; + class iterable final { template struct iterable_iterator final { @@ -533,11 +533,11 @@ class basic_group, get_t, Owned...> final /*! @brief A registry is allowed to create groups. */ friend class basic_registry; - using basic_common_type = basic_sparse_set; - template using storage_type = constness_as_t>::storage_type, Component>; + using basic_common_type = std::common_type_t::base_type..., typename storage_type::base_type...>; + class iterable final { template struct iterable_iterator; diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 7ed6d278b..23c47ba30 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -65,7 +65,6 @@ class basic_storage: public basic_sparse_set::const_pointer; using alloc_ptr_pointer = typename alloc_ptr_traits::pointer; - using underlying_type = basic_sparse_set>; using difference_type = typename entt_traits::difference_type; using comp_traits = component_traits; @@ -181,7 +180,7 @@ class basic_storage: public basic_sparse_set>; /*! @brief Allocator type. */ using allocator_type = Allocator; /*! @brief Type of the objects assigned to entities. */ @@ -350,7 +351,7 @@ public: * @param allocator the allocator to use. */ explicit basic_storage(const allocator_type &allocator) - : underlying_type{deletion_policy{comp_traits::in_place_delete::value}, allocator}, + : base_type{deletion_policy{comp_traits::in_place_delete::value}, allocator}, bucket{allocator, size_type{}}, packed{} {} @@ -360,7 +361,7 @@ public: * @param other The instance to move from. */ basic_storage(basic_storage &&other) ENTT_NOEXCEPT - : underlying_type{std::move(other)}, + : base_type{std::move(other)}, bucket{std::move(other.bucket)}, packed{std::exchange(other.packed, alloc_ptr_pointer{})} {} @@ -378,7 +379,7 @@ public: basic_storage & operator=(basic_storage &&other) ENTT_NOEXCEPT { release_memory(); - underlying_type::operator=(std::move(other)); + base_type::operator=(std::move(other)); bucket = std::move(other.bucket); packed = std::exchange(other.packed, alloc_ptr_pointer{}); @@ -403,9 +404,9 @@ public: * @param cap Desired capacity. */ void reserve(const size_type cap) override { - underlying_type::reserve(cap); + base_type::reserve(cap); - if(cap > underlying_type::size()) { + if(cap > base_type::size()) { assure_at_least(cap - 1u); } } @@ -421,7 +422,7 @@ public: /*! @brief Requests the removal of unused capacity. */ void shrink_to_fit() override { - underlying_type::shrink_to_fit(); + base_type::shrink_to_fit(); release_unused_pages(); } @@ -447,7 +448,7 @@ public: * @return An iterator to the first instance of the internal array. */ [[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT { - const difference_type pos = underlying_type::size(); + const difference_type pos = base_type::size(); return const_iterator{std::addressof(packed), pos}; } @@ -458,7 +459,7 @@ public: /*! @copydoc begin */ [[nodiscard]] iterator begin() ENTT_NOEXCEPT { - const difference_type pos = underlying_type::size(); + const difference_type pos = base_type::size(); return iterator{std::addressof(packed), pos}; } @@ -544,7 +545,7 @@ public: * @return The object assigned to the entity. */ [[nodiscard]] const value_type & get(const entity_type entt) const ENTT_NOEXCEPT { - const auto idx = underlying_type::index(entt); + const auto idx = base_type::index(entt); return packed[page(idx)][offset(idx)]; } @@ -588,13 +589,13 @@ public: */ template value_type & emplace(const entity_type entt, Args &&... args) { - const auto pos = underlying_type::slot(); + const auto pos = base_type::slot(); assure_at_least(pos); auto &value = push_at(pos, std::forward(args)...); ENTT_TRY { - [[maybe_unused]] const auto curr = underlying_type::emplace(entt); + [[maybe_unused]] const auto curr = base_type::emplace(entt); ENTT_ASSERT(pos == curr, "Misplaced component"); } ENTT_CATCH { pop_at(pos); @@ -613,7 +614,7 @@ public: */ template value_type & patch(const entity_type entt, Func &&... func) { - const auto idx = underlying_type::index(entt); + const auto idx = base_type::index(entt); auto &&elem = packed[page(idx)][offset(idx)]; (std::forward(func)(elem), ...); return elem; @@ -634,15 +635,15 @@ public: */ template void insert(It first, It last, const value_type &value = {}) { - reserve(underlying_type::size() + std::distance(first, last)); + reserve(base_type::size() + std::distance(first, last)); for(; first != last; ++first) { - push_at(underlying_type::size(), value); + push_at(base_type::size(), value); ENTT_TRY { - underlying_type::emplace_back(*first); + base_type::emplace_back(*first); } ENTT_CATCH { - pop_at(underlying_type::size()); + pop_at(base_type::size()); ENTT_THROW; } } @@ -662,15 +663,15 @@ public: */ template::value_type>, value_type>>> void insert(EIt first, EIt last, CIt from) { - reserve(underlying_type::size() + std::distance(first, last)); + reserve(base_type::size() + std::distance(first, last)); for(; first != last; ++first, ++from) { - push_at(underlying_type::size(), *from); + push_at(base_type::size(), *from); ENTT_TRY { - underlying_type::emplace_back(*first); + base_type::emplace_back(*first); } ENTT_CATCH { - pop_at(underlying_type::size()); + pop_at(base_type::size()); ENTT_THROW; } } @@ -688,10 +689,11 @@ class basic_storage::template rebind_alloc> { using allocator_traits = std::allocator_traits; - using underlying_type = basic_sparse_set>; using comp_traits = component_traits; public: + /*! @brief Base type. */ + using base_type = basic_sparse_set>; /*! @brief Allocator type. */ using allocator_type = Allocator; /*! @brief Type of the objects assigned to entities. */ @@ -706,7 +708,7 @@ public: * @param allocator Allocator to use (possibly default-constructed). */ explicit basic_storage(const allocator_type &allocator = {}) - : underlying_type{deletion_policy{comp_traits::in_place_delete::value}, allocator} + : base_type{deletion_policy{comp_traits::in_place_delete::value}, allocator} {} /** @@ -714,7 +716,7 @@ public: * @return The associated allocator. */ [[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT { - return allocator_type{underlying_type::get_allocator()}; + return allocator_type{base_type::get_allocator()}; } /** @@ -728,7 +730,7 @@ public: * @return Returns an empty tuple. */ [[nodiscard]] std::tuple<> get_as_tuple([[maybe_unused]] const entity_type entt) const ENTT_NOEXCEPT { - ENTT_ASSERT(underlying_type::contains(entt), "Storage does not contain entity"); + ENTT_ASSERT(base_type::contains(entt), "Storage does not contain entity"); return std::tuple{}; } @@ -746,7 +748,7 @@ public: template void emplace(const entity_type entt, Args &&... args) { [[maybe_unused]] value_type elem{std::forward(args)...}; - underlying_type::emplace(entt); + base_type::emplace(entt); } /** @@ -757,7 +759,7 @@ public: */ template void patch([[maybe_unused]] const entity_type entt, Func &&... func) { - ENTT_ASSERT(underlying_type::contains(entt), "Storage does not contain entity"); + ENTT_ASSERT(base_type::contains(entt), "Storage does not contain entity"); (std::forward(func)(), ...); } @@ -774,7 +776,7 @@ public: */ template void insert(It first, It last, const value_type & = {}) { - underlying_type::insert(first, last); + base_type::insert(first, last); } }; diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 3c4c37104..3de091222 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -32,8 +32,8 @@ namespace internal { template class iterable_storage final { - using basic_common_type = basic_sparse_set; using storage_type = constness_as_t>::storage_type, Component>; + using basic_common_type = typename storage_type::base_type; template struct iterable_storage_iterator final { @@ -110,10 +110,8 @@ private: }; -template +template class view_iterator final { - using basic_common_type = basic_sparse_set::value_type>; - [[nodiscard]] bool valid() const { const auto entt = *it; return Policy::accept(entt) @@ -137,7 +135,7 @@ public: filter{} {} - view_iterator(It from, It to, It curr, std::array all_of, std::array none_of) ENTT_NOEXCEPT + view_iterator(It from, It to, It curr, std::array all_of, std::array none_of) ENTT_NOEXCEPT : first{from}, last{to}, it{curr}, @@ -189,8 +187,8 @@ private: It first; It last; It it; - std::array pools; - std::array filter; + std::array pools; + std::array filter; }; @@ -275,11 +273,11 @@ struct basic_view; */ template class basic_view_impl, Component...> { - using basic_common_type = basic_sparse_set; - template using storage_type = constness_as_t>::storage_type, Comp>; + using basic_common_type = std::common_type_t::base_type...>; + class iterable final { template struct iterable_iterator final { @@ -321,8 +319,8 @@ class basic_view_impl, Component...> { }; public: - using iterator = iterable_iterator>; - using reverse_iterator = iterable_iterator>; + using iterator = iterable_iterator>; + using reverse_iterator = iterable_iterator>; iterable(const basic_view_impl &parent) : view{parent} @@ -391,9 +389,9 @@ public: /*! @brief Unsigned integer type. */ using size_type = std::size_t; /*! @brief Bidirectional iterator type. */ - using iterator = internal::view_iterator; + using iterator = internal::view_iterator; /*! @brief Reverse iterator type. */ - using reverse_iterator = internal::view_iterator; + using reverse_iterator = internal::view_iterator; /*! @brief Iterable view type. */ using iterable_view = iterable; @@ -695,8 +693,8 @@ private: */ template class basic_view_impl, Component> { - using basic_common_type = basic_sparse_set; using storage_type = constness_as_t>::storage_type, Component>; + using basic_common_type = typename storage_type::base_type; public: /*! @brief Underlying entity identifier. */ @@ -923,7 +921,7 @@ public: void each(Func func) const { if constexpr(ignore_as_empty_v>) { if constexpr(std::is_invocable_v) { - for(auto pos = size(); pos; --pos) { + for(size_type pos{}, last = size(); pos < last; ++pos) { func(); } } else { @@ -975,7 +973,7 @@ public: private: const std::tuple pools; - const std::array filter; + const std::tuple<> filter; };