behavior_tree.h
Go to the documentation of this file.
1 /* Copyright (C) 2015-2018 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 
14 #ifndef BEHAVIOR_TREE_H
15 #define BEHAVIOR_TREE_H
16 
27 
30 
35 
39 
46 
47 #include <iostream>
48 
49 namespace BT
50 {
51 
52 //Call the visitor for each node of the tree, given a root.
53 void applyRecursiveVisitor(const TreeNode* root_node,
54  const std::function<void(const TreeNode*)>& visitor);
55 
56 //Call the visitor for each node of the tree, given a root.
57 void applyRecursiveVisitor(TreeNode* root_node, const std::function<void(TreeNode*)>& visitor);
58 
62 void printTreeRecursively(const TreeNode* root_node, std::ostream& stream = std::cout);
63 
64 typedef std::vector<std::pair<uint16_t, uint8_t>> SerializedTreeStatus;
65 
74 void buildSerializedStatusSnapshot(const TreeNode* root_node,
75  SerializedTreeStatus& serialized_buffer);
76 
79 template <typename T>
80 inline NodeType getType()
81 {
82  // clang-format off
83  if( std::is_base_of<ActionNodeBase, T>::value ) return NodeType::ACTION;
84  if( std::is_base_of<ConditionNode, T>::value ) return NodeType::CONDITION;
85  if( std::is_base_of<SubtreeNode, T>::value ) return NodeType::SUBTREE;
86  if( std::is_base_of<SubtreePlusNode, T>::value ) return NodeType::SUBTREE;
87  if( std::is_base_of<DecoratorNode, T>::value ) return NodeType::DECORATOR;
88  if( std::is_base_of<ControlNode, T>::value ) return NodeType::CONTROL;
89  return NodeType::UNDEFINED;
90  // clang-format on
91 }
92 }
93 
94 #endif // BEHAVIOR_TREE_H
std::vector< std::pair< uint16_t, uint8_t > > SerializedTreeStatus
Definition: behavior_tree.h:64
void printTreeRecursively(const TreeNode *root_node, std::ostream &stream=std::cout)
Abstract base class for Behavior Tree Nodes.
Definition: tree_node.h:53
NodeType getType()
Definition: behavior_tree.h:80
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)


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