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

This commit is contained in:
Michele Caini
2022-06-26 12:02:18 +02:00
parent bc85d96938
commit 281289c46a
2 changed files with 24 additions and 0 deletions

View File

@@ -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.

View File

@@ -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);