mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #290 using a CRange of iterator adaptors in implementating the tertiary predicate-based methods of the derived containers,
but preserving the return-by-copy for API stability
This commit is contained in:
@@ -27,13 +27,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CAudioDeviceList CAudioDeviceList::getOutputDevices() const
|
||||
{
|
||||
CAudioDeviceList outList;
|
||||
if (this->isEmpty()) return outList;
|
||||
foreach(CAudioDevice device, *this)
|
||||
{
|
||||
if (device.getType() == CAudioDevice::OutputDevice) outList.push_back(device);
|
||||
}
|
||||
return outList;
|
||||
return this->findBy(&CAudioDevice::getType, CAudioDevice::OutputDevice);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -41,13 +35,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CAudioDeviceList CAudioDeviceList::getInputDevices() const
|
||||
{
|
||||
CAudioDeviceList inList;
|
||||
if (this->isEmpty()) return inList;
|
||||
foreach(CAudioDevice device, *this)
|
||||
{
|
||||
if (device.getType() == CAudioDevice::InputDevice) inList.push_back(device);
|
||||
}
|
||||
return inList;
|
||||
return this->findBy(&CAudioDevice::getType, CAudioDevice::InputDevice);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -47,14 +47,20 @@ namespace BlackMisc
|
||||
return this->findBy(&CAircraft::getCallsign, callsign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find by callsigns
|
||||
*/
|
||||
CAircraftList CAircraftList::findByCallsigns(const CCallsignList &callsigns) const
|
||||
{
|
||||
return this->findBy(Predicates::MemberIsAnyOf(&CAircraft::getCallsign, callsigns));
|
||||
}
|
||||
|
||||
/*
|
||||
* Find by callsign
|
||||
*/
|
||||
CAircraft CAircraftList::findFirstByCallsign(const CCallsign &callsign, const CAircraft &ifNotFound) const
|
||||
{
|
||||
CAircraftList aircrafts = this->findByCallsign(callsign);
|
||||
if (aircrafts.isEmpty()) return ifNotFound;
|
||||
return aircrafts.front();
|
||||
return this->findByCallsign(callsign).frontOrDefault(ifNotFound);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -62,13 +68,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CUserList CAircraftList::getPilots() const
|
||||
{
|
||||
CUserList users;
|
||||
for (auto i = this->begin(); i != this->end(); ++i)
|
||||
{
|
||||
CAircraft aircraft = *i;
|
||||
if (aircraft.getPilot().isValid()) users.push_back(aircraft.getPilot());
|
||||
}
|
||||
return users;
|
||||
return this->findBy(Predicates::MemberValid(&CAircraft::getPilot)).transform(Predicates::MemberTransform(&CAircraft::getPilot));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define BLACKMISC_AIRCRAFTLIST_H
|
||||
|
||||
#include "avaircraft.h"
|
||||
#include "avcallsignlist.h"
|
||||
#include "nwuserlist.h"
|
||||
#include "collection.h"
|
||||
#include "sequence.h"
|
||||
@@ -40,6 +41,9 @@ namespace BlackMisc
|
||||
//! Find 0..n stations by callsign
|
||||
CAircraftList findByCallsign(const CCallsign &callsign) const;
|
||||
|
||||
//! Find 0..n aircraft matching any of a set of callsigns
|
||||
CAircraftList findByCallsigns(const CCallsignList &callsigns) const;
|
||||
|
||||
//! Find the first aircraft by callsign, if none return given one
|
||||
CAircraft findFirstByCallsign(const CCallsign &callsign, const CAircraft &ifNotFound = CAircraft()) const;
|
||||
|
||||
|
||||
@@ -56,9 +56,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CAirport CAirportList::findFirstByIcao(const CAirportIcao &icao, const CAirport &ifNotFound) const
|
||||
{
|
||||
CAirportList airports = this->findByIcao(icao);
|
||||
if (!airports.isEmpty()) return airports[0];
|
||||
return ifNotFound;
|
||||
return this->findByIcao(icao).frontOrDefault(ifNotFound);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -46,14 +46,20 @@ namespace BlackMisc
|
||||
return this->findBy(&CAtcStation::getCallsign, callsign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find by callsigns
|
||||
*/
|
||||
CAtcStationList CAtcStationList::findByCallsigns(const CCallsignList &callsigns) const
|
||||
{
|
||||
return this->findBy(Predicates::MemberIsAnyOf(&CAtcStation::getCallsign, callsigns));
|
||||
}
|
||||
|
||||
/*
|
||||
* Find first by callsign
|
||||
*/
|
||||
CAtcStation CAtcStationList::findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound) const
|
||||
{
|
||||
CAtcStationList stations = findByCallsign(callsign);
|
||||
if (!stations.isEmpty()) return stations[0];
|
||||
return ifNotFound;
|
||||
return this->findByCallsign(callsign).frontOrDefault(ifNotFound);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -94,13 +100,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CUserList CAtcStationList::getControllers() const
|
||||
{
|
||||
CUserList users;
|
||||
for (auto i = this->begin(); i != this->end(); ++i)
|
||||
{
|
||||
CAtcStation station = *i;
|
||||
if (station.getController().isValid()) users.push_back(station.getController());
|
||||
}
|
||||
return users;
|
||||
return this->findBy(Predicates::MemberValid(&CAtcStation::getController)).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "nwuserlist.h"
|
||||
#include "avatcstation.h"
|
||||
#include "avcallsignlist.h"
|
||||
#include "collection.h"
|
||||
#include "sequence.h"
|
||||
#include <QObject>
|
||||
@@ -38,6 +39,9 @@ namespace BlackMisc
|
||||
//! Find 0..n stations by callsign
|
||||
CAtcStationList findByCallsign(const CCallsign &callsign) const;
|
||||
|
||||
//! Find 0..n stations matching any of a set of callsigns
|
||||
CAtcStationList findByCallsigns(const CCallsignList &callsigns) const;
|
||||
|
||||
//! Find first station by callsign, if not return given value / default
|
||||
CAtcStation findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound = CAtcStation()) const;
|
||||
|
||||
|
||||
@@ -35,11 +35,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CKeyboardKey CKeyboardKeyList::keyForFunction(CKeyboardKey::HotkeyFunction function) const
|
||||
{
|
||||
CKeyboardKeyList keys = this->findBy(&CKeyboardKey::getFunction, function);
|
||||
if (keys.isEmpty())
|
||||
return CKeyboardKey(CKeyboardKey::HotkeyNone);
|
||||
else
|
||||
return keys[0];
|
||||
return this->findBy(&CKeyboardKey::getFunction, function).frontOrDefault({ CKeyboardKey::HotkeyNone });
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -93,6 +93,9 @@ namespace BlackMisc
|
||||
//! Matches model string?
|
||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
|
||||
//! Matches wildcard icao object
|
||||
bool matchesWildcardIcao(const BlackMisc::Aviation::CAircraftIcao &otherIcao) const { return m_icao.matchesWildcardIcao(otherIcao); }
|
||||
|
||||
//! Register the metatypes
|
||||
static void registerMetadata();
|
||||
|
||||
|
||||
@@ -25,26 +25,25 @@ namespace BlackMisc
|
||||
CSequence<CAircraftMapping>(other)
|
||||
{ }
|
||||
|
||||
CAircraftMappingList CAircraftMappingList::findByIcaoCode(const CAircraftIcao &searchIcao, bool emptyMeansWildcard) const
|
||||
CAircraftMappingList CAircraftMappingList::findByIcaoCodeWildcard(const CAircraftIcao &searchIcao) const
|
||||
{
|
||||
if (!emptyMeansWildcard) return this->findBy(&CAircraftMapping::getIcao, searchIcao);
|
||||
|
||||
CAircraftMappingList result;
|
||||
for (auto it = this->begin() ; it != this->end(); ++it)
|
||||
return this->findBy([ = ](const CAircraftMapping &mapping)
|
||||
{
|
||||
if (it->getIcao().matchesWildcardIcao(searchIcao)) result.push_back(*it);
|
||||
}
|
||||
return result;
|
||||
return mapping.matchesWildcardIcao(searchIcao);
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftMappingList CAircraftMappingList::findByIcaoCodeExact(const CAircraftIcao &searchIcao) const
|
||||
{
|
||||
return this->findBy(&CAircraftMapping::getIcao, searchIcao);
|
||||
}
|
||||
|
||||
CAircraftMappingList CAircraftMappingList::findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const
|
||||
{
|
||||
CAircraftMappingList result;
|
||||
for (auto it = this->begin() ; it != this->end(); ++it)
|
||||
return this->findBy([ = ](const CAircraftMapping &mapping)
|
||||
{
|
||||
if (it->matchesModelString(modelString, sensitivity)) result.push_back(*it);
|
||||
}
|
||||
return result;
|
||||
return mapping.matchesModelString(modelString, sensitivity);
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -36,8 +36,11 @@ namespace BlackMisc
|
||||
//! QVariant, required for DBus QVariant lists
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
//! Find by frequency
|
||||
CAircraftMappingList findByIcaoCode(const BlackMisc::Aviation::CAircraftIcao &searchIcao, bool emptyMeansWildcard = true) const;
|
||||
//! Find by ICAO code, empty fields treated as wildcards
|
||||
CAircraftMappingList findByIcaoCodeWildcard(const BlackMisc::Aviation::CAircraftIcao &searchIcao) const;
|
||||
|
||||
//! Find by ICAO code, empty fields treated literally
|
||||
CAircraftMappingList findByIcaoCodeExact(const BlackMisc::Aviation::CAircraftIcao &searchIcao) const;
|
||||
|
||||
//! Find by model string
|
||||
CAircraftMappingList findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CTextMessageList CTextMessageList::findByFrequency(const CFrequency &frequency) const
|
||||
{
|
||||
return CTextMessageList(this->findBy(&CTextMessage::getFrequency, frequency));
|
||||
return this->findBy(&CTextMessage::getFrequency, frequency);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -20,15 +20,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CStatusMessageList CStatusMessageList::findByType(CStatusMessage::StatusType type) const
|
||||
{
|
||||
CStatusMessageList sm;
|
||||
foreach(CStatusMessage message, *this)
|
||||
{
|
||||
if (message.getType() == type)
|
||||
{
|
||||
sm.push_back(message);
|
||||
}
|
||||
}
|
||||
return sm;
|
||||
return this->findBy(&CStatusMessage::getType, type);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -36,15 +28,7 @@ namespace BlackMisc
|
||||
*/
|
||||
CStatusMessageList CStatusMessageList::findBySeverity(CStatusMessage::StatusSeverity severity) const
|
||||
{
|
||||
CStatusMessageList sm;
|
||||
foreach(CStatusMessage message, *this)
|
||||
{
|
||||
if (message.getSeverity() == severity)
|
||||
{
|
||||
sm.push_back(message);
|
||||
}
|
||||
}
|
||||
return sm;
|
||||
return this->findBy(&CStatusMessage::getSeverity, severity);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user