Skip to content

Commit 04a514e

Browse files
committed
alternative to #719
1 parent 6407989 commit 04a514e

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

include/behaviortree_cpp_v3/basic_types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ using Optional = nonstd::expected<T, std::string>;
216216
* */
217217
using Result = Optional<void>;
218218

219-
const std::unordered_set<std::string> ReservedPortNames = {"ID", "name", "_description"};
219+
inline bool IsReservedPortname(StringView name)
220+
{
221+
return name == "ID" || name == "name" || name == "_description";
222+
}
223+
220224

221225
class PortInfo
222226
{
@@ -271,7 +275,7 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction, StringView
271275
StringView description = {})
272276
{
273277
auto sname = static_cast<std::string>(name);
274-
if (ReservedPortNames.count(sname) != 0)
278+
if (IsReservedPortname(sname))
275279
{
276280
throw std::runtime_error("A port can not use a reserved name. See ReservedPortNames");
277281
}

src/xml_parsing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement* element,
523523
for (const XMLAttribute* att = element->FirstAttribute(); att; att = att->Next())
524524
{
525525
const std::string attribute_name = att->Name();
526-
if (ReservedPortNames.count(attribute_name) == 0)
526+
if (!IsReservedPortname(attribute_name))
527527
{
528528
port_remap[attribute_name] = att->Value();
529529
}
@@ -699,7 +699,7 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
699699
for (const XMLAttribute* attr = element->FirstAttribute(); attr != nullptr;
700700
attr = attr->Next())
701701
{
702-
if (ReservedPortNames.count(attr->Name()) == 0)
702+
if (!IsReservedPortname(attr->Name()))
703703
{
704704
new_bb->addSubtreeRemapping(attr->Name(), attr->Value());
705705
}
@@ -720,7 +720,7 @@ void BT::XMLParser::Pimpl::recursivelyCreateTree(const std::string& tree_ID,
720720
const char* attr_name = attr->Name();
721721
const char* attr_value = attr->Value();
722722

723-
if (ReservedPortNames.count(attr->Name()) != 0)
723+
if (IsReservedPortname(attr->Name()))
724724
{
725725
continue;
726726
}
@@ -779,7 +779,7 @@ void XMLParser::Pimpl::getPortsRecursively(const XMLElement* element,
779779
{
780780
const char* attr_name = attr->Name();
781781
const char* attr_value = attr->Value();
782-
if (ReservedPortNames.count(attr_name) == 0 &&
782+
if (!IsReservedPortname(attr_name) &&
783783
TreeNode::isBlackboardPointer(attr_value))
784784
{
785785
auto port_name = TreeNode::stripBlackboardPointer(attr_value);

0 commit comments

Comments
 (0)