19 const std::function<
void(
const TreeNode*)>& visitor)
23 throw LogicError(
"One of the children of a DecoratorNode or ControlNode is nulltr");
28 if (
auto control = dynamic_cast<const BT::ControlNode*>(node))
30 for (
const auto& child : control->children())
35 else if (
auto decorator = dynamic_cast<const BT::DecoratorNode*>(node))
45 throw LogicError(
"One of the children of a DecoratorNode or ControlNode is nulltr");
50 if (
auto control = dynamic_cast<BT::ControlNode*>(node))
52 for (
const auto& child : control->children())
57 else if (
auto decorator = dynamic_cast<BT::DecoratorNode*>(node))
65 std::function<void(unsigned, const BT::TreeNode*)> recursivePrint;
67 recursivePrint = [&recursivePrint](
unsigned indent,
const BT::TreeNode* node) {
68 for (
unsigned i = 0; i < indent; i++)
74 std::cout <<
"!nullptr!" << std::endl;
77 std::cout << node->
name() << std::endl;
80 if (
auto control = dynamic_cast<const BT::ControlNode*>(node))
82 for (
const auto& child : control->children())
84 recursivePrint(indent, child);
87 else if (
auto decorator = dynamic_cast<const BT::DecoratorNode*>(node))
89 recursivePrint(indent, decorator->child());
93 std::cout <<
"----------------" << std::endl;
94 recursivePrint(0, root_node);
95 std::cout <<
"----------------" << std::endl;
100 serialized_buffer.clear();
102 auto visitor = [&serialized_buffer](
const TreeNode* node) {
103 serialized_buffer.push_back(
104 std::make_pair(node->
UID(),
static_cast<uint8_t
>(node->
status())));
113 if (
auto action = dynamic_cast<AsyncActionNode*>(node))
115 action->stopAndJoinThread();
const std::string & name() const
Name of the instance, not the type.
void printTreeRecursively(const TreeNode *root_node)
std::vector< std::pair< uint16_t, uint8_t > > SerializedTreeStatus
void haltAllActions(TreeNode *root_node)
Abstract base class for Behavior Tree Nodes.
NodeStatus status() const
void buildSerializedStatusSnapshot(const TreeNode *root_node, SerializedTreeStatus &serialized_buffer)
buildSerializedStatusSnapshot can be used to create a buffer that can be stored (or sent to a client ...
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)