Skip to content

Commit

Permalink
Simplify nested model logic. Thanks to azeey
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Luis Rivero <[email protected]>
  • Loading branch information
j-rivero committed Jun 29, 2021
1 parent 338d966 commit 4b97716
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
11 changes: 2 additions & 9 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1119,17 +1119,10 @@ void addNestedModel(ElementPtr _sdf, ElementPtr _includeSDF)
std::string(">") + name_with_nested_prefix + "<");
// Deal with nested model inside other nested model and already with
// ::namespace:: entries in the name
// Case A. ::namespace1::iter.first::namespace2
replace_all(str, std::string("::") + old_name + "::",
std::string("::") + name_with_nested_prefix + "::");
// Case B. >iter.first::component
replace_all(str, std::string(">") + old_name + "::",
std::string(">") + name_with_nested_prefix + "::");
// Case C.::component::iter.first<
replace_all(str, std::string("::") + old_name + "<",
std::string("::") + name_with_nested_prefix + "<");
// remove duplicate prefixes introduced by the logic above (cases
// A,B,C) if the full name (iter.second) was used in the original SDF: (i.e
// remove duplicate prefixes introduced by the logic above
// if the full name (iter.second) was used in the original SDF: (i.e
// iter.second::component)
std::string::size_type found = name_with_nested_prefix.find(old_name);
if (found != std::string::npos)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/model/nested_names_test/submodel_test.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<joint name='joint2' type='revolute'>
<parent>main_model_prefix::subnested_model::link1</parent>
<child>other_prefix::subnested_model</child>
<child>joint1</child>
</joint>
</model>
</sdf>
8 changes: 2 additions & 6 deletions test/integration/nested_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,11 @@ TEST(NestedModel, IncludeFlatteningNames)
"main_model_prefix::subnested_model");
EXPECT_EQ(jointElem->Get<std::string>("child"),
"main_model_prefix::subnested_model::link1") <<
"Flattening logic for nested models failed for case B (check parser.cc)";
"Flattening logic for nested models failed (check parser.cc)";

sdf::ElementPtr joint2Elem = jointElem->GetNextElement("joint");
EXPECT_EQ(joint2Elem->Get<std::string>("name"), "main_model_prefix::joint2");
EXPECT_EQ(joint2Elem->Get<std::string>("parent"),
"main_model_prefix::subnested_model::link1") <<
"Flattening logic for nested models failed for case A" <<
"(check parser.cc) + duplicates";
EXPECT_EQ(joint2Elem->Get<std::string>("child"),
"other_prefix::main_model_prefix::subnested_model") <<
"Flattening logic for nested models failed for case C (check parser.cc)";
"Flattening logic for nested models failed (check parser.cc)";
}

0 comments on commit 4b97716

Please sign in to comment.