00001 #ifndef DECORATORNODE_H 00002 #define DECORATORNODE_H 00003 00004 #include "behaviortree_cpp/tree_node.h" 00005 00006 namespace BT 00007 { 00008 class DecoratorNode : public TreeNode 00009 { 00010 protected: 00011 TreeNode* child_node_; 00012 00013 public: 00014 00015 DecoratorNode(const std::string& name, const NodeConfiguration& config); 00016 00017 virtual ~DecoratorNode() override = default; 00018 00019 void setChild(TreeNode* child); 00020 00021 const TreeNode* child() const; 00022 00023 TreeNode* child(); 00024 00026 virtual void halt() override; 00027 00029 void haltChild(); 00030 00031 virtual NodeType type() const override 00032 { 00033 return NodeType::DECORATOR; 00034 } 00035 00036 NodeStatus executeTick() override; 00037 }; 00038 00050 class SimpleDecoratorNode : public DecoratorNode 00051 { 00052 public: 00053 typedef std::function<NodeStatus(NodeStatus, TreeNode&)> TickFunctor; 00054 00055 // You must provide the function to call when tick() is invoked 00056 SimpleDecoratorNode(const std::string& name, TickFunctor tick_functor, const NodeConfiguration& config); 00057 00058 ~SimpleDecoratorNode() override = default; 00059 00060 protected: 00061 virtual NodeStatus tick() override; 00062 00063 TickFunctor tick_functor_; 00064 }; 00065 } 00066 00067 #endif