avoid accidental overwrite of InterfaceState

This commit is contained in:
Robert Haschke 2018-02-19 08:18:31 +01:00
parent 373d7f204f
commit e368fd9948
3 changed files with 7 additions and 7 deletions

View File

@ -156,7 +156,7 @@ public:
container_type remove(iterator it); container_type remove(iterator it);
/// update state's priority if new priority is smaller and call notify_ /// update state's priority if new priority is smaller and call notify_
void updatePriority(InterfaceState &state, const InterfaceState::Priority &priority); void updatePriority(InterfaceState *state, const InterfaceState::Priority &priority);
private: private:
const NotifyFunction notify_; const NotifyFunction notify_;

View File

@ -246,12 +246,12 @@ void updateStateCosts(const SerialContainer::solution_container &partial_solutio
// here it suffices to update the start state, because the end state is the start state // here it suffices to update the start state, because the end state is the start state
// of the next solution (they are all connected) // of the next solution (they are all connected)
InterfaceState* state = const_cast<InterfaceState*>(solution->start()); InterfaceState* state = const_cast<InterfaceState*>(solution->start());
if (state->owner()) state->owner()->updatePriority(*state, prio); if (state->owner()) state->owner()->updatePriority(state, prio);
} }
// finally update the end state of the last solution // finally update the end state of the last solution
if (partial_solution_path.empty()) return; if (partial_solution_path.empty()) return;
InterfaceState* state = const_cast<InterfaceState*>(partial_solution_path.back()->end()); InterfaceState* state = const_cast<InterfaceState*>(partial_solution_path.back()->end());
if (state->owner()) state->owner()->updatePriority(*state, prio); if (state->owner()) state->owner()->updatePriority(state, prio);
} }
void SerialContainer::onNewSolution(const SolutionBase &current) void SerialContainer::onNewSolution(const SolutionBase &current)

View File

@ -104,13 +104,13 @@ Interface::container_type Interface::remove(iterator it)
return result; return result;
} }
void Interface::updatePriority(InterfaceState &state, const InterfaceState::Priority& priority) void Interface::updatePriority(InterfaceState *state, const InterfaceState::Priority& priority)
{ {
if (priority < state.priority()) { if (priority < state->priority()) {
auto it = std::find_if(begin(), end(), [&state](const InterfaceState& other) { return &state == &other; }); auto it = std::find_if(begin(), end(), [state](const InterfaceState& other) { return state == &other; });
// state should be part of the interface // state should be part of the interface
assert(it != end()); assert(it != end());
state.priority_ = priority; state->priority_ = priority;
if (notify_) notify_(it, true); if (notify_) notify_(it, true);
} }
} }