diff --git a/test/entt/entity/poly_storage.cpp b/test/entt/entity/poly_storage.cpp deleted file mode 100644 index 9afe7d389..000000000 --- a/test/entt/entity/poly_storage.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include -#include -#include - -template -entt::type_list as_type_list(const entt::type_list &); - -template -struct PolyStorage - : entt::type_list_cat_t< - decltype(as_type_list(std::declval>())), - entt::type_list< - void(const Entity *, const Entity *), - void(const Entity, const void *), - const void *(const Entity) const, - void(entt::basic_registry &) const>> { - using entity_type = Entity; - using size_type = std::size_t; - - template - struct type: entt::Storage::template type { - static constexpr auto base = decltype(as_type_list(std::declval>()))::size; - - void erase(const entity_type *first, const entity_type *last) { - entt::poly_call(*this, first, last); - } - - void emplace(const entity_type entity, const void *instance) { - entt::poly_call(*this, entity, instance); - } - - const void *get(const entity_type entity) const { - return entt::poly_call(*this, entity); - } - - void copy_to(entt::basic_registry &other) const { - entt::poly_call(*this, other); - } - }; - - template - struct members { - static void emplace(Type &self, const entity_type entity, const void *instance) { - self.emplace(entity, *static_cast(instance)); - } - - static const typename Type::value_type *get(const Type &self, const entity_type entity) { - return &self.get(entity); - } - - static void copy_to(const Type &self, entt::basic_registry &other) { - const entt::sparse_set &base = self; - other.template insert(base.rbegin(), base.rend(), self.rbegin()); - } - }; - - template - using impl = entt::value_list_cat_t< - typename entt::Storage::template impl, - entt::value_list< - &Type::template erase, - &members::emplace, - &members::get, - &members::copy_to>>; -}; - -template -struct entt::poly_storage_traits { - using storage_type = entt::poly>; -}; - -TEST(PolyStorage, CopyEntity) { - entt::registry registry; - const auto entity = registry.create(); - const auto other = registry.create(); - - registry.emplace(entity, 42); - registry.emplace(entity, 'c'); - - ASSERT_TRUE((registry.all_of(entity))); - ASSERT_FALSE((registry.any_of(other))); - - registry.visit(entity, [&](const auto &info) { - auto &&storage = registry.storage(info); - storage->emplace(other, storage->get(entity)); - }); - - ASSERT_TRUE((registry.all_of(entity))); - ASSERT_TRUE((registry.all_of(other))); - - ASSERT_EQ(registry.get(entity), registry.get(other)); - ASSERT_EQ(registry.get(entity), registry.get(other)); -} - -TEST(PolyStorage, CopyRegistry) { - entt::registry registry; - entt::registry other; - entt::entity entities[10u]; - - registry.create(std::begin(entities), std::end(entities)); - registry.insert(std::begin(entities), std::end(entities), 42); - registry.insert(std::begin(entities), std::end(entities), 'c'); - - ASSERT_EQ(registry.size(), 10u); - ASSERT_EQ(other.size(), 0u); - - other.assign(registry.data(), registry.data() + registry.size(), registry.released()); - registry.visit([&](const auto &info) { std::as_const(registry).storage(info)->copy_to(other); }); - - ASSERT_EQ(registry.size(), other.size()); - ASSERT_EQ((registry.view().size_hint()), (other.view().size_hint())); - ASSERT_NE((other.view().size_hint()), 0u); - - for(const auto entity: registry.view()) { - ASSERT_EQ((registry.get(entity)), (other.get(entity))); - } -} - -TEST(PolyStorage, Constness) { - entt::registry registry; - const auto &cregistry = registry; - - entt::entity entity[1]; - entity[0] = registry.create(); - registry.emplace(entity[0], 42); - - // cannot invoke erase on a const storage, let's copy the returned value - auto cstorage = cregistry.storage(entt::type_id()); - - ASSERT_DEATH(cstorage->erase(std::begin(entity), std::end(entity)), ""); - ASSERT_TRUE(registry.all_of(entity[0])); - - auto &&storage = registry.storage(entt::type_id()); - storage->erase(std::begin(entity), std::end(entity)); - - ASSERT_FALSE(registry.all_of(entity[0])); -}