Skip to content

Commit

Permalink
Fix: Support multiple nested variable groups (#549)
Browse files Browse the repository at this point in the history
* Triggering the bug #548

* Allow returning empty if no variables are found in the variable group #548

* simplifying get_variable_group_variables #548
  • Loading branch information
ljamt authored Mar 30, 2020
1 parent 2ea32f1 commit d644b19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/cpp/cse_config_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,9 @@ extended_model_description get_emd(

std::vector<std::string> get_variable_group_variables(
const std::unordered_map<std::string, variable_group_description>& descriptions,
const cse_config_parser::VariableEndpoint endpoint)
const cse_config_parser::VariableEndpoint& endpoint)
{
std::vector<std::string> groupVariables;
auto groupIt = descriptions.find(endpoint.name);
if (groupIt == descriptions.end()) {
for (const auto& description : descriptions) {
Expand All @@ -738,14 +739,16 @@ std::vector<std::string> get_variable_group_variables(
for (const auto& variableGroupDescr : description.second.variable_group_descriptions) {
nestedDescriptions.insert({variableGroupDescr.name, variableGroupDescr});
}
return get_variable_group_variables(nestedDescriptions, endpoint);
groupVariables = get_variable_group_variables(nestedDescriptions, endpoint);
if (groupVariables.size() > 0) {
break;
}
}
}
std::ostringstream oss;
oss << "Cannot find variable group description: " << endpoint.simulator << ":" << endpoint.name;
throw std::out_of_range(oss.str());
} else {
groupVariables = groupIt->second.variables;
}
return groupIt->second.variables;
return groupVariables;
}

std::vector<cse::variable_group_description> get_variable_groups(
Expand Down
5 changes: 5 additions & 0 deletions test/data/msmi/CraneController_OspModelDescription.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<Variable ref="Act_Limits[2]"/>
<Variable ref="Act_Limits[3]"/>
</Generic>
<Generic name="Test - do not connect">
<Generic name="Test2 - do not connect">
<Variable ref="Act_Limits[1]"/>
</Generic>
</Generic>
<LinearMechanicalPort name="linear mechanical port">
<Force name="force">
<Variable ref="p_Crane.e[1]" unit="force~N"/>
Expand Down

0 comments on commit d644b19

Please sign in to comment.