Skip to content

Commit ef84fa3

Browse files
committed
introduce abstraction storeState
analogous to storeSolution
1 parent dc8cd34 commit ef84fa3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

core/include/moveit/task_constructor/stage_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ class StagePrivate
144144
void spawn(InterfaceState&& state, const SolutionBasePtr& solution);
145145
void connect(const InterfaceState& from, const InterfaceState& to, const SolutionBasePtr& solution);
146146

147+
// store stage-owned data structures
147148
bool storeSolution(const SolutionBasePtr& solution, const InterfaceState* from, const InterfaceState* to);
149+
InterfaceState* storeState(InterfaceState&& state);
150+
148151
void newSolution(const SolutionBasePtr& solution);
149152
bool storeFailures() const { return introspection_ != nullptr; }
150153
void runCompute() {

core/src/container.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void ContainerBasePrivate::liftSolution(const SolutionBasePtr& solution, const I
212212
if (it != internalToExternalMap().end())
213213
return const_cast<InterfaceState*>(it->second);
214214

215-
InterfaceState* external = &*states_.insert(states_.end(), InterfaceState(*internal));
215+
InterfaceState* external = storeState(InterfaceState(*internal));
216216
internalToExternalMap().insert(std::make_pair(internal, external));
217217
created = true;
218218
return external;

core/src/stage.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ void StagePrivate::sendForward(const InterfaceState& from, InterfaceState&& to,
158158

159159
me()->forwardProperties(from, to);
160160

161-
auto to_it = states_.insert(states_.end(), std::move(to));
161+
InterfaceState* to_stored{ storeState(std::move(to)) };
162162

163163
// register stored interfaces with solution
164164
solution->setStartState(from);
165-
solution->setEndState(*to_it);
165+
solution->setEndState(*to_stored);
166166

167167
if (!solution->isFailure())
168-
nextStarts()->add(*to_it);
168+
nextStarts()->add(*to_stored);
169169

170170
newSolution(solution);
171171
}
@@ -180,13 +180,13 @@ void StagePrivate::sendBackward(InterfaceState&& from, const InterfaceState& to,
180180

181181
me()->forwardProperties(to, from);
182182

183-
auto from_it = states_.insert(states_.end(), std::move(from));
183+
InterfaceState* from_stored{ storeState(std::move(from)) };
184184

185-
solution->setStartState(*from_it);
185+
solution->setStartState(*from_stored);
186186
solution->setEndState(to);
187187

188188
if (!solution->isFailure())
189-
prevEnds()->add(*from_it);
189+
prevEnds()->add(*from_stored);
190190

191191
newSolution(solution);
192192
}
@@ -199,8 +199,8 @@ void StagePrivate::spawn(InterfaceState&& state, const SolutionBasePtr& solution
199199
if (!storeSolution(solution, nullptr, nullptr))
200200
return; // solution dropped
201201

202-
auto from = states_.insert(states_.end(), InterfaceState(state)); // copy
203-
auto to = states_.insert(states_.end(), std::move(state));
202+
InterfaceState* from{ storeState(InterfaceState{ state }) };
203+
InterfaceState* to{ storeState(std::move(state)) };
204204

205205
solution->setStartState(*from);
206206
solution->setEndState(*to);
@@ -275,6 +275,10 @@ void StagePrivate::computeCost(const InterfaceState& from, const InterfaceState&
275275
}
276276
}
277277

278+
InterfaceState* StagePrivate::storeState(InterfaceState&& state) {
279+
return &*states_.insert(states_.end(), std::move(state));
280+
}
281+
278282
Stage::Stage(StagePrivate* impl) : pimpl_(impl) {
279283
assert(impl);
280284
auto& p = properties();

0 commit comments

Comments
 (0)