swift
samplescontainer.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 "samplescontainer.h"
8 
9 #include <QDateTime>
10 #include <QDebug>
11 #include <QtDebug>
12 
15 #include "misc/aviation/callsign.h"
18 #include "misc/network/user.h"
19 #include "misc/pq/frequency.h"
20 #include "misc/pq/length.h"
21 #include "misc/pq/units.h"
22 #include "misc/propertyindexlist.h"
24 #include "misc/range.h"
25 #include "misc/stringutils.h"
26 #include "misc/test/testdata.h"
27 #include "misc/variant.h"
28 
29 using namespace swift::misc;
30 using namespace swift::misc::aviation;
31 using namespace swift::misc::physical_quantities;
32 using namespace swift::misc::geo;
33 using namespace swift::misc::network;
34 using namespace swift::misc::test;
35 
36 namespace swift::sample
37 {
38  int CSamplesContainer::samples()
39  {
40  // ATC stations
41  const CAtcStation station1(CTestData::getMunichTower());
42  CAtcStation station2(station1);
43  CAtcStation station3(CTestData::getMunichApproach());
44 
45  // ATC List
46  CAtcStationList atcList;
47  atcList.push_back(station1);
48  atcList.push_back(station2);
49  atcList.push_back(station3);
50  atcList.push_back(station1);
51  atcList.push_back(station2);
52  atcList.push_back(station3);
53  qDebug() << "-- list:";
54  qDebug() << atcList.toQString();
55 
56  CAtcStationList atcListFind = atcList.findBy(&CAtcStation::getCallsign, "eddm_twr", &CAtcStation::getFrequency,
57  CFrequency(118.7, CFrequencyUnit::MHz()));
58  qDebug() << "-- find by:";
59  qDebug() << atcListFind.toQString();
60 
62  qDebug() << "-- sort by:";
63  qDebug() << atcListSort.toQString();
64 
65  qDebug() << "-----------------------------------------------";
66 
67  // Apply if tests
68  atcList.clear();
69  atcList.push_back(station1);
70  CAtcStation station1Cpy(station1);
71  CFrequency changedFrequency(118.25, CFrequencyUnit::MHz());
72  CPropertyIndexVariantMap vm(CAtcStation::IndexFrequency, CVariant::from(changedFrequency));
73 
74  // demonstration apply
75  CPropertyIndexList changedProperties;
76  changedProperties = station1Cpy.apply(vm, true);
77  qDebug() << "apply, changed" << changedProperties << vm << "expected 1";
78  changedProperties = station1Cpy.apply(vm, true);
79  qDebug() << "apply, changed" << changedProperties << vm << "expected 0";
80 
81  // applyIf
82  int changed;
83  changed = atcList.applyIf(&CAtcStation::getCallsign, CTestData::getMunichTower().getCallsign(), vm);
84  qDebug() << "applyIf, changed" << changed << vm << "expected 1";
85  changed = atcList.applyIf(&CAtcStation::getCallsign, CTestData::getMunichTower().getCallsign(), vm);
86  qDebug() << "applyIf, changed" << changed << vm << "expected 1";
87  changed = atcList.applyIf(&CAtcStation::getCallsign, CTestData::getMunichTower().getCallsign(), vm, true);
88  qDebug() << "applyIf, changed" << changed << vm << "expected 0";
89 
90  return 0;
91  }
92 } // namespace swift::sample
Value object encapsulating a list of property indexes.
Specialized value object compliant map for variants, based on indexes.
CSequence sortedBy(K1 key1, Keys... keys) const
Return a copy sorted by some particular key(s).
Definition: sequence.h:594
CSequence findBy(Predicate p) const
Return a copy containing only those elements for which a given predicate returns true.
Definition: sequence.h:398
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
void clear()
Removes all elements in the sequence.
Definition: sequence.h:288
static CVariant from(T &&value)
Synonym for fromValue().
Definition: variant.h:147
Value object encapsulating information about an ATC station.
Definition: atcstation.h:38
const CCallsign & getCallsign() const
Get callsign.
Definition: atcstation.h:84
QString getControllerRealName() const
Get controller name.
Definition: atcstation.h:108
const physical_quantities::CFrequency & getFrequency() const
Get frequency.
Definition: atcstation.h:135
Value object for a list of ATC stations.
CPropertyIndexList apply(const CPropertyIndexVariantMap &indexMap, bool skipEqualValues=false)
Update by variant map.
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
Generate data for testing purposes.
Definition: testdata.h:45
Free functions in swift::misc.