소스 검색

resource: add ::reset functions (with tests)

Michele Caini 1 년 전
부모
커밋
aa178dd2cf
2개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 13 0
      src/entt/resource/resource.hpp
  2. 12 0
      test/entt/resource/resource.cpp

+ 13 - 0
src/entt/resource/resource.hpp

@@ -148,6 +148,19 @@ public:
         return static_cast<bool>(value);
     }
 
+    /*! @brief Releases the ownership of the managed resource. */
+    void reset() {
+        value.reset();
+    }
+
+    /**
+     * @brief Replaces the managed resource.
+     * @param other A handle to a resource.
+     */
+    void reset(handle_type other) {
+        value = std::move(other);
+    }
+
     /**
      * @brief Returns the underlying resource handle.
      * @return The underlying resource handle.

+ 12 - 0
test/entt/resource/resource.cpp

@@ -56,6 +56,18 @@ TEST(Resource, Functionalities) {
     ASSERT_TRUE(copy);
     ASSERT_TRUE(move);
     ASSERT_EQ(copy, move);
+
+    copy.reset(std::make_shared<derived>());
+
+    ASSERT_TRUE(copy);
+    ASSERT_TRUE(move);
+    ASSERT_NE(copy, move);
+
+    move.reset();
+
+    ASSERT_TRUE(copy);
+    ASSERT_FALSE(move);
+    ASSERT_NE(copy, move);
 }
 
 TEST(Resource, DerivedToBase) {