浏览代码

flow: set-with-mode function to ease the transition of the observer class

Michele Caini 3 年之前
父节点
当前提交
281289c46a
共有 2 个文件被更改,包括 24 次插入0 次删除
  1. 11 0
      src/entt/graph/flow.hpp
  2. 13 0
      test/entt/graph/flow.cpp

+ 11 - 0
src/entt/graph/flow.hpp

@@ -175,6 +175,17 @@ public:
         return *this;
     }
 
+    /**
+     * @brief Assigns a resource to the current task with a given access mode.
+     * @param res Resource identifier.
+     * @param is_rw Access mode.
+     * @return This flow builder.
+     */
+    basic_flow &set(const id_type res, bool is_rw = false) {
+        emplace(res, is_rw);
+        return *this;
+    }
+
     /**
      * @brief Assigns a read-only resource to the current task.
      * @param res Resource identifier.

+ 13 - 0
test/entt/graph/flow.cpp

@@ -120,6 +120,19 @@ TEST(Flow, Clear) {
     ASSERT_EQ(flow.size(), 0u);
 }
 
+TEST(Flow, Set) {
+    entt::flow flow{};
+    flow.bind(0).set(10, true).bind(1).set(10, true).set(11, false);
+    auto graph = flow.graph();
+
+    ASSERT_EQ(flow.size(), 2u);
+    ASSERT_EQ(flow.size(), graph.size());
+    ASSERT_NE(graph.edges().cbegin(), graph.edges().cend());
+
+    ASSERT_TRUE(graph.contains(0u, 1u));
+    ASSERT_FALSE(graph.contains(1u, 0u));
+}
+
 TEST(Flow, RO) {
     entt::flow flow{};
     flow.bind(0).ro(10).bind(1).ro(10).ro(11);