From d91e66721b8079d3541069cc4d280cb2e73ee1b3 Mon Sep 17 00:00:00 2001 From: Michael Behrisch Date: Tue, 16 Jan 2024 10:07:04 +0100 Subject: [PATCH] refactoring stage function #12 --- src/libsumo/Person.cpp | 4 ++-- src/microsim/output/MSDetectorFileOutput.cpp | 2 +- src/microsim/transportables/MSTransportable.h | 17 +++++------------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/libsumo/Person.cpp b/src/libsumo/Person.cpp index 0384845e728e..0577d5324d00 100644 --- a/src/libsumo/Person.cpp +++ b/src/libsumo/Person.cpp @@ -242,7 +242,7 @@ Person::getEdges(const std::string& personID, int nextStageIndex) { throw TraCIException("The negative stage index must refer to a valid previous stage."); } std::vector edgeIDs; - for (auto& e : p->getEdges(nextStageIndex)) { + for (auto& e : p->getNextStage(nextStageIndex)->getEdges()) { if (e != nullptr) { edgeIDs.push_back(e->getID()); } @@ -788,7 +788,7 @@ Person::rerouteTraveltime(const std::string& personID) { if (newEdges.empty()) { throw TraCIException("Could not find new route for person '" + personID + "'."); } - ConstMSEdgeVector oldEdges = p->getEdges(firstIndex); + ConstMSEdgeVector oldEdges = p->getNextStage(firstIndex)->getEdges(); assert(!oldEdges.empty()); if (oldEdges.front()->getFunction() != SumoXMLEdgeFunc::NORMAL) { oldEdges.erase(oldEdges.begin()); diff --git a/src/microsim/output/MSDetectorFileOutput.cpp b/src/microsim/output/MSDetectorFileOutput.cpp index 4e3f6ad59583..bb55a65084c5 100644 --- a/src/microsim/output/MSDetectorFileOutput.cpp +++ b/src/microsim/output/MSDetectorFileOutput.cpp @@ -84,7 +84,7 @@ MSDetectorFileOutput::vehicleApplies(const SUMOTrafficObject& veh) const { end = v.getRoute().end(); } else if (veh.isPerson()) { const MSTransportable& p = dynamic_cast(veh); - route = p.getEdges(0); + route = p.getCurrentStage()->getEdges(); it = route.begin() + p.getRoutePosition(); end = route.end(); } diff --git a/src/microsim/transportables/MSTransportable.h b/src/microsim/transportables/MSTransportable.h index 2be2ee42f5c5..4c23226a8511 100644 --- a/src/microsim/transportables/MSTransportable.h +++ b/src/microsim/transportables/MSTransportable.h @@ -233,18 +233,11 @@ class MSTransportable : public SUMOTrafficObject { return *myStep; } - /// @brief Return the current stage - MSStage* getNextStage(int next) const { - assert(myStep + next >= myPlan->begin()); - assert(myStep + next < myPlan->end()); - return *(myStep + next); - } - - /// @brief Return the edges of the nth next stage - ConstMSEdgeVector getEdges(int next) const { - assert(myStep + next < myPlan->end()); - assert(myStep + next >= myPlan->begin()); - return (*(myStep + next))->getEdges(); + /// @brief Return the next (or previous) stage denoted by the offset + inline MSStage* getNextStage(int offset) const { + assert(myStep + offset >= myPlan->begin()); + assert(myStep + offset < myPlan->end()); + return *(myStep + offset); } /// @brief returns the numerical IDs of edges to be used (possibly of future stages)