Skip to content

Commit b346e7e

Browse files
authored
Task: findChild() and operator[] should directly operate on stages() (#435)
Considering the (fixed) name of the top-level container is meaningless.
1 parent f07b81f commit b346e7e

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

core/include/moveit/task_constructor/task.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class Task : protected WrapperBase
8585
const std::string& name() const { return stages()->name(); }
8686
void setName(const std::string& name) { stages()->setName(name); }
8787

88+
Stage* findChild(const std::string& name) const { return stages()->findChild(name); }
89+
Stage* operator[](int index) const { return stages()->operator[](index); }
90+
8891
const moveit::core::RobotModelConstPtr& getRobotModel() const;
8992
/// setting the robot model also resets the task
9093
void setRobotModel(const moveit::core::RobotModelConstPtr& robot_model);

core/test/test_container.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,27 @@ TEST(ContainerBase, positionForInsert) {
7979

8080
/* TODO: remove interface as it returns raw pointers */
8181
TEST(ContainerBase, findChild) {
82-
SerialContainer s;
82+
auto s = std::make_unique<SerialContainer>();
8383
Stage *a, *b, *c1, *d;
84-
s.add(Stage::pointer(a = new NamedStage("a")));
85-
s.add(Stage::pointer(b = new NamedStage("b")));
86-
s.add(Stage::pointer(c1 = new NamedStage("c")));
84+
s->add(Stage::pointer(a = new NamedStage("a")));
85+
s->add(Stage::pointer(b = new NamedStage("b")));
86+
s->add(Stage::pointer(c1 = new NamedStage("c")));
8787
auto sub = ContainerBase::pointer(new SerialContainer("c"));
8888
sub->add(Stage::pointer(d = new NamedStage("d")));
89-
s.add(std::move(sub));
90-
91-
EXPECT_EQ(s.findChild("a"), a);
92-
EXPECT_EQ(s.findChild("b"), b);
93-
EXPECT_EQ(s.findChild("c"), c1);
94-
EXPECT_EQ(s.findChild("d"), nullptr);
95-
EXPECT_EQ(s.findChild("c/d"), d);
89+
s->add(std::move(sub));
90+
91+
EXPECT_EQ(s->findChild("a"), a);
92+
EXPECT_EQ(s->findChild("b"), b);
93+
EXPECT_EQ(s->findChild("c"), c1);
94+
EXPECT_EQ(s->findChild("d"), nullptr);
95+
EXPECT_EQ(s->findChild("c/d"), d);
96+
97+
Task t("", false, std::move(s));
98+
EXPECT_EQ(t.findChild("a"), a);
99+
EXPECT_EQ(t.findChild("b"), b);
100+
EXPECT_EQ(t.findChild("c"), c1);
101+
EXPECT_EQ(t.findChild("d"), nullptr);
102+
EXPECT_EQ(t.findChild("c/d"), d);
96103
}
97104

98105
template <typename Container>

0 commit comments

Comments
 (0)