Skip to content

Commit

Permalink
Check if an entry is a std::vector in a better way
Browse files Browse the repository at this point in the history
  • Loading branch information
dyackzan committed Oct 23, 2024
1 parent 823f2a2 commit 29c90be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 10 additions & 1 deletion include/behaviortree_cpp/blackboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ struct StampedValue
Timestamp stamp;
};

// Helper trait to check if a type is a std::vector
template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};


/**
* @brief The Blackboard is the mechanism used by BehaviorTrees to exchange
* typed data.
Expand Down Expand Up @@ -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<Any>.
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<Any>);

// check type mismatch
Expand Down
7 changes: 0 additions & 7 deletions include/behaviortree_cpp/tree_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@

namespace BT
{
// Helper trait to check if a type is a std::vector
template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};

/// This information is used mostly by the XMLParser.
struct TreeNodeManifest
{
Expand Down
3 changes: 2 additions & 1 deletion src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
// special case related to unwrapping vector<Any> -> vector<T> objects.
bool const vec_any_input = (prev_info->type() == typeid(std::vector<Any>));
// special case related to wrapping vector<T> -> vector<Any> objects.
bool previous_is_vector = std::string(prev_info->type().name()).find("vector") != std::string::npos;
auto prev_type_demangled = demangle(prev_info->type());
bool previous_is_vector = prev_type_demangled.substr(0, 11) == "std::vector";
bool new_is_vector_any = port_info.type() == typeid(std::vector<Any>);

if(port_type_mismatch && !string_input &&
Expand Down

0 comments on commit 29c90be

Please sign in to comment.