diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index bc323e65d..7c39eb998 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -471,21 +471,20 @@ public: /** * @brief Finds the storage associated with a given name, if any. * @param id Name used to map the storage within the registry. - * @return An iterator to the given storage if it's found, past the end - * iterator otherwise. + * @return A pointer to the storage if it exists, a null pointer otherwise. */ - [[nodiscard]] auto storage(const id_type id) { - return internal::registry_storage_iterator{pools.find(id)}; + [[nodiscard]] base_type *storage(const id_type id) { + return const_cast(std::as_const(*this).storage(id)); } /** * @brief Finds the storage associated with a given name, if any. * @param id Name used to map the storage within the registry. - * @return An iterator to the given storage if it's found, past the end - * iterator otherwise. + * @return A pointer to the storage if it exists, a null pointer otherwise. */ - [[nodiscard]] auto storage(const id_type id) const { - return internal::registry_storage_iterator{pools.find(id)}; + [[nodiscard]] const base_type *storage(const id_type id) const { + const auto it = pools.find(id); + return it == pools.cend() ? nullptr : it->second.get(); } /** diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index b476ecaa3..5df959140 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -1487,14 +1487,14 @@ TEST(Registry, SignalWhenDestroying) { registry.emplace(entity); registry.emplace(entity); - ASSERT_NE(registry.storage(entt::type_id().hash()), registry.storage().end()); - ASSERT_NE(registry.storage(entt::type_id().hash()), registry.storage().end()); - ASSERT_EQ(registry.storage(entt::type_id().hash()), registry.storage().end()); + ASSERT_NE(registry.storage(entt::type_id().hash()), nullptr); + ASSERT_NE(registry.storage(entt::type_id().hash()), nullptr); + ASSERT_EQ(registry.storage(entt::type_id().hash()), nullptr); ASSERT_TRUE(registry.valid(entity)); registry.destroy(entity); - ASSERT_NE(registry.storage(entt::type_id().hash()), registry.storage().end()); + ASSERT_NE(registry.storage(entt::type_id().hash()), nullptr); ASSERT_FALSE(registry.valid(entity)); } @@ -2019,11 +2019,11 @@ TEST(Registry, RuntimePools) { static_assert(std::is_same_v()), entt::storage_type_t &>); static_assert(std::is_same_v()), const entt::storage_type_t &>); - static_assert(std::is_same_vsecond), entt::storage_type_t::base_type &>); - static_assert(std::is_same_vsecond), const entt::storage_type_t::base_type &>); + static_assert(std::is_same_v::base_type *>); + static_assert(std::is_same_v::base_type *>); - ASSERT_NE(registry.storage("other"_hs), registry.storage().end()); - ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), registry.storage().end()); + ASSERT_NE(registry.storage("other"_hs), nullptr); + ASSERT_EQ(std::as_const(registry).storage("rehto"_hs), nullptr); ASSERT_EQ(®istry.storage("other"_hs), &storage); ASSERT_NE(&std::as_const(registry).storage(), &storage); diff --git a/test/example/entity_copy.cpp b/test/example/entity_copy.cpp index 69ad8ddc9..d4157b196 100644 --- a/test/example/entity_copy.cpp +++ b/test/example/entity_copy.cpp @@ -43,8 +43,8 @@ TEST(Example, EntityCopy) { TEST(Example, DifferentRegistryTypes) { using namespace entt::literals; - entt::basic_registry registry{}; - entt::basic_registry other{}; + entt::basic_registry src{}; + entt::basic_registry dst{}; /* TODO These are currently needed to ensure that the source and @@ -56,23 +56,23 @@ TEST(Example, DifferentRegistryTypes) { lines should be removed when a fix is properly landed. https://github.com/skypjack/entt/issues/827 */ - static_cast(registry.storage()); - static_cast(other.storage()); + static_cast(src.storage()); + static_cast(dst.storage()); - const auto src = registry.create(); - const auto dst = other.create(); + const auto entity = src.create(); + const auto copy = dst.create(); - registry.emplace(src, 42); - registry.emplace(src, 'c'); + src.emplace(entity, 42); + src.emplace(entity, 'c'); - for(auto [id, storage]: registry.storage()) { - if(auto it = other.storage(id); it != other.storage().end() && storage.contains(src)) { - it->second.emplace(dst, storage.get(src)); + for(auto [id, storage]: src.storage()) { + if(auto *other = dst.storage(id); other && storage.contains(entity)) { + other->emplace(copy, storage.get(entity)); } } - ASSERT_TRUE((registry.all_of(src))); - ASSERT_FALSE(other.all_of(dst)); - ASSERT_TRUE(other.all_of(dst)); - ASSERT_EQ(other.get(dst), 42); + ASSERT_TRUE((src.all_of(entity))); + ASSERT_FALSE(dst.all_of(copy)); + ASSERT_TRUE(dst.all_of(copy)); + ASSERT_EQ(dst.get(copy), 42); }