swift
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 
7 #include "sampleschangeobject.h"
8 
9 #include <QDateTime>
10 #include <QtDebug>
11 
14 #include "misc/aviation/callsign.h"
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 
24 using namespace swift::misc;
25 using namespace swift::misc::aviation;
26 using namespace swift::misc::physical_quantities;
27 using namespace swift::misc::geo;
28 using namespace swift::misc::network;
29 
30 namespace swift::sample
31 {
32  int CSamplesChangeObject::samples()
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
Specialized value object compliant map for variants, based on indexes.
bool matches(const T &value) const
True if this map matches the value.
void addValue(const CPropertyIndex &index, const CVariant &value)
Add a value.
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
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:411
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
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
Value object encapsulating information of a user.
Definition: user.h:28
Physical unit length (length)
Definition: length.h:18
auto MemberEqual(Ts... vs)
Predicate which tests whether some member functions return some values.
Definition: predicates.h:26
Free functions in swift::misc.