decorator_node.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 * 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:
6 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 * 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,
10 * 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.
11 */
12 
14 
15 namespace BT
16 {
17 DecoratorNode::DecoratorNode(const std::string& name, const NodeParameters& parameters)
18  : TreeNode::TreeNode(name, parameters), child_node_(nullptr)
19 {
20  // TODO(...) In case it is desired to set to idle remove the ReturnStatus
21  // type in order to set the member variable
22  // ReturnStatus const NodeStatus child_status = NodeStatus::IDLE; // commented out as unused
23 }
24 
26 {
27  if (child_node_)
28  {
29  throw BehaviorTreeException("Decorator '" + name() + "' has already a child assigned");
30  }
31 
33 }
34 
36 {
37  haltChild();
39 }
40 
42 {
43  return child_node_;
44 }
45 
47 {
48  return child_node_;
49 }
50 
52 {
54  {
55  child_node_->halt();
56  }
58 }
59 
61  const NodeParameters &params)
62  : DecoratorNode(name, params), tick_functor_(std::move(tick_functor))
63 {
64 }
65 
67 {
68  return tick_functor_(child()->executeTick(), *this);
69 }
70 
72 {
74  NodeStatus child_status =child()->status();
75  if( child_status == NodeStatus::SUCCESS || child_status == NodeStatus::FAILURE )
76  {
78  }
79  return status;
80 }
81 
82 }
const TreeNode * child() const
const std::string & name() const
Definition: tree_node.cpp:92
virtual void halt()=0
The method used to interrupt the execution of a RUNNING node.
std::function< NodeStatus(NodeStatus, TreeNode &)> TickFunctor
virtual NodeStatus tick() override
Method to be implemented by the user.
Definition: any.hpp:455
virtual void halt() override
The method used to interrupt the execution of a RUNNING node.
TreeNode * child_node_
std::unordered_map< std::string, std::string > NodeParameters
Definition: tree_node.h:33
void setChild(TreeNode *child)
DecoratorNode(const std::string &name, const NodeParameters &parameters)
NodeStatus executeTick() override
The method that will be executed to invoke tick(); and setStatus();.
SimpleDecoratorNode(const std::string &name, TickFunctor tick_functor, const NodeParameters &params=NodeParameters())
NodeStatus status() const
Definition: tree_node.cpp:75
NodeStatus
Definition: basic_types.h:28
virtual BT::NodeStatus executeTick()
The method that will be executed to invoke tick(); and setStatus();.
Definition: tree_node.cpp:35
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:43


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53