19 const std::function<
void(
const TreeNode*)>& visitor)
23 throw std::runtime_error(
"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 std::runtime_error(
"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(int, 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())));
119 if (
auto action = dynamic_cast<AsyncActionNode*>(node))
121 action->stopAndJoinThread();
const std::string & name() const
void printTreeRecursively(const TreeNode *root_node)
std::shared_ptr< Blackboard > Ptr
std::vector< std::pair< uint16_t, uint8_t > > SerializedTreeStatus
void haltAllActions(TreeNode *root_node)
void assignBlackboardToEntireTree(TreeNode *root_node, const Blackboard::Ptr &bb)
NodeStatus status() const
void buildSerializedStatusSnapshot(const TreeNode *root_node, SerializedTreeStatus &serialized_buffer)
buildSerializedStatusSnapshot can be used to create a serialize buffer that can be stored (or sent to...
void setBlackboard(const Blackboard::Ptr &bb)
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)