behavior_tree.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
2  * Copyright (C) 2018-2019 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 
14 #ifndef BEHAVIOR_TREE_H
15 #define BEHAVIOR_TREE_H
16 
23 
26 
31 
35 
40 
41 namespace BT
42 {
43 
44 //Call the visitor for each node of the tree, given a root.
45 void applyRecursiveVisitor(const TreeNode* root_node,
46  const std::function<void(const TreeNode*)>& visitor);
47 
48 //Call the visitor for each node of the tree, given a root.
49 void applyRecursiveVisitor(TreeNode* root_node, const std::function<void(TreeNode*)>& visitor);
50 
54 void printTreeRecursively(const TreeNode* root_node);
55 
58 void haltAllActions(TreeNode* root_node);
59 
60 
61 typedef std::vector<std::pair<uint16_t, uint8_t>> SerializedTreeStatus;
62 
71 void buildSerializedStatusSnapshot(const TreeNode* root_node,
72  SerializedTreeStatus& serialized_buffer);
73 
76 template <typename T>
77 inline NodeType getType()
78 {
79  // clang-format off
80  if( std::is_base_of<ActionNodeBase, T>::value ) return NodeType::ACTION;
81  if( std::is_base_of<ConditionNode, T>::value ) return NodeType::CONDITION;
82  if( std::is_base_of<DecoratorSubtreeNode, T>::value ) return NodeType::SUBTREE;
83  if( std::is_base_of<DecoratorNode, T>::value ) return NodeType::DECORATOR;
84  if( std::is_base_of<ControlNode, T>::value ) return NodeType::CONTROL;
85  return NodeType::UNDEFINED;
86  // clang-format on
87 }
88 }
89 
90 #endif // BEHAVIOR_TREE_H
void printTreeRecursively(const TreeNode *root_node)
std::vector< std::pair< uint16_t, uint8_t > > SerializedTreeStatus
Definition: behavior_tree.h:61
void haltAllActions(TreeNode *root_node)
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:53
NodeType getType()
Definition: behavior_tree.h:77
void buildSerializedStatusSnapshot(const TreeNode *root_node, SerializedTreeStatus &serialized_buffer)
buildSerializedStatusSnapshot can be used to create a buffer that can be stored (or sent to a client ...
NodeType
Enumerates the possible types of nodes.
Definition: basic_types.h:22
void applyRecursiveVisitor(const TreeNode *root_node, const std::function< void(const TreeNode *)> &visitor)


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:04