Skip to content

Commit 153fccb

Browse files
committed
make default value of port optional, to allow empty strings
1 parent f9b0a88 commit 153fccb

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

include/behaviortree_cpp/basic_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class PortInfo
265265

266266
const std::string& description() const;
267267

268-
const std::string& defaultValue() const;
268+
std::optional<std::string> defaultValue() const;
269269

270270
bool isStronglyTyped() const
271271
{
@@ -282,7 +282,7 @@ class PortInfo
282282
std::type_index _type_info;
283283
StringConverter _converter;
284284
std::string description_;
285-
std::string default_value_;
285+
std::optional<std::string> default_value_;
286286
};
287287

288288
template <typename T = PortInfo::AnyTypeAllowed>

src/basic_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ const std::string& PortInfo::description() const
356356
return description_;
357357
}
358358

359-
const std::string& PortInfo::defaultValue() const
359+
std::optional<std::string> PortInfo::defaultValue() const
360360
{
361361
return default_value_;
362362
}

src/xml_parsing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ TreeNode::Ptr XMLParser::Pimpl::createNodeFromXML(const XMLElement* element,
632632
auto direction = port_info.direction();
633633
if (direction != PortDirection::OUTPUT &&
634634
config.input_ports.count(port_name) == 0 &&
635-
port_info.defaultValue().empty() == false)
635+
port_info.defaultValue())
636636
{
637-
config.input_ports.insert({port_name, port_info.defaultValue()});
637+
config.input_ports.insert({port_name, *port_info.defaultValue()});
638638
}
639639
}
640640

@@ -867,9 +867,9 @@ std::string writeTreeNodesModelXML(const BehaviorTreeFactory& factory,
867867
{
868868
port_element->SetAttribute("type", BT::demangle(port_info.type()).c_str());
869869
}
870-
if (!port_info.defaultValue().empty())
870+
if (!port_info.defaultValue())
871871
{
872-
port_element->SetAttribute("default", port_info.defaultValue().c_str());
872+
port_element->SetAttribute("default", port_info.defaultValue()->c_str());
873873
}
874874

875875
if (!port_info.description().empty())

0 commit comments

Comments
 (0)