From fdbdbfe93d2f41d9c88d03f5c98c1a2de2eade3e Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 8 Jan 2012 19:31:07 +0000 Subject: [PATCH] When clearing the route, skip generated waypoints. --- src/Autopilot/route_mgr.cxx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Autopilot/route_mgr.cxx b/src/Autopilot/route_mgr.cxx index 178b7cfa2..f236884f9 100644 --- a/src/Autopilot/route_mgr.cxx +++ b/src/Autopilot/route_mgr.cxx @@ -539,9 +539,22 @@ flightgear::WayptRef FGRouteMgr::removeWayptAtIndex(int aIndex) return w; } +struct NotGeneratedWayptPredicate : public std::unary_function +{ + bool operator() (const Waypt* w) const + { + return (w->flag(WPT_GENERATED) == false); + } +}; + + void FGRouteMgr::clearRoute() { - _route.clear(); +// erase all non-generated waypoints + WayptVec::iterator r = + std::remove_if(_route.begin(), _route.end(), NotGeneratedWayptPredicate()); + _route.erase(r, _route.end()); + _currentIndex = -1; update_mirror(); @@ -1135,15 +1148,7 @@ void FGRouteMgr::initAtPosition() bool FGRouteMgr::haveUserWaypoints() const { - for (int i = 0; i < numWaypts(); i++) { - if (!_route[i]->flag(WPT_GENERATED)) { - // have a non-generated waypoint, we're done - return true; - } - } - - // all waypoints are generated - return false; + return std::find_if(_route.begin(), _route.end(), NotGeneratedWayptPredicate()) != _route.end(); } bool FGRouteMgr::activate()