From 38f7696acf2fb690e9b5fbaa753e9b5c44b4eafb Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Fri, 12 Jan 2018 13:42:45 +0100 Subject: [PATCH] ComputeBase::addTrajectory -> ComputeBasePrivate::addTrajectory Forbid indirect access to trajectories_. Only official compute classes have access. --- core/include/moveit/task_constructor/stage.h | 2 -- .../include/moveit/task_constructor/stage_p.h | 3 +++ core/src/stage.cpp | 22 +++++++++---------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core/include/moveit/task_constructor/stage.h b/core/include/moveit/task_constructor/stage.h index ef24a9ee..03f0484f 100644 --- a/core/include/moveit/task_constructor/stage.h +++ b/core/include/moveit/task_constructor/stage.h @@ -186,8 +186,6 @@ public: protected: /// ComputeBase can only be instantiated by derived classes in stage.cpp ComputeBase(ComputeBasePrivate* impl); - - SubTrajectory& addTrajectory(SubTrajectory&& trajectory); }; diff --git a/core/include/moveit/task_constructor/stage_p.h b/core/include/moveit/task_constructor/stage_p.h index c6c4e504..fbc65f3f 100644 --- a/core/include/moveit/task_constructor/stage_p.h +++ b/core/include/moveit/task_constructor/stage_p.h @@ -123,6 +123,9 @@ public: : StagePrivate(me, name) {} + // store trajectory in internal trajectories_ list + SubTrajectory& addTrajectory(SubTrajectory&& trajectory); + private: std::list trajectories_; }; diff --git a/core/src/stage.cpp b/core/src/stage.cpp index 402370af..c1973589 100644 --- a/core/src/stage.cpp +++ b/core/src/stage.cpp @@ -190,20 +190,18 @@ std::ostream& operator<<(std::ostream &os, const Stage& stage) { return os; } +SubTrajectory& ComputeBasePrivate::addTrajectory(SubTrajectory&& trajectory){ + trajectory.setCreator(this); + trajectories_.emplace_back(trajectory); + return trajectories_.back(); +} + ComputeBase::ComputeBase(ComputeBasePrivate *impl) : Stage(impl) { } -SubTrajectory& ComputeBase::addTrajectory(SubTrajectory&& trajectory){ - auto impl = pimpl(); - auto &trajs = impl->trajectories_; - trajectory.setCreator(impl); - trajs.emplace_back(trajectory); - return trajs.back(); -} - size_t ComputeBase::numSolutions() const { return pimpl()->trajectories_.size(); } @@ -384,7 +382,7 @@ void PropagatingEitherWay::sendForward(const InterfaceState& from, SubTrajectory&& t) { auto impl = pimpl(); std::cout << "sending state forward" << std::endl; - SubTrajectory &trajectory = addTrajectory(std::move(t)); + SubTrajectory &trajectory = impl->addTrajectory(std::move(t)); trajectory.setStartState(from); impl->nextStarts()->add(std::move(to), &trajectory, NULL); impl->newSolution(trajectory); @@ -395,7 +393,7 @@ void PropagatingEitherWay::sendBackward(InterfaceState&& from, SubTrajectory&& t) { auto impl = pimpl(); std::cout << "sending state backward" << std::endl; - SubTrajectory& trajectory = addTrajectory(std::move(t)); + SubTrajectory& trajectory = impl->addTrajectory(std::move(t)); trajectory.setEndState(to); impl->prevEnds()->add(std::move(from), NULL, &trajectory); impl->newSolution(trajectory); @@ -474,7 +472,7 @@ void Generator::spawn(InterfaceState&& state, SubTrajectory&& t) assert(!t.trajectory()); auto impl = pimpl(); - SubTrajectory& trajectory = addTrajectory(std::move(t)); + SubTrajectory& trajectory = impl->addTrajectory(std::move(t)); impl->prevEnds()->add(InterfaceState(state), NULL, &trajectory); impl->nextStarts()->add(std::move(state), &trajectory, NULL); impl->newSolution(trajectory); @@ -534,7 +532,7 @@ Connecting::Connecting(const std::string &name) void Connecting::connect(const InterfaceState& from, const InterfaceState& to, SubTrajectory&& t) { auto impl = pimpl(); - SubTrajectory& trajectory = addTrajectory(std::move(t)); + SubTrajectory& trajectory = impl->addTrajectory(std::move(t)); trajectory.setStartState(from); trajectory.setEndState(to); impl->newSolution(trajectory);