Skip to content

Commit 29c90be

Browse files
committed
Check if an entry is a std::vector in a better way
1 parent 823f2a2 commit 29c90be

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

Diff for: include/behaviortree_cpp/blackboard.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ struct StampedValue
2525
Timestamp stamp;
2626
};
2727

28+
// Helper trait to check if a type is a std::vector
29+
template <typename T>
30+
struct is_vector : std::false_type {};
31+
32+
template <typename T, typename A>
33+
struct is_vector<std::vector<T, A>> : std::true_type {};
34+
35+
2836
/**
2937
* @brief The Blackboard is the mechanism used by BehaviorTrees to exchange
3038
* typed data.
@@ -258,7 +266,8 @@ inline void Blackboard::set(const std::string& key, const T& value)
258266
std::type_index previous_type = entry.info.type();
259267

260268
// Allow mismatch if going from vector -> vector<Any>.
261-
bool previous_is_vector = std::string(previous_type.name()).find("vector") != std::string::npos;
269+
auto prev_type_demangled = demangle(entry.value.type());
270+
bool previous_is_vector = prev_type_demangled.substr(0, 11) == "std::vector";
262271
bool new_is_vector_any = new_value.type() == typeid(std::vector<Any>);
263272

264273
// check type mismatch

Diff for: include/behaviortree_cpp/tree_node.h

-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@
3030

3131
namespace BT
3232
{
33-
// Helper trait to check if a type is a std::vector
34-
template <typename T>
35-
struct is_vector : std::false_type {};
36-
37-
template <typename T, typename A>
38-
struct is_vector<std::vector<T, A>> : std::true_type {};
39-
4033
/// This information is used mostly by the XMLParser.
4134
struct TreeNodeManifest
4235
{

Diff for: src/xml_parsing.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
789789
// special case related to unwrapping vector<Any> -> vector<T> objects.
790790
bool const vec_any_input = (prev_info->type() == typeid(std::vector<Any>));
791791
// special case related to wrapping vector<T> -> vector<Any> objects.
792-
bool previous_is_vector = std::string(prev_info->type().name()).find("vector") != std::string::npos;
792+
auto prev_type_demangled = demangle(prev_info->type());
793+
bool previous_is_vector = prev_type_demangled.substr(0, 11) == "std::vector";
793794
bool new_is_vector_any = port_info.type() == typeid(std::vector<Any>);
794795

795796
if(port_type_mismatch && !string_input &&

0 commit comments

Comments
 (0)