Skip to content

Commit

Permalink
Use a lambda, and check if string is empty in case it was incorrectly…
Browse files Browse the repository at this point in the history
… set before
  • Loading branch information
jmarrec committed Mar 17, 2023
1 parent a82809e commit 2e12f6a
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/utilities/bcl/BCLMeasureArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,21 @@ BCLMeasureArgument::BCLMeasureArgument(const pugi::xml_node& element) {

m_displayName = element.child("display_name").text().as_string();

if (auto subelement = element.child("description")) {
m_description = subelement.text().as_string();
}
auto getOptionaString = [&element](const char* name) -> boost::optional<std::string> {
if (auto subelement = element.child(name)) {
const std::string text = subelement.text().as_string();
if (!text.empty()) {
return {text};
}
}
return boost::none;
};

m_description = getOptionaString("description");

m_type = element.child("type").text().as_string();

if (auto subelement = element.child("units")) {
m_units = subelement.text().as_string();
}
m_units = getOptionaString("units");

m_required = false;
std::string test = element.child("required").text().as_string();
Expand All @@ -65,9 +71,7 @@ BCLMeasureArgument::BCLMeasureArgument(const pugi::xml_node& element) {
m_modelDependent = true;
}

if (auto subelement = element.child("default_value")) {
m_defaultValue = subelement.text().as_string();
}
m_defaultValue = getOptionaString("default_value");

if (auto subelement = element.child("choices")) {
for (auto& choiceElement : subelement.children("choice")) {
Expand All @@ -79,19 +83,14 @@ BCLMeasureArgument::BCLMeasureArgument(const pugi::xml_node& element) {
// DLM: this is technically an invalid file, attempt to fix it here
m_choiceDisplayNames.push_back(choiceValue);
} else {
m_choiceDisplayNames.push_back(display_name.text().as_string());
m_choiceDisplayNames.emplace_back(display_name.text().as_string());
}
}
}
}

if (auto subelement = element.child("min_value")) {
m_minValue = subelement.text().as_string();
}

if (auto subelement = element.child("max_value")) {
m_maxValue = subelement.text().as_string();
}
m_minValue = getOptionaString("min_value");
m_maxValue = getOptionaString("max_value");
}

BCLMeasureArgument::BCLMeasureArgument(const std::string& name, const std::string& displayName, const boost::optional<std::string>& description,
Expand Down

0 comments on commit 2e12f6a

Please sign in to comment.