File tree Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ int main(int argc, char** argv)
9797
9898 // this will be synchronous (async_delay is 0)
9999 BT::TestNodeConfig counting_config;
100- test_config .return_status = BT::NodeStatus::SUCCESS;
100+ counting_config .return_status = BT::NodeStatus::SUCCESS;
101101
102102 // ---------------------------------------------------------------
103103 // Next, we want to substitute one or more of out Nodes with this mocks
Original file line number Diff line number Diff line change @@ -55,11 +55,11 @@ struct TestNodeConfig
5555 * This particular node is created by the factory when TestNodeConfig is
5656 * added as a substitution rule:
5757 *
58- * TestNodeConfig test_config;
58+ * auto test_config = std::make_shared<TestNodeConfig>() ;
5959 * // change fields of test_config
6060 * factory.addSubstitutionRule(pattern, test_config);
6161 *
62- * See tutorial 11 for more details.
62+ * See tutorial 15 for more details.
6363 */
6464class TestNode : public BT ::StatefulActionNode
6565{
Original file line number Diff line number Diff line change @@ -469,7 +469,8 @@ class BehaviorTreeFactory
469469
470470 void clearSubstitutionRules ();
471471
472- using SubstitutionRule = std::variant<std::string, TestNodeConfig>;
472+ using SubstitutionRule =
473+ std::variant<std::string, TestNodeConfig, std::shared_ptr<TestNodeConfig>>;
473474
474475 /* *
475476 * @brief addSubstitutionRule replace a node with another one when the tree is
Original file line number Diff line number Diff line change @@ -263,13 +263,22 @@ std::unique_ptr<TreeNode> BehaviorTreeFactory::instantiateTreeNode(
263263 }
264264 else if (const auto test_config = std::get_if<TestNodeConfig>(&rule))
265265 {
266- // second case, the variant is a TestNodeConfig
267- auto test_node =
268- new TestNode (name, config, std::make_shared<TestNodeConfig>(*test_config));
269- node.reset (test_node);
266+ node = std::make_unique<TestNode>(name, config,
267+ std::make_shared<TestNodeConfig>(*test_config));
270268 substituted = true ;
271269 break ;
272270 }
271+ else if (const auto test_config =
272+ std::get_if<std::shared_ptr<TestNodeConfig>>(&rule))
273+ {
274+ node = std::make_unique<TestNode>(name, config, *test_config);
275+ substituted = true ;
276+ break ;
277+ }
278+ else
279+ {
280+ throw LogicError (" Substitution rule is not a string or a TestNodeConfig" );
281+ }
273282 }
274283 }
275284
You can’t perform that action at this time.
0 commit comments