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

Skip to content

Commit 3c19712

Browse files
author
Davide Faconti
committed
Fix issue BehaviorTree#31 : convertFromString mandatory for TreeNode::getParam, not Blackboard::get
1 parent 399eadc commit 3c19712

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

include/behaviortree_cpp/blackboard/blackboard.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
#include <unordered_map>
99

1010
#include "behaviortree_cpp/blackboard/safe_any.hpp"
11-
#include "behaviortree_cpp/optional.hpp"
1211

13-
template <typename T>
14-
T convertFromString(const std::string& str);
1512

1613
namespace BT
1714
{
@@ -74,18 +71,27 @@ class Blackboard
7471
return false;
7572
}
7673

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_)
7982
{
80-
value = convertFromString<T>(val->cast<std::string>());
83+
return false;
8184
}
82-
else
85+
const SafeAny::Any* val = impl_->get(key);
86+
if (!val)
8387
{
84-
value = val->cast<T>();
88+
return false;
8589
}
90+
value = val;
8691
return true;
8792
}
8893

94+
8995
template <typename T>
9096
T get(const std::string& key) const
9197
{

include/behaviortree_cpp/tree_node.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,20 @@ class TreeNode
147147
if ( bb_ && bb_pattern)
148148
{
149149
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+
}
151164
return found;
152165
}
153166
else{

0 commit comments

Comments
 (0)