File tree 4 files changed +18
-8
lines changed
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)
97
97
98
98
// this will be synchronous (async_delay is 0)
99
99
BT::TestNodeConfig counting_config;
100
- test_config .return_status = BT::NodeStatus::SUCCESS;
100
+ counting_config .return_status = BT::NodeStatus::SUCCESS;
101
101
102
102
// ---------------------------------------------------------------
103
103
// 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
55
55
* This particular node is created by the factory when TestNodeConfig is
56
56
* added as a substitution rule:
57
57
*
58
- * TestNodeConfig test_config;
58
+ * auto test_config = std::make_shared<TestNodeConfig>() ;
59
59
* // change fields of test_config
60
60
* factory.addSubstitutionRule(pattern, test_config);
61
61
*
62
- * See tutorial 11 for more details.
62
+ * See tutorial 15 for more details.
63
63
*/
64
64
class TestNode : public BT ::StatefulActionNode
65
65
{
Original file line number Diff line number Diff line change @@ -469,7 +469,8 @@ class BehaviorTreeFactory
469
469
470
470
void clearSubstitutionRules ();
471
471
472
- using SubstitutionRule = std::variant<std::string, TestNodeConfig>;
472
+ using SubstitutionRule =
473
+ std::variant<std::string, TestNodeConfig, std::shared_ptr<TestNodeConfig>>;
473
474
474
475
/* *
475
476
* @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(
263
263
}
264
264
else if (const auto test_config = std::get_if<TestNodeConfig>(&rule))
265
265
{
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));
270
268
substituted = true ;
271
269
break ;
272
270
}
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
+ }
273
282
}
274
283
}
275
284
You can’t perform that action at this time.
0 commit comments