MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / main

Function main

examples/t08_additional_node_args.cpp:103–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101 )";
102
103int 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}

Callers

nothing calls this directly

Calls 4

createTreeFromTextMethod · 0.80
applyVisitorMethod · 0.80
tickWhileRunningMethod · 0.80
initializeMethod · 0.45

Tested by

no test coverage detected