From 95a2796b8429818ee77a79598eaa0dd56891cd44 Mon Sep 17 00:00:00 2001 From: David Yackzan Date: Wed, 23 Oct 2024 07:48:15 -0600 Subject: [PATCH] Check if an entry is a std::vector in a better way --- include/behaviortree_cpp/blackboard.h | 11 ++++++++++- include/behaviortree_cpp/tree_node.h | 7 ------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/behaviortree_cpp/blackboard.h b/include/behaviortree_cpp/blackboard.h index 87ed4c8da..3b7f24a9f 100644 --- a/include/behaviortree_cpp/blackboard.h +++ b/include/behaviortree_cpp/blackboard.h @@ -25,6 +25,14 @@ struct StampedValue Timestamp stamp; }; +// Helper trait to check if a type is a std::vector +template +struct is_vector : std::false_type {}; + +template +struct is_vector> : std::true_type {}; + + /** * @brief The Blackboard is the mechanism used by BehaviorTrees to exchange * typed data. @@ -258,7 +266,8 @@ inline void Blackboard::set(const std::string& key, const T& value) std::type_index previous_type = entry.info.type(); // Allow mismatch if going from vector -> vector. - bool previous_is_vector = std::string(previous_type.name()).find("vector") != std::string::npos; + auto prev_type_demangled = demangle(entry.value.type()); + bool previous_is_vector = prev_type_demangled.substr(0, 11) == "std::vector"; bool new_is_vector_any = new_value.type() == typeid(std::vector); // check type mismatch diff --git a/include/behaviortree_cpp/tree_node.h b/include/behaviortree_cpp/tree_node.h index 2535125ca..1b4dc0fdc 100644 --- a/include/behaviortree_cpp/tree_node.h +++ b/include/behaviortree_cpp/tree_node.h @@ -30,13 +30,6 @@ namespace BT { -// Helper trait to check if a type is a std::vector -template -struct is_vector : std::false_type {}; - -template -struct is_vector> : std::true_type {}; - /// This information is used mostly by the XMLParser. struct TreeNodeManifest {