00001 /* Copyright (C) 2018-2019 Davide Faconti, Eurecat - All Rights Reserved 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 00004 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 00005 * 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: 00006 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00009 * 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, 00010 * 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. 00011 */ 00012 00013 #ifndef DECORATOR_ALWAYS_SUCCESS_NODE_H 00014 #define DECORATOR_ALWAYS_SUCCESS_NODE_H 00015 00016 #include "behaviortree_cpp/decorator_node.h" 00017 00018 namespace BT 00019 { 00023 class ForceSuccessNode : public DecoratorNode 00024 { 00025 public: 00026 ForceSuccessNode(const std::string& name) : 00027 DecoratorNode(name, {} ) 00028 { 00029 setRegistrationID("ForceSuccess"); 00030 } 00031 00032 private: 00033 virtual BT::NodeStatus tick() override; 00034 }; 00035 00036 //------------ implementation ---------------------------- 00037 00038 inline NodeStatus ForceSuccessNode::tick() 00039 { 00040 setStatus(NodeStatus::RUNNING); 00041 00042 const NodeStatus child_state = child_node_->executeTick(); 00043 00044 switch (child_state) 00045 { 00046 case NodeStatus::FAILURE: 00047 case NodeStatus::SUCCESS: 00048 { 00049 return NodeStatus::SUCCESS; 00050 } 00051 00052 case NodeStatus::RUNNING: 00053 { 00054 return NodeStatus::RUNNING; 00055 } 00056 00057 default: 00058 { 00059 // TODO throw? 00060 } 00061 } 00062 return status(); 00063 } 00064 } 00065 00066 #endif