basic_types.h
Go to the documentation of this file.
00001 #ifndef BT_BASIC_TYPES_H
00002 #define BT_BASIC_TYPES_H
00003 
00004 #include <iostream>
00005 #include <string>
00006 #include <stdexcept>
00007 #include <vector>
00008 #include <sstream>
00009 #include <exception>
00010 #include "behaviortree_cpp/string_view.hpp"
00011 #include "behaviortree_cpp/blackboard/demangle_util.h"
00012 
00013 namespace BT
00014 {
00015 // Enumerates the possible types of nodes
00016 enum class NodeType
00017 {
00018     UNDEFINED = 0,
00019     ACTION,
00020     CONDITION,
00021     CONTROL,
00022     DECORATOR,
00023     SUBTREE
00024 };
00025 
00026 // Enumerates the states every node can be in after execution during a particular
00027 // time step.
00028 enum class NodeStatus
00029 {
00030     IDLE = 0,
00031     RUNNING,
00032     SUCCESS,
00033     FAILURE
00034 };
00035 
00036 // Enumerates the options for when a parallel node is considered to have failed:
00037 // - "FAIL_ON_ONE" indicates that the node will return failure as soon as one of
00038 //   its children fails;
00039 // - "FAIL_ON_ALL" indicates that all of the node's children must fail before it
00040 //   returns failure.
00041 enum FailurePolicy
00042 {
00043     FAIL_ON_ONE,
00044     FAIL_ON_ALL
00045 };
00046 
00047 // Enumerates the options for when a parallel node is considered to have succeeded:
00048 // - "SUCCEED_ON_ONE" indicates that the node will return success as soon as one
00049 //   of its children succeeds;
00050 // - "BT::SUCCEED_ON_ALL" indicates that all of the node's children must succeed before
00051 //   it returns success.
00052 enum SuccessPolicy
00053 {
00054     SUCCEED_ON_ONE,
00055     SUCCEED_ON_ALL
00056 };
00057 
00058 typedef nonstd::string_view StringView;
00059 
00063 template <typename T> inline
00064 T convertFromString(const StringView& /*str*/)
00065 {
00066     auto type_name = BT::demangle( typeid(T).name() );
00067 
00068     std::cerr << "You (maybe indirectly) called BT::convertFromString() for type [" <<
00069                  type_name <<"], but I can't find the template specialization.\n" << std::endl;
00070 
00071     throw std::logic_error(std::string("You didn't implement the template specialization of "
00072                                        "convertFromString for this type: ") + type_name );
00073 }
00074 
00075 template <>
00076 std::string convertFromString<std::string>(const StringView& str);
00077 
00078 template <>
00079 const char* convertFromString<const char*>(const StringView& str);
00080 
00081 template <>
00082 int convertFromString<int>(const StringView& str);
00083 
00084 template <>
00085 unsigned convertFromString<unsigned>(const StringView& str);
00086 
00087 template <>
00088 double convertFromString<double>(const StringView& str);
00089 
00090 template <> // Integer numbers separated by the characted ";"
00091 std::vector<int> convertFromString<std::vector<int>>(const StringView& str);
00092 
00093 template <> // Real numbers separated by the characted ";"
00094 std::vector<double> convertFromString<std::vector<double>>(const StringView& str);
00095 
00096 template <> // This recognizes either 0/1, true/false, TRUE/FALSE
00097 bool convertFromString<bool>(const StringView& str);
00098 
00099 template <> // Names with all capital letters
00100 NodeStatus convertFromString<NodeStatus>(const StringView& str);
00101 
00102 template <>  // Names with all capital letters
00103 NodeType convertFromString<NodeType>(const StringView& str);
00104 
00105 
00106 //------------------------------------------------------------------
00107 
00111 const char* toStr(const BT::NodeStatus& status, bool colored = false);
00112 
00113 std::ostream& operator<<(std::ostream& os, const BT::NodeStatus& status);
00114 
00118 const char* toStr(const BT::NodeType& type);
00119 
00120 std::ostream& operator<<(std::ostream& os, const BT::NodeType& type);
00121 
00122 
00123 // small utility, unless you want to use <boost/algorithm/string.hpp>
00124 std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
00125 }
00126 
00127 #endif   // BT_BASIC_TYPES_H


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 03:50:09