| 101 | )"; |
| 102 | |
| 103 | int main() |
| 104 | { |
| 105 | BehaviorTreeFactory factory; |
| 106 | |
| 107 | NoCopyObj non_copyable(88); |
| 108 | |
| 109 | // Passing the extra parameters to the constructor of Action_A |
| 110 | // note that if you want to pass an object by ref, instead of value |
| 111 | // (copy), you must use std::ref wrapper. |
| 112 | factory.registerNodeType<Action_A>("Action_A", 42, "hello world", |
| 113 | std::ref(non_copyable)); |
| 114 | |
| 115 | // Action_B will require initialization |
| 116 | factory.registerNodeType<Action_B>("Action_B"); |
| 117 | |
| 118 | auto tree = factory.createTreeFromText(xml_text); |
| 119 | |
| 120 | auto visitor = [](TreeNode* node) { |
| 121 | if(auto action_B_node = dynamic_cast<Action_B*>(node)) |
| 122 | { |
| 123 | action_B_node->initialize(69, "interesting_value"); |
| 124 | } |
| 125 | }; |
| 126 | // apply the visitor to all the nodes of the tree |
| 127 | tree.applyVisitor(visitor); |
| 128 | |
| 129 | tree.tickWhileRunning(); |
| 130 | |
| 131 | /* Expected output: |
| 132 | Action_A: 42 / hello world / 88 |
| 133 | Action_B: 69 / interesting_value |
| 134 | */ |
| 135 | return 0; |
| 136 | } |
nothing calls this directly
no test coverage detected