basic_types.h
Go to the documentation of this file.
1 #ifndef BT_BASIC_TYPES_H
2 #define BT_BASIC_TYPES_H
3 
4 #include <iostream>
5 #include <string>
6 #include <stdexcept>
7 #include <vector>
8 #include <sstream>
9 #include <exception>
12 
13 namespace BT
14 {
15 // Enumerates the possible types of nodes
16 enum class NodeType
17 {
18  UNDEFINED = 0,
19  ACTION,
20  CONDITION,
21  CONTROL,
22  DECORATOR,
23  SUBTREE
24 };
25 
26 // Enumerates the states every node can be in after execution during a particular
27 // time step.
28 enum class NodeStatus
29 {
30  IDLE = 0,
31  RUNNING,
32  SUCCESS,
33  FAILURE
34 };
35 
36 // Enumerates the options for when a parallel node is considered to have failed:
37 // - "FAIL_ON_ONE" indicates that the node will return failure as soon as one of
38 // its children fails;
39 // - "FAIL_ON_ALL" indicates that all of the node's children must fail before it
40 // returns failure.
42 {
45 };
46 
47 // Enumerates the options for when a parallel node is considered to have succeeded:
48 // - "SUCCEED_ON_ONE" indicates that the node will return success as soon as one
49 // of its children succeeds;
50 // - "BT::SUCCEED_ON_ALL" indicates that all of the node's children must succeed before
51 // it returns success.
53 {
56 };
57 
58 typedef nonstd::string_view StringView;
59 
63 template <typename T> inline
64 T convertFromString(const StringView& /*str*/)
65 {
66  auto type_name = BT::demangle( typeid(T).name() );
67 
68  std::cerr << "You (maybe indirectly) called BT::convertFromString() for type [" <<
69  type_name <<"], but I can't find the template specialization.\n" << std::endl;
70 
71  throw std::logic_error(std::string("You didn't implement the template specialization of "
72  "convertFromString for this type: ") + type_name );
73 }
74 
75 template <>
76 std::string convertFromString<std::string>(const StringView& str);
77 
78 template <>
79 const char* convertFromString<const char*>(const StringView& str);
80 
81 template <>
82 int convertFromString<int>(const StringView& str);
83 
84 template <>
85 unsigned convertFromString<unsigned>(const StringView& str);
86 
87 template <>
88 double convertFromString<double>(const StringView& str);
89 
90 template <> // Integer numbers separated by the characted ";"
91 std::vector<int> convertFromString<std::vector<int>>(const StringView& str);
92 
93 template <> // Real numbers separated by the characted ";"
94 std::vector<double> convertFromString<std::vector<double>>(const StringView& str);
95 
96 template <> // This recognizes either 0/1, true/false, TRUE/FALSE
97 bool convertFromString<bool>(const StringView& str);
98 
99 template <> // Names with all capital letters
100 NodeStatus convertFromString<NodeStatus>(const StringView& str);
101 
102 template <> // Names with all capital letters
103 NodeType convertFromString<NodeType>(const StringView& str);
104 
105 
106 //------------------------------------------------------------------
107 
111 const char* toStr(const BT::NodeStatus& status, bool colored = false);
112 
113 std::ostream& operator<<(std::ostream& os, const BT::NodeStatus& status);
114 
118 const char* toStr(const BT::NodeType& type);
119 
120 std::ostream& operator<<(std::ostream& os, const BT::NodeType& type);
121 
122 
123 // small utility, unless you want to use <boost/algorithm/string.hpp>
124 std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
125 }
126 
127 #endif // BT_BASIC_TYPES_H
double convertFromString< double >(const StringView &str)
Definition: basic_types.cpp:92
Point3D convertFromString(const StringView &key)
NodeType convertFromString< NodeType >(const StringView &str)
SuccessPolicy
Definition: basic_types.h:52
std::ostream & operator<<(std::ostream &os, const BT::NodeStatus &status)
unsigned convertFromString< unsigned >(const StringView &str)
Definition: basic_types.cpp:86
const char * toStr(const BT::NodeStatus &status, bool colored=false)
toStr converts NodeStatus to string. Optionally colored.
Definition: basic_types.cpp:7
std::vector< StringView > splitString(const StringView &strToSplit, char delimeter)
std::string demangle(char const *name)
Definition: demangle_util.h:92
NodeStatus convertFromString< NodeStatus >(const StringView &str)
nonstd::string_view StringView
Definition: basic_types.h:58
const char * convertFromString< const char * >(const StringView &str)
Definition: basic_types.cpp:74
bool convertFromString< bool >(const StringView &str)
int convertFromString< int >(const StringView &str)
Definition: basic_types.cpp:80
NodeStatus
Definition: basic_types.h:28
FailurePolicy
Definition: basic_types.h:41
NodeType
Definition: basic_types.h:16


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53