From f741fe48a11c269babecf7018c2a8ce4e4b6a8ce Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Fri, 10 Dec 2021 08:25:46 +0100 Subject: [PATCH] group: added ::handle to non-owning groups --- src/entt/entity/group.hpp | 8 ++++++++ test/entt/entity/group.cpp | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/entt/entity/group.hpp b/src/entt/entity/group.hpp index 5cac18a4c..737bd8e2f 100644 --- a/src/entt/entity/group.hpp +++ b/src/entt/entity/group.hpp @@ -167,6 +167,14 @@ public: basic_group() ENTT_NOEXCEPT : handler{} {} + /** + * @brief Returns a const reference to the underlying handler. + * @return A const reference to the underlying handler. + */ + const base_type &handle() const ENTT_NOEXCEPT { + return *handler; + } + /** * @brief Returns the storage for a given component type. * @tparam Comp Type of component of which to return the storage. diff --git a/test/entt/entity/group.cpp b/test/entt/entity/group.cpp index 96e35e65a..7bd970993 100644 --- a/test/entt/entity/group.cpp +++ b/test/entt/entity/group.cpp @@ -80,6 +80,25 @@ TEST(NonOwningGroup, Functionalities) { ASSERT_FALSE(invalid); } +TEST(NonOwningGroup, Handle) { + entt::registry registry; + const auto entity = registry.create(); + + auto group = registry.group(entt::get); + auto &&handle = group.handle(); + + ASSERT_TRUE(handle.empty()); + ASSERT_FALSE(handle.contains(entity)); + ASSERT_EQ(&handle, &group.handle()); + + registry.emplace(entity); + registry.emplace(entity); + + ASSERT_FALSE(handle.empty()); + ASSERT_TRUE(handle.contains(entity)); + ASSERT_EQ(&handle, &group.handle()); +} + TEST(NonOwningGroup, Invalid) { entt::registry registry{}; auto group = std::as_const(registry).group_if_exists(entt::get);