swift
Loading...
Searching...
No Matches
sampleschangeobject.cpp
Go to the documentation of this file.
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
6
8
9#include <QDateTime>
10#include <QtDebug>
11
16#include "misc/network/user.h"
17#include "misc/pq/frequency.h"
18#include "misc/pq/length.h"
19#include "misc/pq/units.h"
20#include "misc/predicates.h"
22#include "misc/variant.h"
23
24using namespace swift::misc;
25using namespace swift::misc::aviation;
26using namespace swift::misc::physical_quantities;
27using namespace swift::misc::geo;
28using namespace swift::misc::network;
29
30namespace swift::sample
31{
33 {
34 // ATC station
35 const CCoordinateGeodetic geoPos =
36 CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", { 1487, CLengthUnit::ft() });
37 const CAtcStation station1(CCallsign("eddm_twr"), CUser("123456", "Joe Doe"),
38 CFrequency(118.7, CFrequencyUnit::MHz()), geoPos, CLength(50, CLengthUnit::km()),
39 false);
40 const CAtcStation station2(station1);
41 const CAtcStation station3(CCallsign("eddm_app"), CUser("654321", "Jen Doe"),
42 CFrequency(120.7, CFrequencyUnit::MHz()), geoPos, CLength(100, CLengthUnit::km()),
43 false);
44
45 Q_ASSERT_X(station1 == station2, Q_FUNC_INFO, "Unequal stations");
46
47 // ATC List
48 CAtcStationList atcList;
49 atcList.push_back(station1);
50 atcList.push_back(station2);
51 atcList.push_back(station3);
52 atcList.push_back(station1);
53 atcList.push_back(station2);
54 atcList.push_back(station3);
55 qDebug() << "-- before update";
56 qDebug() << atcList.toQString();
57
58 // put Jane in the tower
59 CPropertyIndexVariantMap newController;
60 newController.addValue(CAtcStation::IndexController, CVariant::fromValue(CUser("112233", "Jane Doe")));
62 newController);
63 qDebug() << "-- after update via predicates";
64 qDebug() << atcList.toQString();
65
66 // now Jane's time is over
67 CPropertyIndexVariantMap anotherController;
68 anotherController.addValue(CAtcStation::IndexController, CVariant::fromValue(CUser("445566", "Fuzzy")));
69 atcList.applyIf([=](const auto &arg) { return newController.matches(arg); }, anotherController);
70
71 qDebug() << "-- after update via value map";
72 qDebug() << atcList.toQString();
73
74 qDebug() << "-----------------------------------------------";
75 return 0;
76 }
77} // namespace swift::sample
static CFrequencyUnit MHz()
Megahertz.
Definition units.h:380
Specialized value object compliant map for variants, based on indexes.
void addValue(const CPropertyIndex &index, const CVariant &value)
Add a value.
bool matches(const T &value) const
True if this map matches the value.
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
int applyIf(Predicate p, const VariantMap &newValues, bool skipEqualValues=false)
Modify by applying a value map to each element for which a given predicate returns true.
Definition sequence.h:420
static CVariant fromValue(T &&value)
Construct a variant from a value.
Definition variant.h:139
Value object encapsulating information about an ATC station.
Definition atcstation.h:38
const CCallsign & getCallsign() const
Get callsign.
Definition atcstation.h:84
Value object for a list of ATC stations.
Value object encapsulating information of a callsign.
Definition callsign.h:30
static CCoordinateGeodetic fromWgs84(const QString &latitudeWgs84, const QString &longitudeWgs84, const aviation::CAltitude &geodeticHeight={})
Coordinate by WGS84 position data.
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
Value object encapsulating information of a user.
Definition user.h:28
Physical unit length (length).
Definition length.h:18
static CLengthUnit km()
Kilometer km.
Definition units.h:165
static CLengthUnit ft()
Foot ft.
Definition units.h:157
static int samples()
Run the samples.
auto MemberEqual(Ts... vs)
Predicate which tests whether some member functions return some values.
Definition predicates.h:26
Free functions in swift::misc.