File tree Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Expand file tree Collapse file tree 2 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 8
8
#include < unordered_map>
9
9
10
10
#include " behaviortree_cpp/blackboard/safe_any.hpp"
11
- #include " behaviortree_cpp/optional.hpp"
12
11
13
- template <typename T>
14
- T convertFromString (const std::string& str);
15
12
16
13
namespace BT
17
14
{
@@ -74,18 +71,27 @@ class Blackboard
74
71
return false ;
75
72
}
76
73
77
- if (!std::is_same<std::string, T>::value &&
78
- (val->type () == typeid (SafeAny::SimpleString) || val->type () == typeid (std::string)))
74
+ value = val->cast <T>();
75
+ return true ;
76
+ }
77
+
78
+ template <typename T>
79
+ bool get (const std::string& key, const SafeAny::Any* value) const
80
+ {
81
+ if (!impl_)
79
82
{
80
- value = convertFromString<T>(val-> cast <std::string>()) ;
83
+ return false ;
81
84
}
82
- else
85
+ const SafeAny::Any* val = impl_->get (key);
86
+ if (!val)
83
87
{
84
- value = val-> cast <T>() ;
88
+ return false ;
85
89
}
90
+ value = val;
86
91
return true ;
87
92
}
88
93
94
+
89
95
template <typename T>
90
96
T get (const std::string& key) const
91
97
{
Original file line number Diff line number Diff line change @@ -147,7 +147,20 @@ class TreeNode
147
147
if ( bb_ && bb_pattern)
148
148
{
149
149
const std::string stripped_key (&str[2 ], str.size () - 3 );
150
- bool found = bb_->get (stripped_key, destination);
150
+ const SafeAny::Any* val;
151
+ bool found = bb_->get (stripped_key, val);
152
+ if ( found )
153
+ {
154
+ if ( std::is_same<T,std::string>::value == false &&
155
+ (val->type () == typeid (std::string) ||
156
+ val->type () == typeid (SafeAny::SimpleString)))
157
+ {
158
+ destination = convertFromString<T>(val->cast <std::string>());
159
+ }
160
+ else {
161
+ destination = val->cast <T>();
162
+ }
163
+ }
151
164
return found;
152
165
}
153
166
else {
You can’t perform that action at this time.
0 commit comments