| 63 | } |
| 64 | |
| 65 | void 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 | |
| 100 | void buildSerializedStatusSnapshot(const TreeNode* root_node, |
| 101 | SerializedTreeStatus& serialized_buffer) |