void-packages/srcpkgs/sumo/patches/0001-Rework-the-ComparatorI...

336 lines
17 KiB
Diff

From 59ee8a9c8bceb09fa4e90234e823d8004da7211f Mon Sep 17 00:00:00 2001
From: Max Schettler <schettle@mail.uni-paderborn.de>
Date: Tue, 29 May 2018 14:08:48 +0200
Subject: [PATCH] Rework the ComparatorIdLess
This makes it compile with current compilers (GCC >= 8, Clang >= 6).
Fixes #4110.
Signed-off-by: Max Schettler <schettle@mail.uni-paderborn.de>
---
src/jtrrouter/ROJTREdge.h | 2 +-
src/microsim/MSEdgeControl.cpp | 2 +-
src/microsim/MSEdgeControl.h | 2 +-
src/microsim/MSLane.cpp | 8 +++---
src/microsim/MSLane.h | 4 +--
src/microsim/MSLink.h | 4 +--
src/microsim/devices/MSDevice_Tripinfo.h | 2 +-
src/microsim/devices/MSDevice_Vehroutes.cpp | 2 +-
src/microsim/devices/MSDevice_Vehroutes.h | 2 +-
src/microsim/traffic_lights/MSRailSignal.cpp | 2 +-
src/netbuild/NBAlgorithms_Ramps.cpp | 8 +++---
src/netbuild/NBEdgeCont.cpp | 4 +--
src/netbuild/NBNodeCont.cpp | 4 +--
src/utils/common/Named.h | 28 +++++++-------------
src/utils/vehicle/SUMOVehicle.h | 3 ---
15 files changed, 33 insertions(+), 44 deletions(-)
diff --git src/jtrrouter/ROJTREdge.h src/jtrrouter/ROJTREdge.h
index dbaf9508bb..ec8a63759e 100644
--- src/jtrrouter/ROJTREdge.h
+++ src/jtrrouter/ROJTREdge.h
@@ -111,7 +111,7 @@ public:
private:
/// @brief Definition of a map that stores the probabilities of using a certain follower over time
- typedef std::map<ROJTREdge*, ValueTimeLine<double>*, Named::ComparatorIdLess> FollowerUsageCont;
+ typedef std::map<ROJTREdge*, ValueTimeLine<double>*, ComparatorIdLess> FollowerUsageCont;
/// @brief Storage for the probabilities of using a certain follower over time
FollowerUsageCont myFollowingDefs;
diff --git src/microsim/MSEdgeControl.cpp src/microsim/MSEdgeControl.cpp
index 34beb8cf96..b7eca6df46 100644
--- src/microsim/MSEdgeControl.cpp
+++ src/microsim/MSEdgeControl.cpp
@@ -77,7 +77,7 @@ MSEdgeControl::~MSEdgeControl() {
void
MSEdgeControl::patchActiveLanes() {
- for (std::set<MSLane*, Named::ComparatorIdLess>::iterator i = myChangedStateLanes.begin(); i != myChangedStateLanes.end(); ++i) {
+ for (std::set<MSLane*, ComparatorIdLess>::iterator i = myChangedStateLanes.begin(); i != myChangedStateLanes.end(); ++i) {
LaneUsage& lu = myLanes[(*i)->getNumericalID()];
// if the lane was inactive but is now...
if (!lu.amActive && (*i)->getVehicleNumber() > 0) {
diff --git src/microsim/MSEdgeControl.h src/microsim/MSEdgeControl.h
index 64536fe25b..aeb570bc27 100644
--- src/microsim/MSEdgeControl.h
+++ src/microsim/MSEdgeControl.h
@@ -220,7 +220,7 @@ private:
std::vector<MSLane*> myWithVehicles2Integrate;
/// @brief Lanes which changed the state without informing the control
- std::set<MSLane*, Named::ComparatorIdLess> myChangedStateLanes;
+ std::set<MSLane*, ComparatorIdLess> myChangedStateLanes;
/// @brief The list of active (not empty) lanes
std::vector<SUMOTime> myLastLaneChange;
diff --git src/microsim/MSLane.cpp src/microsim/MSLane.cpp
index 7edb512c0f..258152c83b 100644
--- src/microsim/MSLane.cpp
+++ src/microsim/MSLane.cpp
@@ -1172,7 +1172,7 @@ MSLane::detectCollisions(SUMOTime timestep, const std::string& stage) {
if (myVehicles.size() == 0 || myCollisionAction == COLLISION_ACTION_NONE) {
return;
}
- std::set<const MSVehicle*, SUMOVehicle::ComparatorIdLess> toRemove;
+ std::set<const MSVehicle*, ComparatorIdLess> toRemove;
std::set<const MSVehicle*> toTeleport;
if (MSGlobals::gLateralResolution <= 0 && MSGlobals::gLaneChangeDuration <= 0) {
// no sublanes
@@ -1304,7 +1304,7 @@ MSLane::detectCollisions(SUMOTime timestep, const std::string& stage) {
}
- for (std::set<const MSVehicle*, SUMOVehicle::ComparatorIdLess>::iterator it = toRemove.begin(); it != toRemove.end(); ++it) {
+ for (std::set<const MSVehicle*, ComparatorIdLess>::iterator it = toRemove.begin(); it != toRemove.end(); ++it) {
MSVehicle* veh = const_cast<MSVehicle*>(*it);
MSLane* vehLane = veh->getLane();
vehLane->removeVehicle(veh, MSMoveReminder::NOTIFICATION_TELEPORT, false);
@@ -1353,7 +1353,7 @@ MSLane::detectPedestrianJunctionCollision(const MSVehicle* collider, const Posit
bool
MSLane::detectCollisionBetween(SUMOTime timestep, const std::string& stage, MSVehicle* collider, MSVehicle* victim,
- std::set<const MSVehicle*, SUMOVehicle::ComparatorIdLess>& toRemove,
+ std::set<const MSVehicle*, ComparatorIdLess>& toRemove,
std::set<const MSVehicle*>& toTeleport) const {
#ifndef NO_TRACI
if (myCollisionAction == COLLISION_ACTION_TELEPORT && ((victim->hasInfluencer() && victim->getInfluencer().isRemoteAffected(timestep)) ||
@@ -1416,7 +1416,7 @@ MSLane::detectCollisionBetween(SUMOTime timestep, const std::string& stage, MSVe
void
MSLane::handleCollisionBetween(SUMOTime timestep, const std::string& stage, MSVehicle* collider, MSVehicle* victim,
- double gap, double latGap, std::set<const MSVehicle*, SUMOVehicle::ComparatorIdLess>& toRemove,
+ double gap, double latGap, std::set<const MSVehicle*, ComparatorIdLess>& toRemove,
std::set<const MSVehicle*>& toTeleport) const {
std::string prefix = "Vehicle '" + collider->getID() + "'; collision with vehicle '" + victim->getID() ;
if (myCollisionStopTime > 0) {
diff --git src/microsim/MSLane.h src/microsim/MSLane.h
index db97e5e93a..1eedbfddba 100644
--- src/microsim/MSLane.h
+++ src/microsim/MSLane.h
@@ -1098,13 +1098,13 @@ protected:
/// @brief detect whether there is a collision between the two vehicles
bool detectCollisionBetween(SUMOTime timestep, const std::string& stage, MSVehicle* collider, MSVehicle* victim,
- std::set<const MSVehicle*, SUMOVehicle::ComparatorIdLess>& toRemove,
+ std::set<const MSVehicle*, ComparatorIdLess>& toRemove,
std::set<const MSVehicle*>& toTeleport) const;
/// @brief take action upon collision
void handleCollisionBetween(SUMOTime timestep, const std::string& stage, MSVehicle* collider, MSVehicle* victim,
double gap, double latGap,
- std::set<const MSVehicle*, SUMOVehicle::ComparatorIdLess>& toRemove,
+ std::set<const MSVehicle*, ComparatorIdLess>& toRemove,
std::set<const MSVehicle*>& toTeleport) const;
/// @brief compute maximum braking distance on this lane
diff --git src/microsim/MSLink.h src/microsim/MSLink.h
index 97cf763f32..caeced9cd9 100644
--- src/microsim/MSLink.h
+++ src/microsim/MSLink.h
@@ -204,7 +204,7 @@ public:
ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
/// @brief return all approaching vehicles
- const std::map<const SUMOVehicle*, ApproachingVehicleInformation, SUMOVehicle::ComparatorIdLess>& getApproaching() const {
+ const std::map<const SUMOVehicle*, ApproachingVehicleInformation, ComparatorIdLess>& getApproaching() const {
return myApproachingVehicles;
}
@@ -529,7 +529,7 @@ private:
/// @brief The lane approaching this link
MSLane* myLaneBefore;
- std::map<const SUMOVehicle*, ApproachingVehicleInformation, SUMOVehicle::ComparatorIdLess> myApproachingVehicles;
+ std::map<const SUMOVehicle*, ApproachingVehicleInformation, ComparatorIdLess> myApproachingVehicles;
std::set<MSLink*> myBlockedFoeLinks;
/// @brief The position within this respond
diff --git src/microsim/devices/MSDevice_Tripinfo.h src/microsim/devices/MSDevice_Tripinfo.h
index fb72281c66..886c1148b0 100644
--- src/microsim/devices/MSDevice_Tripinfo.h
+++ src/microsim/devices/MSDevice_Tripinfo.h
@@ -228,7 +228,7 @@ private:
SUMOTime myMesoTimeLoss;
/// @brief devices which may still need to produce output
- typedef std::set<const MSDevice_Tripinfo*, Named::NamedLikeComparatorIdLess<MSDevice_Tripinfo> > DeviceSet;
+ typedef std::set<const MSDevice_Tripinfo*, ComparatorIdLess > DeviceSet;
static DeviceSet myPendingOutput;
diff --git src/microsim/devices/MSDevice_Vehroutes.cpp src/microsim/devices/MSDevice_Vehroutes.cpp
index a8d4901c85..43094b83c6 100644
--- src/microsim/devices/MSDevice_Vehroutes.cpp
+++ src/microsim/devices/MSDevice_Vehroutes.cpp
@@ -384,7 +384,7 @@ MSDevice_Vehroutes::addRoute() {
void
MSDevice_Vehroutes::generateOutputForUnfinished() {
- for (std::map<const SUMOVehicle*, MSDevice_Vehroutes*, Named::NamedLikeComparatorIdLess<SUMOVehicle> >::const_iterator it = myStateListener.myDevices.begin();
+ for (std::map<const SUMOVehicle*, MSDevice_Vehroutes*, ComparatorIdLess >::const_iterator it = myStateListener.myDevices.begin();
it != myStateListener.myDevices.end(); ++it) {
if (it->first->hasDeparted()) {
it->second->writeOutput(false);
diff --git src/microsim/devices/MSDevice_Vehroutes.h src/microsim/devices/MSDevice_Vehroutes.h
index 4586587c0a..8121a406fa 100644
--- src/microsim/devices/MSDevice_Vehroutes.h
+++ src/microsim/devices/MSDevice_Vehroutes.h
@@ -218,7 +218,7 @@ private:
void vehicleStateChanged(const SUMOVehicle* const vehicle, MSNet::VehicleState to);
/// @brief A map for internal notification
- std::map<const SUMOVehicle*, MSDevice_Vehroutes*, SUMOVehicle::ComparatorIdLess> myDevices;
+ std::map<const SUMOVehicle*, MSDevice_Vehroutes*, ComparatorIdLess> myDevices;
};
diff --git src/microsim/traffic_lights/MSRailSignal.cpp src/microsim/traffic_lights/MSRailSignal.cpp
index 4506fe6495..45db95fd14 100644
--- src/microsim/traffic_lights/MSRailSignal.cpp
+++ src/microsim/traffic_lights/MSRailSignal.cpp
@@ -215,7 +215,7 @@ MSRailSignal::getAppropriateState() {
std::map<const MSLane*, const MSLink*>::iterator it = mySucceedingBlocksIncommingLinks.find(lane);
if (it != mySucceedingBlocksIncommingLinks.end()) {
const MSLink* inCommingLing = it->second;
- const std::map<const SUMOVehicle*, MSLink::ApproachingVehicleInformation, SUMOVehicle::ComparatorIdLess> approaching = inCommingLing->getApproaching();
+ const std::map<const SUMOVehicle*, MSLink::ApproachingVehicleInformation, ComparatorIdLess> approaching = inCommingLing->getApproaching();
std::map<const SUMOVehicle*, MSLink::ApproachingVehicleInformation>::const_iterator apprIt = approaching.begin();
for (; apprIt != approaching.end(); apprIt++) {
MSLink::ApproachingVehicleInformation info = apprIt->second;
diff --git src/netbuild/NBAlgorithms_Ramps.cpp src/netbuild/NBAlgorithms_Ramps.cpp
index 38a0e23dc1..b6c6cae2bd 100644
--- src/netbuild/NBAlgorithms_Ramps.cpp
+++ src/netbuild/NBAlgorithms_Ramps.cpp
@@ -84,8 +84,8 @@ NBRampsComputer::computeRamps(NBNetBuilder& nb, OptionsCont& oc) {
NBDistrictCont& dc = nb.getDistrictCont();
// if an edge is part of two ramps, ordering is important
- std::set<NBNode*, Named::ComparatorIdLess> potOnRamps;
- std::set<NBNode*, Named::ComparatorIdLess> potOffRamps;
+ std::set<NBNode*, ComparatorIdLess> potOnRamps;
+ std::set<NBNode*, ComparatorIdLess> potOffRamps;
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
NBNode* cur = (*i).second;
if (mayNeedOnRamp(cur, minHighwaySpeed, maxRampSpeed, noramps)) {
@@ -95,10 +95,10 @@ NBRampsComputer::computeRamps(NBNetBuilder& nb, OptionsCont& oc) {
potOffRamps.insert(cur);
}
}
- for (std::set<NBNode*, Named::ComparatorIdLess>::const_iterator i = potOnRamps.begin(); i != potOnRamps.end(); ++i) {
+ for (std::set<NBNode*, ComparatorIdLess>::const_iterator i = potOnRamps.begin(); i != potOnRamps.end(); ++i) {
buildOnRamp(*i, nc, ec, dc, rampLength, dontSplit);
}
- for (std::set<NBNode*, Named::ComparatorIdLess>::const_iterator i = potOffRamps.begin(); i != potOffRamps.end(); ++i) {
+ for (std::set<NBNode*, ComparatorIdLess>::const_iterator i = potOffRamps.begin(); i != potOffRamps.end(); ++i) {
buildOffRamp(*i, nc, ec, dc, rampLength, dontSplit);
}
}
diff --git src/netbuild/NBEdgeCont.cpp src/netbuild/NBEdgeCont.cpp
index fb47bfeb30..67d97476fe 100644
--- src/netbuild/NBEdgeCont.cpp
+++ src/netbuild/NBEdgeCont.cpp
@@ -1167,7 +1167,7 @@ NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
avoid.insert(avoid.end(), reserve.begin(), reserve.end());
}
IDSupplier idSupplier("", avoid);
- std::set<NBEdge*, Named::ComparatorIdLess> toChange;
+ std::set<NBEdge*, ComparatorIdLess> toChange;
for (EdgeCont::iterator it = myEdges.begin(); it != myEdges.end(); it++) {
if (numericaIDs) {
try {
@@ -1181,7 +1181,7 @@ NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
}
}
const bool origNames = OptionsCont::getOptions().getBool("output.original-names");
- for (std::set<NBEdge*, Named::ComparatorIdLess>::iterator it = toChange.begin(); it != toChange.end(); ++it) {
+ for (std::set<NBEdge*, ComparatorIdLess>::iterator it = toChange.begin(); it != toChange.end(); ++it) {
NBEdge* edge = *it;
myEdges.erase(edge->getID());
if (origNames) {
diff --git src/netbuild/NBNodeCont.cpp src/netbuild/NBNodeCont.cpp
index b511e5a094..5768205f04 100644
--- src/netbuild/NBNodeCont.cpp
+++ src/netbuild/NBNodeCont.cpp
@@ -1306,7 +1306,7 @@ NBNodeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
avoid.insert(avoid.end(), reserve.begin(), reserve.end());
}
IDSupplier idSupplier("", avoid);
- std::set<NBNode*, Named::ComparatorIdLess> toChange;
+ std::set<NBNode*, ComparatorIdLess> toChange;
for (NodeCont::iterator it = myNodes.begin(); it != myNodes.end(); it++) {
if (numericaIDs) {
try {
@@ -1320,7 +1320,7 @@ NBNodeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
}
}
const bool origNames = OptionsCont::getOptions().getBool("output.original-names");
- for (std::set<NBNode*, Named::ComparatorIdLess>::iterator it = toChange.begin(); it != toChange.end(); ++it) {
+ for (std::set<NBNode*, ComparatorIdLess>::iterator it = toChange.begin(); it != toChange.end(); ++it) {
NBNode* node = *it;
myNodes.erase(node->getID());
if (origNames) {
diff --git src/utils/common/Named.h src/utils/common/Named.h
index c88d96700c..3b01bd1b9d 100644
--- src/utils/common/Named.h
+++ src/utils/common/Named.h
@@ -35,6 +35,16 @@
#include <set>
+/// @brief Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle)
+// @note Numbers of different lenghts will not be ordered by alphanumerical sorting
+struct ComparatorIdLess {
+ template<class T>
+ bool operator()(const T* const a, const T* const b) const {
+ return a->getID() < b->getID();
+ }
+};
+
+
// ===========================================================================
// class definitions
// ===========================================================================
@@ -75,24 +85,6 @@ public:
}
- /// @brief Function-object for stable sorting in containers
- // @note Numbers of different lengths will not be ordered by alphanumerical sorting
- struct ComparatorIdLess {
- bool operator()(Named* const a, Named* const b) const {
- return a->getID() < b->getID();
- }
- };
-
- /// @brief Function-object for stable sorting of objects acting like Named without being derived (SUMOVehicle)
- // @note Numbers of different lenghts will not be ordered by alphanumerical sorting
- template <class NamedLike>
- struct NamedLikeComparatorIdLess {
- bool operator()(const NamedLike* const a, const NamedLike* const b) const {
- return a->getID() < b->getID();
- }
- };
-
-
/** @class StoringVisitor
* @brief Allows to store the object; used as context while traveling the rtree in TraCI
*/
diff --git src/utils/vehicle/SUMOVehicle.h src/utils/vehicle/SUMOVehicle.h
index 8e7af4ae76..43c783c8b0 100644
--- src/utils/vehicle/SUMOVehicle.h
+++ src/utils/vehicle/SUMOVehicle.h
@@ -75,9 +75,6 @@ public:
*/
virtual double getPreviousSpeed() const = 0;
-
- typedef Named::NamedLikeComparatorIdLess<SUMOVehicle> ComparatorIdLess;
-
/// @brief Destructor
virtual ~SUMOVehicle() {}
--
2.18.0