Skip to content

Commit c046ec6

Browse files
committed
streamline add/insert interfaces for Task/Container
`add` falls back to `insert` for both structures, but `add` throws exceptions and does not provide a return value. `insert` provides standard STL container access.
1 parent df8a783 commit c046ec6

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

core/include/moveit/task_constructor/container.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class ContainerBase : public Stage
6262
/// traverse all children of this container recursively
6363
bool traverseRecursively(const StageCallback& processor) const;
6464

65+
void add(Stage::pointer&& stage);
66+
6567
virtual bool insert(Stage::pointer&& stage, int before = -1);
6668
virtual bool remove(int pos);
6769
virtual bool remove(Stage* child);

core/include/moveit/task_constructor/task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class Task : protected WrapperBase
9292
/// load robot model from given parameter
9393
void loadRobotModel(const std::string& robot_description = "robot_description");
9494

95-
// TODO: use Stage::insert as well?
9695
void add(Stage::pointer&& stage);
96+
bool insert(Stage::pointer&& stage, int before = -1);
9797
void clear() final;
9898

9999
/// enable introspection publishing for use with rviz

core/src/container.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,18 @@ bool ContainerBase::traverseRecursively(const ContainerBase::StageCallback& proc
194194
return pimpl()->traverseStages(processor, 1, UINT_MAX);
195195
}
196196

197+
void ContainerBase::add(Stage::pointer&& stage) {
198+
if (!insert(std::move(stage))) {
199+
throw std::runtime_error(name() + ": Could not insert stage");
200+
}
201+
}
202+
197203
bool ContainerBase::insert(Stage::pointer&& stage, int before) {
204+
if (!stage) {
205+
ROS_ERROR_STREAM(name() << ": reveived invalid stage pointer");
206+
return false;
207+
}
208+
198209
StagePrivate* impl = stage->pimpl();
199210
if (!impl->setParent(this))
200211
return false;

core/src/task.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@ void Task::loadRobotModel(const std::string& robot_description) {
194194
}
195195

196196
void Task::add(Stage::pointer&& stage) {
197-
if (!stage)
198-
throw std::runtime_error("stage insertion failed: invalid stage pointer");
197+
stages()->add(std::move(stage));
198+
}
199199

200-
if (!stages()->insert(std::move(stage)))
201-
throw std::runtime_error(std::string("insertion failed for stage: ") + stage->name());
200+
bool Task::insert(Stage::pointer&& stage, int before) {
201+
return stages()->insert(std::move(stage), before);
202202
}
203203

204204
void Task::clear() {

0 commit comments

Comments
 (0)