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

Function printTreeRecursively

src/behavior_tree.cpp:65–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65void printTreeRecursively(const TreeNode* root_node, std::ostream& stream)
66{
67 std::function<void(unsigned, const BT::TreeNode*)> recursivePrint;
68
69 recursivePrint = [&recursivePrint, &stream](unsigned indent, const BT::TreeNode* node) {
70 for(unsigned i = 0; i < indent; i++)
71 {
72 stream << " ";
73 }
74 if(node == nullptr)
75 {
76 stream << "!nullptr!" << std::endl;
77 return;
78 }
79 stream << node->name() << std::endl;
80 indent++;
81
82 if(auto control = dynamic_cast<const BT::ControlNode*>(node))
83 {
84 for(const auto& child : control->children())
85 {
86 recursivePrint(indent, child);
87 }
88 }
89 else if(auto decorator = dynamic_cast<const BT::DecoratorNode*>(node))
90 {
91 recursivePrint(indent, decorator->child());
92 }
93 };
94
95 stream << "----------------" << std::endl;
96 recursivePrint(0, root_node);
97 stream << "----------------" << std::endl;
98}
99
100void buildSerializedStatusSnapshot(const TreeNode* root_node,
101 SerializedTreeStatus& serialized_buffer)

Callers 5

TESTFunction · 0.85
TEST_FFunction · 0.85
TESTFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 2

nameMethod · 0.45
childMethod · 0.45

Tested by 3

TESTFunction · 0.68
TEST_FFunction · 0.68
TESTFunction · 0.68