mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 04:25:42 +08:00
Use nested namespaces (C++17 feature)
This commit is contained in:
@@ -16,127 +16,124 @@
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
namespace BlackMisc::Aviation
|
||||
{
|
||||
namespace Aviation
|
||||
CAirportList::CAirportList() { }
|
||||
|
||||
CAirportList::CAirportList(const CSequence<CAirport> &other) :
|
||||
CSequence<CAirport>(other)
|
||||
{ }
|
||||
|
||||
CAirportList CAirportList::findByIcao(const CAirportIcaoCode &icao) const
|
||||
{
|
||||
CAirportList::CAirportList() { }
|
||||
return this->findBy(&CAirport::getIcao, icao);
|
||||
}
|
||||
|
||||
CAirportList::CAirportList(const CSequence<CAirport> &other) :
|
||||
CSequence<CAirport>(other)
|
||||
{ }
|
||||
bool CAirportList::containsAirportWithIcaoCode(const CAirportIcaoCode &icao) const
|
||||
{
|
||||
if (icao.isEmpty()) { return false; }
|
||||
return this->contains(&CAirport::getIcao, icao);
|
||||
}
|
||||
|
||||
CAirportList CAirportList::findByIcao(const CAirportIcaoCode &icao) const
|
||||
void CAirportList::replaceOrAddByIcao(const CAirport &addedOrReplacedAirport)
|
||||
{
|
||||
if (!addedOrReplacedAirport.hasValidIcaoCode()) return; // ignore invalid airport
|
||||
this->replaceOrAdd(&CAirport::getIcao, addedOrReplacedAirport.getIcao(), addedOrReplacedAirport);
|
||||
}
|
||||
|
||||
void CAirportList::updateMissingParts(const CAirportList &updateFromList)
|
||||
{
|
||||
if (updateFromList.isEmpty()) { return; }
|
||||
for (CAirport &airport : *this)
|
||||
{
|
||||
return this->findBy(&CAirport::getIcao, icao);
|
||||
}
|
||||
|
||||
bool CAirportList::containsAirportWithIcaoCode(const CAirportIcaoCode &icao) const
|
||||
{
|
||||
if (icao.isEmpty()) { return false; }
|
||||
return this->contains(&CAirport::getIcao, icao);
|
||||
}
|
||||
|
||||
void CAirportList::replaceOrAddByIcao(const CAirport &addedOrReplacedAirport)
|
||||
{
|
||||
if (!addedOrReplacedAirport.hasValidIcaoCode()) return; // ignore invalid airport
|
||||
this->replaceOrAdd(&CAirport::getIcao, addedOrReplacedAirport.getIcao(), addedOrReplacedAirport);
|
||||
}
|
||||
|
||||
void CAirportList::updateMissingParts(const CAirportList &updateFromList)
|
||||
{
|
||||
if (updateFromList.isEmpty()) { return; }
|
||||
for (CAirport &airport : *this)
|
||||
const CAirport fromAirport = updateFromList.findFirstByIcao(airport.getIcao());
|
||||
if (fromAirport.hasValidIcaoCode())
|
||||
{
|
||||
const CAirport fromAirport = updateFromList.findFirstByIcao(airport.getIcao());
|
||||
if (fromAirport.hasValidIcaoCode())
|
||||
{
|
||||
airport.updateMissingParts(fromAirport);
|
||||
}
|
||||
airport.updateMissingParts(fromAirport);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CAirport CAirportList::findFirstByIcao(const CAirportIcaoCode &icao, const CAirport &ifNotFound) const
|
||||
CAirport CAirportList::findFirstByIcao(const CAirportIcaoCode &icao, const CAirport &ifNotFound) const
|
||||
{
|
||||
return this->findFirstByOrDefault(&CAirport::getIcao, icao, ifNotFound);
|
||||
}
|
||||
|
||||
CAirport CAirportList::findFirstByNameOrLocation(const QString &nameOrLocation, const CAirport &ifNotFound) const
|
||||
{
|
||||
if (this->isEmpty() || nameOrLocation.isEmpty()) { return ifNotFound; }
|
||||
CAirportList airports = this->findBy([&](const CAirport & airport)
|
||||
{
|
||||
return this->findFirstByOrDefault(&CAirport::getIcao, icao, ifNotFound);
|
||||
return airport.matchesDescriptiveName(nameOrLocation);
|
||||
});
|
||||
if (!airports.isEmpty()) { return airports.frontOrDefault(); }
|
||||
|
||||
airports = this->findBy([&](const CAirport & airport)
|
||||
{
|
||||
return airport.matchesLocation(nameOrLocation);
|
||||
});
|
||||
if (!airports.isEmpty()) { return airports.frontOrDefault(); }
|
||||
return ifNotFound;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allIcaoCodes(bool sorted) const
|
||||
{
|
||||
QStringList icaos;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getIcaoAsString().isEmpty()) { continue; }
|
||||
icaos.push_back(airport.getIcaoAsString());
|
||||
}
|
||||
if (sorted) { icaos.sort(); }
|
||||
return icaos;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allDescriptivesNames(bool sorted) const
|
||||
{
|
||||
QStringList names;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getDescriptiveName().isEmpty()) { continue; }
|
||||
names.push_back(airport.getDescriptiveName());
|
||||
}
|
||||
if (sorted) { names.sort(); }
|
||||
return names;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allLocations() const
|
||||
{
|
||||
CSetBuilder<QString> locations;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getLocation().isEmpty()) { continue; }
|
||||
locations.insert(airport.getLocation());
|
||||
}
|
||||
|
||||
CAirport CAirportList::findFirstByNameOrLocation(const QString &nameOrLocation, const CAirport &ifNotFound) const
|
||||
return locations;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allLocationsPlusOptionalDescription(bool sorted) const
|
||||
{
|
||||
QStringList locations;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (this->isEmpty() || nameOrLocation.isEmpty()) { return ifNotFound; }
|
||||
CAirportList airports = this->findBy([&](const CAirport & airport)
|
||||
{
|
||||
return airport.matchesDescriptiveName(nameOrLocation);
|
||||
});
|
||||
if (!airports.isEmpty()) { return airports.frontOrDefault(); }
|
||||
|
||||
airports = this->findBy([&](const CAirport & airport)
|
||||
{
|
||||
return airport.matchesLocation(nameOrLocation);
|
||||
});
|
||||
if (!airports.isEmpty()) { return airports.frontOrDefault(); }
|
||||
return ifNotFound;
|
||||
const QString l = airport.getLocationPlusOptionalName();
|
||||
if (l.isEmpty()) { continue; }
|
||||
locations.push_back(l);
|
||||
}
|
||||
if (sorted) { locations.sort(); }
|
||||
return locations;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allIcaoCodes(bool sorted) const
|
||||
CAirportList CAirportList::fromDatabaseJson(const QJsonArray &array, CAirportList *inconsistent)
|
||||
{
|
||||
CAirportList airports;
|
||||
Q_UNUSED(inconsistent); // not yet implemented, but signature already prepared
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
QStringList icaos;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getIcaoAsString().isEmpty()) { continue; }
|
||||
icaos.push_back(airport.getIcaoAsString());
|
||||
}
|
||||
if (sorted) { icaos.sort(); }
|
||||
return icaos;
|
||||
const CAirport airport(CAirport::fromDatabaseJson(value.toObject()));
|
||||
airports.push_back(airport);
|
||||
}
|
||||
|
||||
QStringList CAirportList::allDescriptivesNames(bool sorted) const
|
||||
{
|
||||
QStringList names;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getDescriptiveName().isEmpty()) { continue; }
|
||||
names.push_back(airport.getDescriptiveName());
|
||||
}
|
||||
if (sorted) { names.sort(); }
|
||||
return names;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allLocations() const
|
||||
{
|
||||
CSetBuilder<QString> locations;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
if (airport.getLocation().isEmpty()) { continue; }
|
||||
locations.insert(airport.getLocation());
|
||||
}
|
||||
|
||||
return locations;
|
||||
}
|
||||
|
||||
QStringList CAirportList::allLocationsPlusOptionalDescription(bool sorted) const
|
||||
{
|
||||
QStringList locations;
|
||||
for (const CAirport &airport : *this)
|
||||
{
|
||||
const QString l = airport.getLocationPlusOptionalName();
|
||||
if (l.isEmpty()) { continue; }
|
||||
locations.push_back(l);
|
||||
}
|
||||
if (sorted) { locations.sort(); }
|
||||
return locations;
|
||||
}
|
||||
|
||||
CAirportList CAirportList::fromDatabaseJson(const QJsonArray &array, CAirportList *inconsistent)
|
||||
{
|
||||
CAirportList airports;
|
||||
Q_UNUSED(inconsistent); // not yet implemented, but signature already prepared
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
const CAirport airport(CAirport::fromDatabaseJson(value.toObject()));
|
||||
airports.push_back(airport);
|
||||
}
|
||||
return airports;
|
||||
}
|
||||
} // namespace
|
||||
return airports;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user