Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4b3f1e

Browse files
author
Davide Faconti
committed
update
1 parent fd59513 commit f4b3f1e

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

include/behaviortree_cpp/basic_types.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ enum class NodeStatus
3838
FAILURE
3939
};
4040

41+
enum class PortDirection{
42+
INPUT,
43+
OUTPUT,
44+
INOUT
45+
};
46+
47+
4148
typedef nonstd::string_view StringView;
4249

4350
/**
@@ -90,6 +97,10 @@ NodeStatus convertFromString<NodeStatus>(StringView str);
9097
template <> // Names with all capital letters
9198
NodeType convertFromString<NodeType>(StringView str);
9299

100+
template <>
101+
PortDirection convertFromString<PortDirection>(StringView str);
102+
103+
93104
typedef std::function<Any(StringView)> StringConverter;
94105

95106
typedef std::unordered_map<const std::type_info*, StringConverter> StringConvertersMap;
@@ -113,18 +124,22 @@ StringConverter GetAnyFromStringFunctor<void>()
113124
/**
114125
* @brief toStr converts NodeStatus to string. Optionally colored.
115126
*/
116-
const char* toStr(const BT::NodeStatus& status, bool colored = false);
127+
const char* toStr(BT::NodeStatus status, bool colored = false);
117128

118129
std::ostream& operator<<(std::ostream& os, const BT::NodeStatus& status);
119130

120131
/**
121132
* @brief toStr converts NodeType to string.
122133
*/
123-
const char* toStr(const BT::NodeType& type);
134+
const char* toStr(BT::NodeType type);
124135

125136
std::ostream& operator<<(std::ostream& os, const BT::NodeType& type);
126137

127138

139+
const char* toStr(BT::PortDirection direction);
140+
141+
std::ostream& operator<<(std::ostream& os, const BT::PortDirection& type);
142+
128143
// Small utility, unless you want to use <boost/algorithm/string.hpp>
129144
std::vector<StringView> splitString(const StringView& strToSplit, char delimeter);
130145

@@ -173,13 +188,6 @@ template <typename T> using Optional = nonstd::expected<T, std::string>;
173188
* */
174189
using Result = Optional<void>;
175190

176-
enum class PortDirection{INPUT, OUTPUT, INOUT };
177-
178-
const char* toStr(PortDirection type);
179-
180-
std::ostream& operator<<(std::ostream& os, const BT::PortDirection& type);
181-
182-
183191
class PortInfo
184192
{
185193

src/basic_types.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BT
66
{
7-
const char* toStr(const NodeStatus& status, bool colored)
7+
const char* toStr(NodeStatus status, bool colored)
88
{
99
if (!colored)
1010
{
@@ -45,7 +45,7 @@ const char* toStr(const NodeStatus& status, bool colored)
4545
return "Undefined";
4646
}
4747

48-
const char* toStr(const NodeType& type)
48+
const char* toStr(NodeType type)
4949
{
5050
switch (type)
5151
{
@@ -174,6 +174,15 @@ NodeType convertFromString<NodeType>(StringView str)
174174
return NodeType::UNDEFINED;
175175
}
176176

177+
template <>
178+
PortDirection convertFromString<PortDirection>(StringView str)
179+
{
180+
if( str == "Input" || str == "INPUT" ) return PortDirection::INPUT;
181+
if( str == "Output" || str == "OUTPUT") return PortDirection::OUTPUT;
182+
return PortDirection::INOUT;
183+
}
184+
185+
177186
std::ostream& operator<<(std::ostream& os, const NodeType& type)
178187
{
179188
os << toStr(type);
@@ -217,10 +226,6 @@ PortDirection PortInfo::direction() const
217226
return _type;
218227
}
219228

220-
const std::type_info* PortInfo::type() const
221-
{
222-
return _info;
223-
}
224229

225230
Any PortInfo::parseString(const char *str) const
226231
{
@@ -254,11 +259,16 @@ const char *toStr(PortDirection type)
254259
{
255260
switch(type)
256261
{
257-
case PortDirection::INPUT: return "input_port";
258-
case PortDirection::OUTPUT: return "output_port";
259-
case PortDirection::INOUT: return "input_port";
262+
case PortDirection::INPUT: return "Input";
263+
case PortDirection::OUTPUT: return "Output";
264+
case PortDirection::INOUT: return "InOut";
260265
}
261266
}
262267

268+
const std::type_info* PortInfo::type() const
269+
{
270+
return _info;
271+
}
272+
263273

264274
} // end namespace

0 commit comments

Comments
 (0)