sparse_set: deprecate type() in favor of info() for consistency

This commit is contained in:
Michele Caini
2025-03-27 10:23:26 +01:00
parent d60efe04fd
commit e42231fab0
16 changed files with 76 additions and 72 deletions

1
TODO
View File

@@ -36,4 +36,3 @@ TODO:
* improve non-const allow cast with in-place switch
* meta fixed_size could return the size directly if present
* setup testbed workflow on the CI and review build process for testbed (i.e. tests first due to SDL)
* type() -> info() for consistency (sparse_set)

View File

@@ -1548,7 +1548,7 @@ is not known), there is always the possibility of receiving a `type_info` object
for the type of elements associated with the entities (if any):
```cpp
if(entt::type_id<velocity>() == base.type()) {
if(entt::type_id<velocity>() == base.info()) {
// ...
}
```

View File

@@ -151,7 +151,7 @@ public:
[[nodiscard]] bool owned(const id_type hash) const noexcept override {
for(size_type pos{}; pos < Owned; ++pos) {
if(pools[pos]->type().hash() == hash) {
if(pools[pos]->info().hash() == hash) {
return true;
}
}

View File

@@ -251,7 +251,7 @@ class basic_registry {
using storage_type = storage_for_type<Type>;
if(auto it = pools.find(id); it != pools.cend()) {
ENTT_ASSERT(it->second->type() == type_id<Type>(), "Unexpected type");
ENTT_ASSERT(it->second->info() == type_id<Type>(), "Unexpected type");
return static_cast<storage_type &>(*it->second);
}
@@ -281,7 +281,7 @@ class basic_registry {
return &entities;
} else {
if(const auto it = pools.find(id); it != pools.cend()) {
ENTT_ASSERT(it->second->type() == type_id<Type>(), "Unexpected type");
ENTT_ASSERT(it->second->info() == type_id<Type>(), "Unexpected type");
return static_cast<const storage_for_type<Type> *>(it->second.get());
}

View File

@@ -433,7 +433,7 @@ public:
explicit basic_sparse_set(const type_info &elem, deletion_policy pol = deletion_policy::swap_and_pop, const allocator_type &allocator = {})
: sparse{allocator},
packed{allocator},
info{&elem},
descriptor{&elem},
mode{pol},
head{policy_to_head()} {
ENTT_ASSERT(traits_type::version_mask || mode != deletion_policy::in_place, "Policy does not support zero-sized versions");
@@ -449,7 +449,7 @@ public:
basic_sparse_set(basic_sparse_set &&other) noexcept
: sparse{std::move(other.sparse)},
packed{std::move(other.packed)},
info{other.info},
descriptor{other.descriptor},
mode{other.mode},
head{std::exchange(other.head, policy_to_head())} {}
@@ -461,7 +461,7 @@ public:
basic_sparse_set(basic_sparse_set &&other, const allocator_type &allocator)
: sparse{std::move(other.sparse), allocator},
packed{std::move(other.packed), allocator},
info{other.info},
descriptor{other.descriptor},
mode{other.mode},
head{std::exchange(other.head, policy_to_head())} {
ENTT_ASSERT(alloc_traits::is_always_equal::value || get_allocator() == other.get_allocator(), "Copying a sparse set is not allowed");
@@ -497,7 +497,7 @@ public:
using std::swap;
swap(sparse, other.sparse);
swap(packed, other.packed);
swap(info, other.info);
swap(descriptor, other.descriptor);
swap(mode, other.mode);
swap(head, other.head);
}
@@ -1079,11 +1079,16 @@ public:
}
/**
* @brief Returned value type, if any.
* @return Returned value type, if any.
* @brief Returns a type info object for the value type, if any.
* @return A type info object for the value type, if any.
*/
[[nodiscard]] const type_info &type() const noexcept {
return *info;
[[nodiscard]] const type_info &info() const noexcept {
return *descriptor;
}
/*! @copydoc info */
[[deprecated("use ::info instead")]] const type_info &type() const noexcept {
return info();
}
/**
@@ -1099,7 +1104,7 @@ public:
private:
sparse_container_type sparse;
packed_container_type packed;
const type_info *info;
const type_info *descriptor;
deletion_policy mode;
size_type head;
};

View File

@@ -384,7 +384,7 @@ public:
return *this;
}
/*! @copydoc any::type */
/*! @copydoc any::info */
[[nodiscard]] inline meta_type type() const noexcept;
/**

View File

@@ -93,7 +93,7 @@ TYPED_TEST(BasicHandle, Storage) {
ASSERT_NE(handle.storage().begin(), handle.storage().end());
ASSERT_EQ(++handle.storage().begin(), handle.storage().end());
ASSERT_EQ(handle.storage().begin()->second.type(), entt::type_id<int>());
ASSERT_EQ(handle.storage().begin()->second.info(), entt::type_id<int>());
}
ENTT_DEBUG_TYPED_TEST(BasicHandleDeathTest, Storage) {

View File

@@ -56,13 +56,13 @@ TYPED_TEST(ReactiveMixin, Constructors) {
ASSERT_EQ(pool.policy(), entt::deletion_policy{traits_type::in_place_delete});
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
pool = entt::reactive_mixin<entt::storage<value_type>>{std::allocator<value_type>{}};
ASSERT_EQ(pool.policy(), entt::deletion_policy{traits_type::in_place_delete});
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
}
TYPED_TEST(ReactiveMixin, Move) {
@@ -80,7 +80,7 @@ TYPED_TEST(ReactiveMixin, Move) {
static_assert(std::is_move_assignable_v<decltype(pool)>, "Move assignable type required");
ASSERT_TRUE(pool.contains(entity[0u]));
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
entt::reactive_mixin<entt::storage<value_type>> other{std::move(pool)};
@@ -89,7 +89,7 @@ TYPED_TEST(ReactiveMixin, Move) {
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(other.index(entity[0u]), 0u);
ASSERT_EQ(&other.registry(), &registry);
@@ -149,8 +149,8 @@ TYPED_TEST(ReactiveMixin, Swap) {
pool.swap(other);
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.size(), 1u);
ASSERT_EQ(other.size(), 1u);

View File

@@ -466,9 +466,9 @@ TEST(Registry, RegistryStorageIteratorConversion) {
testing::StaticAssertTypeEq<decltype(*cit), std::pair<entt::id_type, const entt::sparse_set &>>();
ASSERT_EQ(it->first, entt::type_id<int>().hash());
ASSERT_EQ((*it).second.type(), entt::type_id<int>());
ASSERT_EQ((*it).second.info(), entt::type_id<int>());
ASSERT_EQ(it->first, cit->first);
ASSERT_EQ((*it).second.type(), (*cit).second.type());
ASSERT_EQ((*it).second.info(), (*cit).second.info());
ASSERT_EQ(it - cit, 0);
ASSERT_EQ(cit - it, 0);
@@ -1442,7 +1442,7 @@ TEST(Registry, EraseIf) {
ASSERT_FALSE(registry.storage<int>("other"_hs).contains(entity));
ASSERT_TRUE(registry.storage<char>().contains(entity));
registry.erase_if(entity, [](auto, const auto &storage) { return storage.type() == entt::type_id<char>(); });
registry.erase_if(entity, [](auto, const auto &storage) { return storage.info() == entt::type_id<char>(); });
ASSERT_TRUE(registry.storage<int>().contains(entity));
ASSERT_FALSE(registry.storage<int>("other"_hs).contains(entity));
@@ -2546,8 +2546,8 @@ TEST(Registry, VoidType) {
ASSERT_FALSE(registry.storage<void>("custom"_hs).empty());
ASSERT_TRUE(registry.storage<void>("custom"_hs).contains(entity));
ASSERT_EQ(registry.storage<void>().type(), entt::type_id<void>());
ASSERT_EQ(registry.storage<void>("custom"_hs).type(), entt::type_id<void>());
ASSERT_EQ(registry.storage<void>().info(), entt::type_id<void>());
ASSERT_EQ(registry.storage<void>("custom"_hs).info(), entt::type_id<void>());
}
TEST(Registry, NoEtoType) {

View File

@@ -231,7 +231,7 @@ TEST(SighMixin, VoidType) {
pool.emplace(entity);
ASSERT_EQ(pool.type(), entt::type_id<void>());
ASSERT_EQ(pool.info(), entt::type_id<void>());
ASSERT_TRUE(pool.contains(entity));
entt::sigh_mixin<entt::storage<void>> other{std::move(pool)};
@@ -336,7 +336,7 @@ TYPED_TEST(SighMixin, Move) {
static_assert(std::is_move_constructible_v<decltype(pool)>, "Move constructible type required");
static_assert(std::is_move_assignable_v<decltype(pool)>, "Move assignable type required");
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
entt::sigh_mixin<entt::storage<value_type>> other{std::move(pool)};
@@ -345,7 +345,7 @@ TYPED_TEST(SighMixin, Move) {
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(other.index(entt::entity{3}), 0u);
ASSERT_EQ(other.get(entt::entity{3}), value_type{3});
@@ -408,8 +408,8 @@ TYPED_TEST(SighMixin, Swap) {
pool.swap(other);
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.size(), 1u + traits_type::in_place_delete);
ASSERT_EQ(other.size(), 1u);

View File

@@ -58,7 +58,7 @@ TYPED_TEST(SparseSet, Constructors) {
ASSERT_EQ(set.policy(), entt::deletion_policy::swap_and_pop);
ASSERT_NO_THROW([[maybe_unused]] auto alloc = set.get_allocator());
ASSERT_EQ(set.type(), entt::type_id<void>());
ASSERT_EQ(set.info(), entt::type_id<void>());
set = sparse_set_type{allocator_type{}};
@@ -70,7 +70,7 @@ TYPED_TEST(SparseSet, Constructors) {
ASSERT_EQ(set.policy(), policy);
ASSERT_NO_THROW([[maybe_unused]] auto alloc = set.get_allocator());
ASSERT_EQ(set.type(), entt::type_id<void>());
ASSERT_EQ(set.info(), entt::type_id<void>());
set = sparse_set_type{entt::type_id<int>(), policy, allocator_type{}};

View File

@@ -96,13 +96,13 @@ TYPED_TEST(Storage, Constructors) {
ASSERT_EQ(pool.policy(), entt::deletion_policy{traits_type::in_place_delete});
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
pool = entt::storage<value_type>{std::allocator<value_type>{}};
ASSERT_EQ(pool.policy(), entt::deletion_policy{traits_type::in_place_delete});
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
}
TYPED_TEST(Storage, Move) {
@@ -123,7 +123,7 @@ TYPED_TEST(Storage, Move) {
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(other.index(entity[0u]), 0u);
ASSERT_EQ(other.get(entity[0u]), value_type{3});
@@ -134,7 +134,7 @@ TYPED_TEST(Storage, Move) {
ASSERT_TRUE(other.empty());
ASSERT_FALSE(extended.empty());
ASSERT_EQ(extended.type(), entt::type_id<value_type>());
ASSERT_EQ(extended.info(), entt::type_id<value_type>());
ASSERT_EQ(extended.index(entity[0u]), 0u);
ASSERT_EQ(extended.get(entity[0u]), value_type{3});
@@ -145,7 +145,7 @@ TYPED_TEST(Storage, Move) {
ASSERT_TRUE(other.empty());
ASSERT_TRUE(extended.empty());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.index(entity[0u]), 0u);
ASSERT_EQ(pool.get(entity[0u]), value_type{3});
@@ -157,7 +157,7 @@ TYPED_TEST(Storage, Move) {
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(other.index(entity[0u]), 0u);
ASSERT_EQ(other.get(entity[0u]), value_type{3});
}
@@ -169,8 +169,8 @@ TYPED_TEST(Storage, Swap) {
entt::storage<value_type> pool;
entt::storage<value_type> other;
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
pool.emplace(entt::entity{4}, 1);
@@ -183,8 +183,8 @@ TYPED_TEST(Storage, Swap) {
pool.swap(other);
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.size(), 1u + traits_type::in_place_delete);
ASSERT_EQ(other.size(), 1u);
@@ -721,8 +721,8 @@ TEST(Storage, TryEmplaceNonDefaultConstructible) {
entt::sparse_set &base = pool;
const std::array entity{entt::entity{1}, entt::entity{3}};
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.type(), base.type());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), base.info());
ASSERT_FALSE(pool.contains(entity[0u]));
ASSERT_FALSE(pool.contains(entity[1u]));
@@ -764,8 +764,8 @@ TEST(Storage, TryEmplaceNonCopyConstructible) {
entt::sparse_set &base = pool;
const std::array entity{entt::entity{1}, entt::entity{3}};
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.type(), base.type());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), base.info());
ASSERT_FALSE(pool.contains(entity[0u]));
ASSERT_FALSE(pool.contains(entity[1u]));

View File

@@ -19,13 +19,13 @@ TEST(StorageEntity, Constructors) {
ASSERT_EQ(pool.policy(), entt::deletion_policy::swap_only);
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<void>());
ASSERT_EQ(pool.info(), entt::type_id<void>());
pool = entt::storage<entt::entity>{std::allocator<entt::entity>{}};
ASSERT_EQ(pool.policy(), entt::deletion_policy::swap_only);
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<void>());
ASSERT_EQ(pool.info(), entt::type_id<void>());
}
TEST(StorageEntity, Move) {
@@ -44,7 +44,7 @@ TEST(StorageEntity, Move) {
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<void>());
ASSERT_EQ(other.info(), entt::type_id<void>());
ASSERT_EQ(other.index(entity[0u]), 0u);
entt::storage<entt::entity> extended{std::move(other), std::allocator<entt::entity>{}};
@@ -54,7 +54,7 @@ TEST(StorageEntity, Move) {
ASSERT_TRUE(other.empty());
ASSERT_FALSE(extended.empty());
ASSERT_EQ(extended.type(), entt::type_id<void>());
ASSERT_EQ(extended.info(), entt::type_id<void>());
ASSERT_EQ(extended.index(entity[0u]), 0u);
pool = std::move(extended);
@@ -64,7 +64,7 @@ TEST(StorageEntity, Move) {
ASSERT_TRUE(other.empty());
ASSERT_TRUE(extended.empty());
ASSERT_EQ(pool.type(), entt::type_id<void>());
ASSERT_EQ(pool.info(), entt::type_id<void>());
ASSERT_EQ(pool.index(entity[0u]), 0u);
other = entt::storage<entt::entity>{};
@@ -75,7 +75,7 @@ TEST(StorageEntity, Move) {
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<void>());
ASSERT_EQ(other.info(), entt::type_id<void>());
ASSERT_EQ(other.index(entity[0u]), 0u);
}
@@ -83,8 +83,8 @@ TEST(StorageEntity, Swap) {
entt::storage<entt::entity> pool;
entt::storage<entt::entity> other;
ASSERT_EQ(pool.type(), entt::type_id<void>());
ASSERT_EQ(other.type(), entt::type_id<void>());
ASSERT_EQ(pool.info(), entt::type_id<void>());
ASSERT_EQ(other.info(), entt::type_id<void>());
pool.generate(entt::entity{4});
@@ -97,8 +97,8 @@ TEST(StorageEntity, Swap) {
pool.swap(other);
ASSERT_EQ(pool.type(), entt::type_id<void>());
ASSERT_EQ(other.type(), entt::type_id<void>());
ASSERT_EQ(pool.info(), entt::type_id<void>());
ASSERT_EQ(other.info(), entt::type_id<void>());
ASSERT_EQ(pool.size(), 2u);
ASSERT_EQ(other.size(), 1u);

View File

@@ -64,13 +64,13 @@ TYPED_TEST(StorageNoInstance, Constructors) {
ASSERT_EQ(pool.policy(), entt::deletion_policy::swap_and_pop);
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
pool = entt::storage<value_type>{std::allocator<value_type>{}};
ASSERT_EQ(pool.policy(), entt::deletion_policy::swap_and_pop);
ASSERT_NO_THROW([[maybe_unused]] auto alloc = pool.get_allocator());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
}
TYPED_TEST(StorageNoInstance, Move) {
@@ -91,7 +91,7 @@ TYPED_TEST(StorageNoInstance, Move) {
ASSERT_TRUE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(other.index(entity[0u]), 0u);
entt::storage<value_type> extended{std::move(other), std::allocator<value_type>{}};
@@ -101,7 +101,7 @@ TYPED_TEST(StorageNoInstance, Move) {
ASSERT_TRUE(other.empty());
ASSERT_FALSE(extended.empty());
ASSERT_EQ(extended.type(), entt::type_id<value_type>());
ASSERT_EQ(extended.info(), entt::type_id<value_type>());
ASSERT_EQ(extended.index(entity[0u]), 0u);
pool = std::move(extended);
@@ -111,7 +111,7 @@ TYPED_TEST(StorageNoInstance, Move) {
ASSERT_TRUE(other.empty());
ASSERT_TRUE(extended.empty());
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.index(entity[0u]), 0u);
other = entt::storage<value_type>{};
@@ -122,7 +122,7 @@ TYPED_TEST(StorageNoInstance, Move) {
ASSERT_FALSE(pool.empty());
ASSERT_FALSE(other.empty());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(other.index(entity[0u]), 0u);
}
@@ -132,8 +132,8 @@ TYPED_TEST(StorageNoInstance, Swap) {
entt::storage<value_type> pool;
entt::storage<value_type> other;
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
pool.emplace(entt::entity{4});
@@ -146,8 +146,8 @@ TYPED_TEST(StorageNoInstance, Swap) {
pool.swap(other);
ASSERT_EQ(pool.type(), entt::type_id<value_type>());
ASSERT_EQ(other.type(), entt::type_id<value_type>());
ASSERT_EQ(pool.info(), entt::type_id<value_type>());
ASSERT_EQ(other.info(), entt::type_id<value_type>());
ASSERT_EQ(pool.size(), 1u);
ASSERT_EQ(other.size(), 1u);

View File

@@ -855,19 +855,19 @@ TEST(MultiStorageView, UseAndRefresh) {
view.use<int>();
ASSERT_EQ(view.handle()->type(), entt::type_id<int>());
ASSERT_EQ(view.handle()->info(), entt::type_id<int>());
ASSERT_EQ(view.front(), entity[1u]);
ASSERT_EQ(view.back(), entity[0u]);
view.use<char>();
ASSERT_EQ(view.handle()->type(), entt::type_id<char>());
ASSERT_EQ(view.handle()->info(), entt::type_id<char>());
ASSERT_EQ(view.front(), entity[0u]);
ASSERT_EQ(view.back(), entity[1u]);
view.refresh();
ASSERT_EQ(view.handle()->type(), entt::type_id<int>());
ASSERT_EQ(view.handle()->info(), entt::type_id<int>());
}
TEST(MultiStorageView, Each) {

View File

@@ -106,7 +106,7 @@ TYPED_TEST(EntityCopy, CrossRegistry) {
if(!other) {
using namespace entt::literals;
entt::resolve(storage.type()).invoke("storage"_hs, {}, entt::forward_as_meta(dst), id);
entt::resolve(storage.info()).invoke("storage"_hs, {}, entt::forward_as_meta(dst), id);
other = dst.storage(id);
}