swift
Loading...
Searching...
No Matches
atcstationlist.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QString>
7#include <QtGlobal>
8
12#include "misc/predicates.h"
13#include "misc/range.h"
14
15using namespace swift::misc::physical_quantities;
16using namespace swift::misc::network;
17
18SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc::aviation, CAtcStation, CAtcStationList)
19
20namespace swift::misc::aviation
21{
23
25 {
26 return this->findBy(
27 [&](const CAtcStation &atcStation) { return atcStation.isComUnitTunedToFrequency(comUnit); });
28 }
29
31 {
32 return this->containsBy(
33 [&](const CAtcStation &atcStation) { return atcStation.isComUnitTunedToFrequency(comUnit); });
34 }
35
37 {
38 if (frequency.isNull())
39 {
40 return {};
41 }
42 return this->findBy([&](const CAtcStation &atcStation) { return atcStation.isAtcStationFrequency(frequency); });
43 }
44
46 bool overrideWithNewer)
47 {
49
50 // for loop just to get reference
51 bool unequal = false;
52 for (CAtcStation &station : *this)
53 {
54 if (station.getCallsign() != callsign)
55 {
56 continue;
57 }
58
59 const CInformationMessage m = station.getInformationMessage(type);
60 if (m.getType() == CInformationMessage::Unspecified)
61 {
62 break;
63 }
64
65 if (m.getMessage() == im.getMessage())
66 {
67 if (!overrideWithNewer)
68 {
69 break;
70 }
71 if (!im.isNewerThan(m))
72 {
73 break;
74 }
75 }
76 else
77 {
78 unequal = true;
79 }
80 station.setMessage(im);
81 break; // only count unequals
82 }
83 return unequal;
84 }
85
86 int CAtcStationList::setOnline(const CCallsign &callsign, bool online)
87 {
88 int c = 0;
89 for (CAtcStation &station : *this)
90 {
91 if (station.getCallsign() != callsign)
92 {
93 continue;
94 }
95 if (station.setOnline(online))
96 {
97 c++;
98 }
99 }
100 return c;
101 }
102
107
113
115
117 {
118 if (this->isEmpty())
119 {
120 return {};
121 }
122 CAtcStationList copy(*this);
124 return copy;
125 }
126
131
133 {
134 CAtcStationList stations = *this;
136 return stations;
137 }
138
140 {
141 if (this->isEmpty())
142 {
143 return {};
144 }
145 const CAtcStationList stations = sort ? this->sortedByAtcSuffixSortOrderAndDistance() : *this;
146
147 QString suffix;
149 for (const CAtcStation &s : stations)
150 {
151 const QString currentSuffix = s.getCallsignSuffix();
152 if (suffix != currentSuffix)
153 {
154 suffix = currentSuffix;
155 split[currentSuffix] = CAtcStationList();
156 }
157 split[currentSuffix].push_back(s);
158 }
159 return split;
160 }
161} // namespace swift::misc::aviation
auto transform(F function) const
Return a new container generated by applying some transformation function to all elements of this one...
Definition range.h:415
void sortBy(K1 key1, Keys... keys)
Definition sequence.h:603
CSequence findBy(Predicate p) const
Definition sequence.h:407
bool isNewerThan(const ITimestampBased &otherTimestampObj) const
Is this newer than other?
Value object encapsulating information about an ATC station.
Definition atcstation.h:38
bool hasValidFrequency() const
Valid COM frequency.
Definition atcstation.h:132
bool isComUnitTunedToFrequency(const aviation::CComSystem &comUnit) const
Is Com unit tuned to this stations frequency.
const CInformationMessage & getInformationMessage(CInformationMessage::InformationType type) const
Message per type.
bool setOnline(bool online)
Set online.
const CCallsign & getCallsign() const
Get callsign.
Definition atcstation.h:84
bool isAtcStationFrequency(const physical_quantities::CFrequency &frequency) const
Is passed frequency the frequency of this station.
bool setMessage(const CInformationMessage &message)
Set given message.
int getSuffixSortOrder() const
Callsign suffix sort order.
const swift::misc::network::CUser & getController() const
Get controller.
Definition atcstation.h:105
bool isInRange() const
In range? If range and distance to own aircraft are not available false.
int removeIfOutsideRange()
Remove if marked outside of range.
CSequence()=default
Default constructor.
QHash< QString, CAtcStationList > splitPerSuffix(bool sort=true) const
Split per suffix.
CAtcStationList stationsWithValidFrequency() const
Find 0..n stations with valid COM frequency.
bool hasComUnitTunedInChannelSpacing(const CComSystem &comUnit) const
Any stations tuned in frequency of COM unit (with channel spacing).
CAtcStationList sortedByAtcSuffixSortOrderAndDistance() const
Sorted by ATC suffix sort order and distance.
int setOnline(const CCallsign &callsign, bool online)
Set online status.
void sortByAtcSuffixSortOrderAndDistance()
Sort by ATC suffix sort order and distance.
CAtcStationList findIfFrequencyIsWithinSpacing(const physical_quantities::CFrequency &frequency)
Find 0..n stations with frequency (with 5 kHz spacing for .x20/.x25 and .x70/.x75).
CAtcStationList()=default
Default constructor.
CAtcStationList findIfComUnitTunedInChannelSpacing(const CComSystem &comUnit) const
Find 0..n stations tuned in frequency of COM unit (with channel spacing).
network::CUserList getControllers() const
All controllers (with valid data).
bool updateIfMessageChanged(const CInformationMessage &im, const CCallsign &callsign, bool overrideWithNewer)
Update if message changed.
CAtcStationList findInRange() const
Those in range.
Value object encapsulating information of a callsign.
Definition callsign.h:30
COM system (aka "radio").
Definition comsystem.h:37
Value object encapsulating information message (ATIS, METAR, TAF).
const QString & getMessage() const
Get message.
const physical_quantities::CLength & getRelativeDistance() const
Get the distance.
Value object encapsulating a list of voice rooms.
Definition userlist.h:26
auto MemberTransform(T memberFunc)
Returns a function object that returns the value returned by one of it's argument member functions.
Definition predicates.h:54
auto MemberValid(T memberFunc)
Returns a predicate that returns true if the isValid() method of the value returned from one of its m...
Definition predicates.h:64
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition sequence.h:63