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 NodeConfiguration& config)
19  : TreeNode::TreeNode(name, config), child_node_(nullptr)
20 {
21 }
22 
24 {
25  if (child_node_)
26  {
27  throw BehaviorTreeException("Decorator [", name(), "] has already a child assigned");
28  }
29 
31 }
32 
34 {
35  haltChild();
37 }
38 
40 {
41  return child_node_;
42 }
43 
45 {
46  return child_node_;
47 }
48 
50 {
51  if( !child_node_ ){
52  return;
53  }
55  {
56  child_node_->halt();
57  }
59 }
60 
63  : DecoratorNode(name, config), tick_functor_(std::move(tick_functor))
64 {
65 }
66 
68 {
69  return tick_functor_(child()->executeTick(), *this);
70 }
71 
73 {
75  NodeStatus child_status = child()->status();
76  if( child_status == NodeStatus::SUCCESS || child_status == NodeStatus::FAILURE )
77  {
79  }
80  return status;
81 }
82 
83 }
const TreeNode * child() const
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:73
virtual void halt()=0
const NodeConfiguration & config() const
Definition: tree_node.cpp:99
std::function< NodeStatus(NodeStatus, TreeNode &)> TickFunctor
virtual NodeStatus tick() override
Method to be implemented by the user.
DecoratorNode(const std::string &name, const NodeConfiguration &config)
Definition: any.hpp:455
virtual void halt() override
The method used to interrupt the execution of this node.
TreeNode * child_node_
void haltChild()
Halt() the child node.
SimpleDecoratorNode(const std::string &name, TickFunctor tick_functor, const NodeConfiguration &config)
void setChild(TreeNode *child)
NodeStatus executeTick() override
The method that should be used to invoke tick() and setStatus();.
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:53
NodeStatus status() const
Definition: tree_node.cpp:56
NodeStatus
Definition: basic_types.h:35
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Definition: tree_node.cpp:33
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:40


behaviotree_cpp_v3
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Tue May 4 2021 02:56:24