Przeglądaj źródła

group: added ::handle to non-owning groups

Michele Caini 4 lat temu
rodzic
commit
f741fe48a1
2 zmienionych plików z 27 dodań i 0 usunięć
  1. 8 0
      src/entt/entity/group.hpp
  2. 19 0
      test/entt/entity/group.cpp

+ 8 - 0
src/entt/entity/group.hpp

@@ -167,6 +167,14 @@ public:
     basic_group() ENTT_NOEXCEPT
     basic_group() ENTT_NOEXCEPT
         : handler{} {}
         : 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.
      * @brief Returns the storage for a given component type.
      * @tparam Comp Type of component of which to return the storage.
      * @tparam Comp Type of component of which to return the storage.

+ 19 - 0
test/entt/entity/group.cpp

@@ -80,6 +80,25 @@ TEST(NonOwningGroup, Functionalities) {
     ASSERT_FALSE(invalid);
     ASSERT_FALSE(invalid);
 }
 }
 
 
+TEST(NonOwningGroup, Handle) {
+    entt::registry registry;
+    const auto entity = registry.create();
+
+    auto group = registry.group(entt::get<int, char>);
+    auto &&handle = group.handle();
+
+    ASSERT_TRUE(handle.empty());
+    ASSERT_FALSE(handle.contains(entity));
+    ASSERT_EQ(&handle, &group.handle());
+
+    registry.emplace<int>(entity);
+    registry.emplace<char>(entity);
+
+    ASSERT_FALSE(handle.empty());
+    ASSERT_TRUE(handle.contains(entity));
+    ASSERT_EQ(&handle, &group.handle());
+}
+
 TEST(NonOwningGroup, Invalid) {
 TEST(NonOwningGroup, Invalid) {
     entt::registry registry{};
     entt::registry registry{};
     auto group = std::as_const(registry).group_if_exists(entt::get<const empty_type, const int>);
     auto group = std::as_const(registry).group_if_exists(entt::get<const empty_type, const int>);