BehaviorTree
Core Library to create and execute Behavior Trees
Loading...
Searching...
No Matches
if_then_else_node.h
1/* Copyright (C) 2020-2025 Davide Faconti - 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
13#pragma once
14
15#include "behaviortree_cpp/control_node.h"
16
17namespace BT
18{
19/**
20 * @brief IfThenElseNode must have exactly 2 or 3 children. This node is NOT reactive.
21 *
22 * The first child is the "statement" of the if.
23 *
24 * If that return SUCCESS, then the second child is executed.
25 *
26 * Instead, if it returned FAILURE, the third child is executed.
27 *
28 * If you have only 2 children, this node will return FAILURE whenever the
29 * statement returns FAILURE.
30 *
31 * This is equivalent to add AlwaysFailure as 3rd child.
32 *
33 */
34class IfThenElseNode : public ControlNode
35{
36public:
37 IfThenElseNode(const std::string& name);
38
39 ~IfThenElseNode() override = default;
40
41 IfThenElseNode(const IfThenElseNode&) = delete;
42 IfThenElseNode& operator=(const IfThenElseNode&) = delete;
43 IfThenElseNode(IfThenElseNode&&) = delete;
44 IfThenElseNode& operator=(IfThenElseNode&&) = delete;
45
46 virtual void halt() override;
47
48private:
49 size_t child_idx_;
50
51 virtual BT::NodeStatus tick() override;
52};
53
54} // namespace BT
The ControlNode is the base class for nodes that can have multiple children.
Definition: control_node.h:32
IfThenElseNode must have exactly 2 or 3 children. This node is NOT reactive.
Definition: if_then_else_node.h:35
virtual void halt() override
Definition: action_node.h:24
NodeStatus
Definition: basic_types.h:34