decorator_node.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved
2  * Copyright (C) 2018-2020 Davide Faconti, Eurecat - All Rights Reserved
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
11 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 */
13 
15 
16 namespace BT
17 {
18 DecoratorNode::DecoratorNode(const std::string& name, const NodeConfig& config)
19  : TreeNode::TreeNode(name, config), child_node_(nullptr)
20 {}
21 
23 {
24  if(child_node_)
25  {
26  throw BehaviorTreeException("Decorator [", name(), "] has already a child assigned");
27  }
28 
30 }
31 
33 {
34  resetChild();
35  resetStatus(); // might be redundant
36 }
37 
39 {
40  return child_node_;
41 }
42 
44 {
45  return child_node_;
46 }
47 
49 {
50  resetChild();
51 }
52 
54 {
55  if(!child_node_)
56  {
57  return;
58  }
60  {
62  }
64 }
65 
67  TickFunctor tick_functor,
68  const NodeConfig& config)
69  : DecoratorNode(name, config), tick_functor_(std::move(tick_functor))
70 {}
71 
73 {
74  return tick_functor_(child()->executeTick(), *this);
75 }
76 
78 {
80  NodeStatus child_status = child()->status();
81  if(child_status == NodeStatus::SUCCESS || child_status == NodeStatus::FAILURE)
82  {
83  child()->resetStatus();
84  }
85  return status;
86 }
87 
88 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
BT::DecoratorNode::executeTick
NodeStatus executeTick() override
The method that should be used to invoke tick() and setStatus();.
Definition: decorator_node.cpp:77
BT::BehaviorTreeException
Definition: exceptions.h:23
BT::SimpleDecoratorNode::TickFunctor
std::function< NodeStatus(NodeStatus, TreeNode &)> TickFunctor
Definition: decorator_node.h:55
BT::SimpleDecoratorNode::tick
virtual NodeStatus tick() override
Method to be implemented by the user.
Definition: decorator_node.cpp:72
BT::TreeNode::executeTick
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Definition: tree_node.cpp:71
BT::DecoratorNode::haltChild
void haltChild()
Same as resetChild()
Definition: decorator_node.cpp:48
BT::TreeNode
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:118
BT::DecoratorNode
Definition: decorator_node.h:8
BT::TreeNode::status
NodeStatus status() const
Definition: tree_node.cpp:279
BT::NodeStatus::FAILURE
@ FAILURE
BT::TreeNode::haltNode
void haltNode()
Definition: tree_node.cpp:142
lexy_ext::child
auto child(const lexy::parse_tree< Reader, TokenKind, MemoryResource > &tree, typename lexy::parse_tree< Reader, TokenKind, MemoryResource >::node node, Predicate predicate) -> std::optional< typename lexy::parse_tree< Reader, TokenKind, MemoryResource >::node >
Returns the first child that matches predicate, if there is any.
Definition: parse_tree_algorithm.hpp:244
BT::SimpleDecoratorNode::SimpleDecoratorNode
SimpleDecoratorNode(const std::string &name, TickFunctor tick_functor, const NodeConfig &config)
Definition: decorator_node.cpp:66
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:296
BT::NodeStatus::SUCCESS
@ SUCCESS
BT::TreeNode::DecoratorNode
friend class DecoratorNode
Definition: tree_node.h:368
BT::DecoratorNode::child
const TreeNode * child() const
Definition: decorator_node.cpp:38
BT::NodeStatus::RUNNING
@ RUNNING
BT::SimpleDecoratorNode::tick_functor_
TickFunctor tick_functor_
Definition: decorator_node.h:66
BT::DecoratorNode::halt
virtual void halt() override
The method used to interrupt the execution of this node.
Definition: decorator_node.cpp:32
BT::TreeNode::resetStatus
void resetStatus()
Set the status to IDLE.
Definition: tree_node.cpp:262
std
Definition: std.hpp:30
BT::DecoratorNode::setChild
void setChild(TreeNode *child)
Definition: decorator_node.cpp:22
BT::NodeConfig
Definition: tree_node.h:73
BT::DecoratorNode::resetChild
void resetChild()
Definition: decorator_node.cpp:53
decorator_node.h
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33
BT::DecoratorNode::child_node_
TreeNode * child_node_
Definition: decorator_node.h:11


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:07