mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +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:
@@ -29,7 +29,7 @@ namespace BlackSimTest
|
|||||||
qDebug() << "loaded:" << s << "size:" << cvm.size();
|
qDebug() << "loaded:" << s << "size:" << cvm.size();
|
||||||
|
|
||||||
BlackMisc::Aviation::CAircraftIcao icao("C172");
|
BlackMisc::Aviation::CAircraftIcao icao("C172");
|
||||||
qDebug() << cvm.findByIcao(icao);
|
qDebug() << cvm.findByIcaoWildcard(icao);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,13 +62,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
CUserList CVatsimDataFileReader::getPilotsForCallsigns(const CCallsignList &callsigns)
|
CUserList CVatsimDataFileReader::getPilotsForCallsigns(const CCallsignList &callsigns)
|
||||||
{
|
{
|
||||||
CUserList users;
|
return this->m_aircrafts.findByCallsigns(callsigns).transform(Predicates::MemberTransform(&CAircraft::getPilot));
|
||||||
if (callsigns.isEmpty()) return users;
|
|
||||||
foreach(CCallsign callsign, callsigns)
|
|
||||||
{
|
|
||||||
users.push_back(this->getAircrafts().findByCallsign(callsign).getPilots());
|
|
||||||
}
|
|
||||||
return users;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserList CVatsimDataFileReader::getPilotsForCallsign(const CCallsign &callsign)
|
CUserList CVatsimDataFileReader::getPilotsForCallsign(const CCallsign &callsign)
|
||||||
@@ -100,13 +94,7 @@ namespace BlackCore
|
|||||||
|
|
||||||
CUserList CVatsimDataFileReader::getControllersForCallsigns(const CCallsignList &callsigns)
|
CUserList CVatsimDataFileReader::getControllersForCallsigns(const CCallsignList &callsigns)
|
||||||
{
|
{
|
||||||
CUserList users;
|
return this->m_atcStations.findByCallsigns(callsigns).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
||||||
if (callsigns.isEmpty()) return users;
|
|
||||||
foreach(CCallsign callsign, callsigns)
|
|
||||||
{
|
|
||||||
users.push_back(this->getAtcStations().findByCallsign(callsign).getControllers());
|
|
||||||
}
|
|
||||||
return users;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserList CVatsimDataFileReader::getUsersForCallsigns(const CCallsignList &callsigns)
|
CUserList CVatsimDataFileReader::getUsersForCallsigns(const CCallsignList &callsigns)
|
||||||
|
|||||||
@@ -27,13 +27,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CAudioDeviceList CAudioDeviceList::getOutputDevices() const
|
CAudioDeviceList CAudioDeviceList::getOutputDevices() const
|
||||||
{
|
{
|
||||||
CAudioDeviceList outList;
|
return this->findBy(&CAudioDevice::getType, CAudioDevice::OutputDevice);
|
||||||
if (this->isEmpty()) return outList;
|
|
||||||
foreach(CAudioDevice device, *this)
|
|
||||||
{
|
|
||||||
if (device.getType() == CAudioDevice::OutputDevice) outList.push_back(device);
|
|
||||||
}
|
|
||||||
return outList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -41,13 +35,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CAudioDeviceList CAudioDeviceList::getInputDevices() const
|
CAudioDeviceList CAudioDeviceList::getInputDevices() const
|
||||||
{
|
{
|
||||||
CAudioDeviceList inList;
|
return this->findBy(&CAudioDevice::getType, CAudioDevice::InputDevice);
|
||||||
if (this->isEmpty()) return inList;
|
|
||||||
foreach(CAudioDevice device, *this)
|
|
||||||
{
|
|
||||||
if (device.getType() == CAudioDevice::InputDevice) inList.push_back(device);
|
|
||||||
}
|
|
||||||
return inList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -47,14 +47,20 @@ namespace BlackMisc
|
|||||||
return this->findBy(&CAircraft::getCallsign, callsign);
|
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
|
* Find by callsign
|
||||||
*/
|
*/
|
||||||
CAircraft CAircraftList::findFirstByCallsign(const CCallsign &callsign, const CAircraft &ifNotFound) const
|
CAircraft CAircraftList::findFirstByCallsign(const CCallsign &callsign, const CAircraft &ifNotFound) const
|
||||||
{
|
{
|
||||||
CAircraftList aircrafts = this->findByCallsign(callsign);
|
return this->findByCallsign(callsign).frontOrDefault(ifNotFound);
|
||||||
if (aircrafts.isEmpty()) return ifNotFound;
|
|
||||||
return aircrafts.front();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -62,13 +68,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CUserList CAircraftList::getPilots() const
|
CUserList CAircraftList::getPilots() const
|
||||||
{
|
{
|
||||||
CUserList users;
|
return this->findBy(Predicates::MemberValid(&CAircraft::getPilot)).transform(Predicates::MemberTransform(&CAircraft::getPilot));
|
||||||
for (auto i = this->begin(); i != this->end(); ++i)
|
|
||||||
{
|
|
||||||
CAircraft aircraft = *i;
|
|
||||||
if (aircraft.getPilot().isValid()) users.push_back(aircraft.getPilot());
|
|
||||||
}
|
|
||||||
return users;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#define BLACKMISC_AIRCRAFTLIST_H
|
#define BLACKMISC_AIRCRAFTLIST_H
|
||||||
|
|
||||||
#include "avaircraft.h"
|
#include "avaircraft.h"
|
||||||
|
#include "avcallsignlist.h"
|
||||||
#include "nwuserlist.h"
|
#include "nwuserlist.h"
|
||||||
#include "collection.h"
|
#include "collection.h"
|
||||||
#include "sequence.h"
|
#include "sequence.h"
|
||||||
@@ -40,6 +41,9 @@ namespace BlackMisc
|
|||||||
//! Find 0..n stations by callsign
|
//! Find 0..n stations by callsign
|
||||||
CAircraftList findByCallsign(const CCallsign &callsign) const;
|
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
|
//! Find the first aircraft by callsign, if none return given one
|
||||||
CAircraft findFirstByCallsign(const CCallsign &callsign, const CAircraft &ifNotFound = CAircraft()) const;
|
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
|
CAirport CAirportList::findFirstByIcao(const CAirportIcao &icao, const CAirport &ifNotFound) const
|
||||||
{
|
{
|
||||||
CAirportList airports = this->findByIcao(icao);
|
return this->findByIcao(icao).frontOrDefault(ifNotFound);
|
||||||
if (!airports.isEmpty()) return airports[0];
|
|
||||||
return ifNotFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -46,14 +46,20 @@ namespace BlackMisc
|
|||||||
return this->findBy(&CAtcStation::getCallsign, callsign);
|
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
|
* Find first by callsign
|
||||||
*/
|
*/
|
||||||
CAtcStation CAtcStationList::findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound) const
|
CAtcStation CAtcStationList::findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound) const
|
||||||
{
|
{
|
||||||
CAtcStationList stations = findByCallsign(callsign);
|
return this->findByCallsign(callsign).frontOrDefault(ifNotFound);
|
||||||
if (!stations.isEmpty()) return stations[0];
|
|
||||||
return ifNotFound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -94,13 +100,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CUserList CAtcStationList::getControllers() const
|
CUserList CAtcStationList::getControllers() const
|
||||||
{
|
{
|
||||||
CUserList users;
|
return this->findBy(Predicates::MemberValid(&CAtcStation::getController)).transform(Predicates::MemberTransform(&CAtcStation::getController));
|
||||||
for (auto i = this->begin(); i != this->end(); ++i)
|
|
||||||
{
|
|
||||||
CAtcStation station = *i;
|
|
||||||
if (station.getController().isValid()) users.push_back(station.getController());
|
|
||||||
}
|
|
||||||
return users;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "nwuserlist.h"
|
#include "nwuserlist.h"
|
||||||
#include "avatcstation.h"
|
#include "avatcstation.h"
|
||||||
|
#include "avcallsignlist.h"
|
||||||
#include "collection.h"
|
#include "collection.h"
|
||||||
#include "sequence.h"
|
#include "sequence.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@@ -38,6 +39,9 @@ namespace BlackMisc
|
|||||||
//! Find 0..n stations by callsign
|
//! Find 0..n stations by callsign
|
||||||
CAtcStationList findByCallsign(const CCallsign &callsign) const;
|
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
|
//! Find first station by callsign, if not return given value / default
|
||||||
CAtcStation findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound = CAtcStation()) const;
|
CAtcStation findFirstByCallsign(const CCallsign &callsign, const CAtcStation &ifNotFound = CAtcStation()) const;
|
||||||
|
|
||||||
|
|||||||
@@ -35,11 +35,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CKeyboardKey CKeyboardKeyList::keyForFunction(CKeyboardKey::HotkeyFunction function) const
|
CKeyboardKey CKeyboardKeyList::keyForFunction(CKeyboardKey::HotkeyFunction function) const
|
||||||
{
|
{
|
||||||
CKeyboardKeyList keys = this->findBy(&CKeyboardKey::getFunction, function);
|
return this->findBy(&CKeyboardKey::getFunction, function).frontOrDefault({ CKeyboardKey::HotkeyNone });
|
||||||
if (keys.isEmpty())
|
|
||||||
return CKeyboardKey(CKeyboardKey::HotkeyNone);
|
|
||||||
else
|
|
||||||
return keys[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ namespace BlackMisc
|
|||||||
//! Matches model string?
|
//! Matches model string?
|
||||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
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
|
//! Register the metatypes
|
||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
|
|
||||||
|
|||||||
@@ -25,26 +25,25 @@ namespace BlackMisc
|
|||||||
CSequence<CAircraftMapping>(other)
|
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);
|
return this->findBy([ = ](const CAircraftMapping &mapping)
|
||||||
|
|
||||||
CAircraftMappingList result;
|
|
||||||
for (auto it = this->begin() ; it != this->end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (it->getIcao().matchesWildcardIcao(searchIcao)) result.push_back(*it);
|
return mapping.matchesWildcardIcao(searchIcao);
|
||||||
}
|
});
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
CAircraftMappingList CAircraftMappingList::findByIcaoCodeExact(const CAircraftIcao &searchIcao) const
|
||||||
|
{
|
||||||
|
return this->findBy(&CAircraftMapping::getIcao, searchIcao);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAircraftMappingList CAircraftMappingList::findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const
|
CAircraftMappingList CAircraftMappingList::findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const
|
||||||
{
|
{
|
||||||
CAircraftMappingList result;
|
return this->findBy([ = ](const CAircraftMapping &mapping)
|
||||||
for (auto it = this->begin() ; it != this->end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (it->matchesModelString(modelString, sensitivity)) result.push_back(*it);
|
return mapping.matchesModelString(modelString, sensitivity);
|
||||||
}
|
});
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ namespace BlackMisc
|
|||||||
//! QVariant, required for DBus QVariant lists
|
//! QVariant, required for DBus QVariant lists
|
||||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||||
|
|
||||||
//! Find by frequency
|
//! Find by ICAO code, empty fields treated as wildcards
|
||||||
CAircraftMappingList findByIcaoCode(const BlackMisc::Aviation::CAircraftIcao &searchIcao, bool emptyMeansWildcard = true) const;
|
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
|
//! Find by model string
|
||||||
CAircraftMappingList findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const;
|
CAircraftMappingList findByModelString(const QString modelString, Qt::CaseSensitivity sensitivity) const;
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CTextMessageList CTextMessageList::findByFrequency(const CFrequency &frequency) const
|
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 CStatusMessageList::findByType(CStatusMessage::StatusType type) const
|
||||||
{
|
{
|
||||||
CStatusMessageList sm;
|
return this->findBy(&CStatusMessage::getType, type);
|
||||||
foreach(CStatusMessage message, *this)
|
|
||||||
{
|
|
||||||
if (message.getType() == type)
|
|
||||||
{
|
|
||||||
sm.push_back(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -36,15 +28,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
CStatusMessageList CStatusMessageList::findBySeverity(CStatusMessage::StatusSeverity severity) const
|
CStatusMessageList CStatusMessageList::findBySeverity(CStatusMessage::StatusSeverity severity) const
|
||||||
{
|
{
|
||||||
CStatusMessageList sm;
|
return this->findBy(&CStatusMessage::getSeverity, severity);
|
||||||
foreach(CStatusMessage message, *this)
|
|
||||||
{
|
|
||||||
if (message.getSeverity() == severity)
|
|
||||||
{
|
|
||||||
sm.push_back(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -17,13 +17,7 @@ namespace BlackSim
|
|||||||
|
|
||||||
QStringList CSimulatorInfoList::toStringList(bool i18n) const
|
QStringList CSimulatorInfoList::toStringList(bool i18n) const
|
||||||
{
|
{
|
||||||
QStringList infoList;
|
return this->transform([i18n](const CSimulatorInfo &info) { return info.toQString(i18n); });
|
||||||
foreach(CSimulatorInfo info, (*this))
|
|
||||||
{
|
|
||||||
QString i = info.toQString(i18n);
|
|
||||||
infoList.append(i);
|
|
||||||
}
|
|
||||||
return infoList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorInfoList::registerMetadata()
|
void CSimulatorInfoList::registerMetadata()
|
||||||
|
|||||||
@@ -20,9 +20,14 @@ namespace BlackSim
|
|||||||
return this->m_mappings;
|
return this->m_mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlackMisc::Network::CAircraftMappingList ISimulatorModelMappings::findByIcao(const BlackMisc::Aviation::CAircraftIcao &icao, bool emptyMeansWildCard) const
|
BlackMisc::Network::CAircraftMappingList ISimulatorModelMappings::findByIcaoWildcard(const BlackMisc::Aviation::CAircraftIcao &icao) const
|
||||||
{
|
{
|
||||||
return this->m_mappings.findByIcaoCode(icao, emptyMeansWildCard);
|
return this->m_mappings.findByIcaoCodeWildcard(icao);
|
||||||
|
}
|
||||||
|
|
||||||
|
BlackMisc::Network::CAircraftMappingList ISimulatorModelMappings::findByIcaoExact(const BlackMisc::Aviation::CAircraftIcao &icao) const
|
||||||
|
{
|
||||||
|
return this->m_mappings.findByIcaoCodeExact(icao);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -37,8 +37,11 @@ namespace BlackSim
|
|||||||
//! Get list
|
//! Get list
|
||||||
const BlackMisc::Network::CAircraftMappingList &getMappingList() const;
|
const BlackMisc::Network::CAircraftMappingList &getMappingList() const;
|
||||||
|
|
||||||
//! Find by ICAO code
|
//! Find by ICAO code, empty fields are treated as wildcards
|
||||||
BlackMisc::Network::CAircraftMappingList findByIcao(const BlackMisc::Aviation::CAircraftIcao &icao, bool emptyMeansWildCard = true) const;
|
BlackMisc::Network::CAircraftMappingList findByIcaoWildcard(const BlackMisc::Aviation::CAircraftIcao &icao) const;
|
||||||
|
|
||||||
|
//! Find by ICAO code, empty fields are treated literally
|
||||||
|
BlackMisc::Network::CAircraftMappingList findByIcaoExact(const BlackMisc::Aviation::CAircraftIcao &icao) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BlackMisc::Network::CAircraftMappingList m_mappings; //!< Mappings
|
BlackMisc::Network::CAircraftMappingList m_mappings; //!< Mappings
|
||||||
|
|||||||
Reference in New Issue
Block a user