view/group/registry: storage_type -> storage_for (prepare for storage_type_t)

This commit is contained in:
Michele Caini
2022-05-15 10:45:33 +02:00
parent b59e06ec89
commit 0c8178c753
3 changed files with 39 additions and 39 deletions
+10 -10
View File
@@ -134,11 +134,11 @@ class basic_group<Entity, owned_t<>, get_t<Get...>, exclude_t<Exclude...>> {
static constexpr std::size_t index_of = type_list_index_v<std::remove_const_t<Comp>, type_list<std::remove_const_t<Get>...>>;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
using storage_for = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
using basic_common_type = std::common_type_t<typename storage_type<Get>::base_type...>;
using basic_common_type = std::common_type_t<typename storage_for<Get>::base_type...>;
basic_group(basic_common_type &ref, storage_type<Get> &...gpool) noexcept
basic_group(basic_common_type &ref, storage_for<Get> &...gpool) noexcept
: handler{&ref},
pools{&gpool...} {}
@@ -154,7 +154,7 @@ public:
/*! @brief Reversed iterator type. */
using reverse_iterator = typename base_type::reverse_iterator;
/*! @brief Iterable group type. */
using iterable = iterable_adaptor<internal::extended_group_iterator<iterator, owned_t<>, get_t<storage_type<Get>...>>>;
using iterable = iterable_adaptor<internal::extended_group_iterator<iterator, owned_t<>, get_t<storage_for<Get>...>>>;
/*! @brief Default constructor to use to create empty, invalid groups. */
basic_group() noexcept
@@ -489,7 +489,7 @@ public:
private:
base_type *const handler;
const std::tuple<storage_type<Get> *...> pools;
const std::tuple<storage_for<Get> *...> pools;
};
/**
@@ -534,9 +534,9 @@ class basic_group<Entity, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...
static constexpr std::size_t index_of = type_list_index_v<std::remove_const_t<Comp>, type_list<std::remove_const_t<Owned>..., std::remove_const_t<Get>...>>;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
using storage_for = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
basic_group(const std::size_t &extent, storage_type<Owned> &...opool, storage_type<Get> &...gpool) noexcept
basic_group(const std::size_t &extent, storage_for<Owned> &...opool, storage_for<Get> &...gpool) noexcept
: pools{&opool..., &gpool...},
length{&extent} {}
@@ -546,13 +546,13 @@ public:
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = std::common_type_t<typename storage_type<Owned>::base_type..., typename storage_type<Get>::base_type...>;
using base_type = std::common_type_t<typename storage_for<Owned>::base_type..., typename storage_for<Get>::base_type...>;
/*! @brief Random access iterator type. */
using iterator = typename base_type::iterator;
/*! @brief Reversed iterator type. */
using reverse_iterator = typename base_type::reverse_iterator;
/*! @brief Iterable group type. */
using iterable = iterable_adaptor<internal::extended_group_iterator<iterator, owned_t<storage_type<Owned>...>, get_t<storage_type<Get>...>>>;
using iterable = iterable_adaptor<internal::extended_group_iterator<iterator, owned_t<storage_for<Owned>...>, get_t<storage_for<Get>...>>>;
/*! @brief Default constructor to use to create empty, invalid groups. */
basic_group() noexcept
@@ -846,7 +846,7 @@ public:
}
private:
const std::tuple<storage_type<Owned> *..., storage_type<Get> *...> pools;
const std::tuple<storage_for<Owned> *..., storage_for<Get> *...> pools;
const size_type *const length;
};
+12 -12
View File
@@ -222,7 +222,7 @@ class basic_registry {
using basic_common_type = basic_sparse_set<Entity>;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
using storage_for = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
template<typename...>
struct group_handler;
@@ -237,7 +237,7 @@ class basic_registry {
void maybe_valid_if(basic_registry &owner, const Entity entt) {
[[maybe_unused]] const auto cpools = std::forward_as_tuple(owner.assure<Owned>()...);
const auto is_valid = ((std::is_same_v<Component, Owned> || std::get<storage_type<Owned> &>(cpools).contains(entt)) && ...)
const auto is_valid = ((std::is_same_v<Component, Owned> || std::get<storage_for<Owned> &>(cpools).contains(entt)) && ...)
&& ((std::is_same_v<Component, Get> || owner.assure<Get>().contains(entt)) && ...)
&& ((std::is_same_v<Component, Exclude> || !owner.assure<Exclude>().contains(entt)) && ...);
@@ -248,7 +248,7 @@ class basic_registry {
} else {
if(is_valid && !(std::get<0>(cpools).index(entt) < current)) {
const auto pos = current++;
(std::get<storage_type<Owned> &>(cpools).swap_elements(std::get<storage_type<Owned> &>(cpools).data()[pos], entt), ...);
(std::get<storage_for<Owned> &>(cpools).swap_elements(std::get<storage_for<Owned> &>(cpools).data()[pos], entt), ...);
}
}
}
@@ -259,7 +259,7 @@ class basic_registry {
} else {
if(const auto cpools = std::forward_as_tuple(owner.assure<Owned>()...); std::get<0>(cpools).contains(entt) && (std::get<0>(cpools).index(entt) < current)) {
const auto pos = --current;
(std::get<storage_type<Owned> &>(cpools).swap_elements(std::get<storage_type<Owned> &>(cpools).data()[pos], entt), ...);
(std::get<storage_for<Owned> &>(cpools).swap_elements(std::get<storage_for<Owned> &>(cpools).data()[pos], entt), ...);
}
}
}
@@ -279,12 +279,12 @@ class basic_registry {
auto &&cpool = pools[id];
if(!cpool) {
cpool.reset(new storage_type<Component>{});
cpool.reset(new storage_for<Component>{});
cpool->bind(forward_as_any(*this));
}
ENTT_ASSERT(cpool->type() == type_id<Component>(), "Unexpected type");
return static_cast<storage_type<Component> &>(*cpool);
return static_cast<storage_for<Component> &>(*cpool);
}
template<typename Component>
@@ -293,10 +293,10 @@ class basic_registry {
if(const auto it = pools.find(id); it != pools.cend()) {
ENTT_ASSERT(it->second->type() == type_id<Component>(), "Unexpected type");
return static_cast<const storage_type<Component> &>(*it->second);
return static_cast<const storage_for<Component> &>(*it->second);
}
static storage_type<Component> placeholder{};
static storage_for<Component> placeholder{};
return placeholder;
}
@@ -1227,9 +1227,9 @@ public:
template<typename Component, typename... Other, typename... Exclude>
[[nodiscard]] auto view(exclude_t<Exclude...> = {}) {
return basic_view{std::forward_as_tuple(
static_cast<storage_type<Component> &>(assure<std::remove_const_t<Component>>()),
static_cast<storage_type<Other> &>(assure<std::remove_const_t<Other>>())...),
std::forward_as_tuple(static_cast<storage_type<Exclude> &>(assure<std::remove_const_t<Exclude>>())...)};
static_cast<storage_for<Component> &>(assure<std::remove_const_t<Component>>()),
static_cast<storage_for<Other> &>(assure<std::remove_const_t<Other>>())...),
std::forward_as_tuple(static_cast<storage_for<Exclude> &>(assure<std::remove_const_t<Exclude>>())...)};
}
/**
@@ -1334,7 +1334,7 @@ public:
}
}
return {handler->current, std::get<storage_type<std::remove_const_t<Owned>> &>(cpools)..., std::get<storage_type<std::remove_const_t<Get>> &>(cpools)...};
return {handler->current, std::get<storage_for<std::remove_const_t<Owned>> &>(cpools)..., std::get<storage_for<std::remove_const_t<Get>> &>(cpools)...};
}
/*! @copydoc group */
+17 -17
View File
@@ -193,7 +193,7 @@ class basic_view<Entity, get_t<Component...>, exclude_t<Exclude...>> {
friend class basic_view;
template<typename Comp>
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
using storage_for = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Comp>>::type, Comp>;
[[nodiscard]] auto opaque_check() const noexcept {
std::array<const base_type *, sizeof...(Component) - 1u> other{};
@@ -242,11 +242,11 @@ public:
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = std::common_type_t<typename storage_type<Component>::base_type...>;
using base_type = std::common_type_t<typename storage_for<Component>::base_type...>;
/*! @brief Bidirectional iterator type. */
using iterator = internal::view_iterator<base_type, sizeof...(Component) - 1u, sizeof...(Exclude)>;
/*! @brief Iterable view type. */
using iterable = iterable_adaptor<internal::extended_view_iterator<iterator, storage_type<Component>...>>;
using iterable = iterable_adaptor<internal::extended_view_iterator<iterator, storage_for<Component>...>>;
/*! @brief Default constructor to use to create empty, invalid views. */
basic_view() noexcept
@@ -259,7 +259,7 @@ public:
* @param component The storage for the types to iterate.
* @param epool The storage for the types used to filter the view.
*/
basic_view(storage_type<Component> &...component, storage_type<Exclude> &...epool) noexcept
basic_view(storage_for<Component> &...component, storage_for<Exclude> &...epool) noexcept
: basic_view{std::forward_as_tuple(component...), std::forward_as_tuple(epool...)} {}
/**
@@ -267,7 +267,7 @@ public:
* @param component The storage for the types to iterate.
* @param epool The storage for the types used to filter the view.
*/
basic_view(std::tuple<storage_type<Component> &...> component, std::tuple<storage_type<Exclude> &...> epool = {}) noexcept
basic_view(std::tuple<storage_for<Component> &...> component, std::tuple<storage_for<Exclude> &...> epool = {}) noexcept
: pools{std::apply([](auto &...curr) { return std::make_tuple(&curr...); }, component)},
filter{std::apply([](auto &...curr) { return std::make_tuple(&curr...); }, epool)},
view{std::apply([](const auto &...curr) { return (std::min)({&static_cast<const base_type &>(curr)...}, [](auto *lhs, auto *rhs) { return lhs->size() < rhs->size(); }); }, component)} {}
@@ -280,7 +280,7 @@ public:
template<typename Comp>
[[nodiscard]] basic_view use() const noexcept {
basic_view other{*this};
other.view = std::get<storage_type<Comp> *>(pools);
other.view = std::get<storage_for<Comp> *>(pools);
return other;
}
@@ -311,7 +311,7 @@ public:
*/
template<typename Comp>
[[nodiscard]] decltype(auto) storage() const noexcept {
return *std::get<storage_type<Comp> *>(pools);
return *std::get<storage_for<Comp> *>(pools);
}
/**
@@ -433,9 +433,9 @@ public:
if constexpr(sizeof...(Comp) == 0) {
return std::apply([entt](auto *...curr) { return std::tuple_cat(curr->get_as_tuple(entt)...); }, pools);
} else if constexpr(sizeof...(Comp) == 1) {
return (std::get<storage_type<Comp> *>(pools)->get(entt), ...);
return (std::get<storage_for<Comp> *>(pools)->get(entt), ...);
} else {
return std::tuple_cat(std::get<storage_type<Comp> *>(pools)->get_as_tuple(entt)...);
return std::tuple_cat(std::get<storage_for<Comp> *>(pools)->get_as_tuple(entt)...);
}
}
@@ -512,8 +512,8 @@ public:
}
private:
std::tuple<storage_type<Component> *...> pools;
std::tuple<storage_type<Exclude> *...> filter;
std::tuple<storage_for<Component> *...> pools;
std::tuple<storage_for<Exclude> *...> filter;
const base_type *view;
};
@@ -544,7 +544,7 @@ class basic_view<Entity, get_t<Component>, exclude_t<>, std::void_t<std::enable_
template<typename, typename, typename, typename>
friend class basic_view;
using storage_type = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::type, Component>;
using storage_for = constness_as_t<typename storage_traits<Entity, std::remove_const_t<Component>>::type, Component>;
public:
/*! @brief Underlying entity identifier. */
@@ -552,13 +552,13 @@ public:
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Common type among all storage types. */
using base_type = typename storage_type::base_type;
using base_type = typename storage_for::base_type;
/*! @brief Random access iterator type. */
using iterator = typename base_type::iterator;
/*! @brief Reversed iterator type. */
using reverse_iterator = typename base_type::reverse_iterator;
/*! @brief Iterable view type. */
using iterable = decltype(std::declval<storage_type>().each());
using iterable = decltype(std::declval<storage_for>().each());
/*! @brief Default constructor to use to create empty, invalid views. */
basic_view() noexcept
@@ -570,14 +570,14 @@ public:
* @brief Constructs a single-type view from a storage class.
* @param ref The storage for the type to iterate.
*/
basic_view(storage_type &ref) noexcept
basic_view(storage_for &ref) noexcept
: basic_view{std::forward_as_tuple(ref)} {}
/**
* @brief Constructs a single-type view from a storage class.
* @param ref The storage for the type to iterate.
*/
basic_view(std::tuple<storage_type &> ref, std::tuple<> = {}) noexcept
basic_view(std::tuple<storage_for &> ref, std::tuple<> = {}) noexcept
: pools{&std::get<0>(ref)},
filter{},
view{&std::get<0>(ref)} {}
@@ -838,7 +838,7 @@ public:
}
private:
std::tuple<storage_type *> pools;
std::tuple<storage_for *> pools;
std::tuple<> filter;
const base_type *view;
};