Skip to content

Commit

Permalink
alternative to #719
Browse files Browse the repository at this point in the history
  • Loading branch information
facontidavide committed Dec 19, 2023
1 parent 6407989 commit 04a514e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions include/behaviortree_cpp_v3/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ using Optional = nonstd::expected<T, std::string>;
* */
using Result = Optional<void>;

const std::unordered_set<std::string> ReservedPortNames = {"ID", "name", "_description"};
inline bool IsReservedPortname(StringView name)
{
return name == "ID" || name == "name" || name == "_description";
}


class PortInfo
{
Expand Down Expand Up @@ -271,7 +275,7 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction, StringView
StringView description = {})
{
auto sname = static_cast<std::string>(name);
if (ReservedPortNames.count(sname) != 0)
if (IsReservedPortname(sname))
{
throw std::runtime_error("A port can not use a reserved name. See ReservedPortNames");
}
Expand Down
8 changes: 4 additions & 4 deletions src/xml_parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement* element,
for (const XMLAttribute* att = element->FirstAttribute(); att; att = att->Next())
{
const std::string attribute_name = att->Name();
if (ReservedPortNames.count(attribute_name) == 0)
if (!IsReservedPortname(attribute_name))
{
port_remap[attribute_name] = att->Value();
}
Expand Down Expand Up @@ -699,7 +699,7 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
for (const XMLAttribute* attr = element->FirstAttribute(); attr != nullptr;
attr = attr->Next())
{
if (ReservedPortNames.count(attr->Name()) == 0)
if (!IsReservedPortname(attr->Name()))
{
new_bb->addSubtreeRemapping(attr->Name(), attr->Value());
}
Expand All @@ -720,7 +720,7 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
const char* attr_name = attr->Name();
const char* attr_value = attr->Value();

if (ReservedPortNames.count(attr->Name()) != 0)
if (IsReservedPortname(attr->Name()))
{
continue;
}
Expand Down Expand Up @@ -779,7 +779,7 @@ void XMLParser::Pimpl::getPortsRecursively(const XMLElement* element,
{
const char* attr_name = attr->Name();
const char* attr_value = attr->Value();
if (ReservedPortNames.count(attr_name) == 0 &&
if (!IsReservedPortname(attr_name) &&
TreeNode::isBlackboardPointer(attr_value))
{
auto port_name = TreeNode::stripBlackboardPointer(attr_value);
Expand Down

0 comments on commit 04a514e

Please sign in to comment.