Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
Cleanup for erase vector/list statements
  • Loading branch information
albar965 committed Dec 22, 2024
1 parent 8b7d80f commit 95a1c2f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 80 deletions.
9 changes: 2 additions & 7 deletions src/fs/bgl/ap/airport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,9 @@ void Airport::updateHelipads()

void Airport::removeVehicleParking()
{
QList<Parking>::iterator it = std::remove_if(parkings.begin(), parkings.end(),
[](const Parking& p) -> bool
{
parkings.erase(std::remove_if(parkings.begin(), parkings.end(), [](const Parking& p) -> bool {
return p.getType() == atools::fs::bgl::ap::VEHICLES;
});

if(it != parkings.end())
parkings.erase(it, parkings.end());
}), parkings.end());
}

void Airport::updateTaxiPaths(const QList<TaxiPoint>& taxipoints, const QStringList& taxinames)
Expand Down
14 changes: 4 additions & 10 deletions src/fs/db/airwayresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,9 @@ void AirwayResolver::buildAirway(const QString& airwayName, QSet<AirwaySegment>&
void AirwayResolver::cleanFragments(QVector<Fragment>& fragments)
{
// Erase empty segments
auto it = std::remove_if(fragments.begin(), fragments.end(), [](const Fragment& f) -> bool
{
fragments.erase(std::remove_if(fragments.begin(), fragments.end(), [](const Fragment& f) -> bool {
return f.waypoints.size() < 2;
});
if(it != fragments.end())
fragments.erase(it, fragments.end());
}), fragments.end());

// Erase all segments that are contained by another
for(int i = 0; i < fragments.size(); i++)
Expand All @@ -412,12 +409,9 @@ void AirwayResolver::cleanFragments(QVector<Fragment>& fragments)
}

// Remove the marked segments
auto it2 = std::remove_if(fragments.begin(), fragments.end(), [](const Fragment& f) -> bool
{
fragments.erase(std::remove_if(fragments.begin(), fragments.end(), [](const Fragment& f) -> bool {
return f.waypoints.isEmpty();
});
if(it2 != fragments.end())
fragments.erase(it2, fragments.end());
}), fragments.end());
}

} // namespace writer
Expand Down
25 changes: 9 additions & 16 deletions src/fs/db/nav/airwaysegmentwriter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel [email protected]
* Copyright 2015-2024 Alexander Barthel [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,13 +16,12 @@
*****************************************************************************/

#include "fs/db/nav/airwaysegmentwriter.h"
#include "fs/db/meta/bglfilewriter.h"
#include "fs/db/datawriter.h"

#include "atools.h"
#include "fs/bgl/nav/airwaywaypoint.h"
#include "fs/bgl/util.h"
#include "fs/db/nav/waypointwriter.h"
#include "fs/db/datawriter.h"
#include "geo/calculations.h"
#include "atools.h"

namespace atools {
namespace fs {
Expand All @@ -39,22 +38,18 @@ void AirwaySegmentWriter::writeObject(const AirwaySegment *type)

bind(":mid_ident", type->getMidWaypoint().getIdent());
bind(":mid_region", type->getMidWaypoint().getRegion());
bind(":mid_type", bgl::util::enumToStr(bgl::AirwayWaypoint::airwayWaypointTypeToStr,
type->getMidWaypoint().getType()));
bind(":mid_type", bgl::util::enumToStr(bgl::AirwayWaypoint::airwayWaypointTypeToStr, type->getMidWaypoint().getType()));

if(type->hasNextWaypoint())
{
using namespace atools::geo;
using namespace atools;

bind(":next_type",
bgl::util::enumToStr(bgl::AirwayWaypoint::airwayWaypointTypeToStr,
type->getNextWaypoint().getType()));
bind(":next_type", bgl::util::enumToStr(bgl::AirwayWaypoint::airwayWaypointTypeToStr, type->getNextWaypoint().getType()));
bind(":next_ident", type->getNextWaypoint().getIdent());
bind(":next_region", type->getNextWaypoint().getRegion());
bind(":next_airport_ident", type->getNextWaypoint().getAirportIdent());
bind(":next_minimum_altitude",
roundToPrecision(meterToFeet(type->getNextWaypoint().getMinimumAltitude()), 1));
bind(":next_minimum_altitude", roundToPrecision(meterToFeet(type->getNextWaypoint().getMinimumAltitude()), 1));
}
else
{
Expand All @@ -70,13 +65,11 @@ void AirwaySegmentWriter::writeObject(const AirwaySegment *type)
using namespace atools::geo;

bind(":previous_type",
bgl::util::enumToStr(bgl::AirwayWaypoint::airwayWaypointTypeToStr,
type->getPreviousWaypoint().getType()));
bgl::util::enumToStr(bgl::AirwayWaypoint::airwayWaypointTypeToStr, type->getPreviousWaypoint().getType()));
bind(":previous_ident", type->getPreviousWaypoint().getIdent());
bind(":previous_region", type->getPreviousWaypoint().getRegion());
bind(":previous_airport_ident", type->getPreviousWaypoint().getAirportIdent());
bind(":previous_minimum_altitude",
roundToPrecision(meterToFeet(type->getPreviousWaypoint().getMinimumAltitude()), 1));
bind(":previous_minimum_altitude", roundToPrecision(meterToFeet(type->getPreviousWaypoint().getMinimumAltitude()), 1));
}
else
{
Expand Down
36 changes: 12 additions & 24 deletions src/fs/sc/datareaderthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void DataReaderThread::debugWriteWhazzup(const atools::fs::sc::SimConnectData& d
// ac.setCoordinates(pos);
}

// // Move N8
//// Move N8
// if(reg.startsWith("N8"))
// {
// atools::geo::Pos pos = ac.getPosition();
Expand Down Expand Up @@ -349,36 +349,24 @@ void DataReaderThread::run()
// Remove boat and ship traffic depending on settings for testing purposes
QVector<SimConnectAircraft>& aiAircraft = data.getAiAircraft();
if(!(opts & atools::fs::sc::FETCH_AI_AIRCRAFT))
{
QVector<SimConnectAircraft>::iterator it =
std::remove_if(aiAircraft.begin(), aiAircraft.end(), [] (const SimConnectAircraft &aircraft)->bool
{
return !aircraft.isUser() && !aircraft.isAnyBoat();
});
if(it != aiAircraft.end())
aiAircraft.erase(it, aiAircraft.end());
}
aiAircraft.erase(std::remove_if(aiAircraft.begin(), aiAircraft.end(), [] (const SimConnectAircraft& aircraft)->bool {
return !aircraft.isUser() && !aircraft.isAnyBoat();
}), aiAircraft.end());

if(!(opts & atools::fs::sc::FETCH_AI_BOAT))
{
QVector<SimConnectAircraft>::iterator it =
std::remove_if(aiAircraft.begin(), aiAircraft.end(), [] (const SimConnectAircraft &aircraft)->bool
{
return !aircraft.isUser() && aircraft.isAnyBoat();
});
if(it != aiAircraft.end())
aiAircraft.erase(it, aiAircraft.end());
}
aiAircraft.erase(std::remove_if(aiAircraft.begin(), aiAircraft.end(), [] (const SimConnectAircraft& aircraft)->bool {
return !aircraft.isUser() && aircraft.isAnyBoat();
}), aiAircraft.end());

if(!replayWhazzupFile.isEmpty())
debugWriteWhazzup(data);

#ifdef DEBUG_CREATE_WHAZZUP_TEST_FILTER

data.getAiAircraft().erase(std::remove_if(data.getAiAircraft().begin(), data.getAiAircraft().end(),
[] (const SimConnectAircraft &type)->bool {
return type.getAirplaneRegistration() != "N2092Z";
}), data.getAiAircraft().end());
[] (const SimConnectAircraft& type)->bool {
return type.getAirplaneRegistration() != "N2092Z";
}), data.getAiAircraft().end());
#endif

emit postSimConnectData(data);
Expand Down Expand Up @@ -472,9 +460,9 @@ void DataReaderThread::run()
closeReplay();

if(failedTerminally)
terminate = true; // Drop dead
terminate = true; // Drop dead
else
terminate = false; // Allow restart
terminate = false; // Allow restart

connected = false;
reconnecting = false;
Expand Down
3 changes: 1 addition & 2 deletions src/fs/userdata/airspacereaderopenair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ void AirspaceReaderOpenAir::writeBoundary()
insertAirspaceQuery->bindValue(":file_id", fileId);

// Remove all remaining invalid points
auto it = std::remove_if(curLine.begin(), curLine.end(), [](const Pos& p) -> bool
{
auto it = std::remove_if(curLine.begin(), curLine.end(), [](const Pos& p) -> bool {
return !p.isValidRange();
});

Expand Down
9 changes: 2 additions & 7 deletions src/geo/linestring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,9 @@ void LineString::setAltitude(float alt)

void LineString::removeInvalid()
{
auto it = std::remove_if(begin(), end(),
[](const Pos& pos) -> bool
{
erase(std::remove_if(begin(), end(), [](const Pos& pos) -> bool {
return !pos.isValid();
});

if(it != end())
erase(it, end());
}), end());
}

void LineString::removeDuplicates(float epsilon)
Expand Down
6 changes: 2 additions & 4 deletions src/gui/dockwidgethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,9 @@ void DockWidgetHandler::updateDockTabStatus(QDockWidget *dockWidget)

if(it == dockStackList.end())
{
auto rmIt = std::remove_if(tabified.begin(), tabified.end(), [](QDockWidget *dock) -> bool {
tabified.erase(std::remove_if(tabified.begin(), tabified.end(), [](QDockWidget *dock) -> bool {
return dock->isFloating();
});
if(rmIt != tabified.end())
tabified.erase(rmIt, tabified.end());
}), tabified.end());

if(!tabified.isEmpty())
{
Expand Down
13 changes: 3 additions & 10 deletions src/track/trackreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ int TrackReader::removeInvalid()

int TrackReader::removeInvalid(TrackVectorType& trackVector)
{
auto it = std::remove_if(trackVector.begin(), trackVector.end(), [](const Track& track) -> bool
{
auto it = std::remove_if(trackVector.begin(), trackVector.end(), [](const Track& track) -> bool {
bool valid = track.isFullyValid();
if(!valid)
qWarning() << "TrackReader: Invalid track " << track;
Expand Down Expand Up @@ -325,15 +324,9 @@ void TrackReader::extractTracks(const QStringList& lines, const QRegularExpressi

// Remove elements without waypoints =======================================
if(removeEmpty)
{
atools::track::TrackVectorType::iterator it = std::remove_if(temp.begin(), temp.end(), [](const Track& t) -> bool
{
temp.erase(std::remove_if(temp.begin(), temp.end(), [](const Track& t) -> bool {
return t.route.isEmpty();
});

if(it != temp.end())
temp.erase(it, temp.end());
}
}), temp.end());

tracks.append(temp);
}
Expand Down

0 comments on commit 95a1c2f

Please sign in to comment.