swift
Loading...
Searching...
No Matches
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
18#include "misc/network/user.h"
19#include "misc/pq/frequency.h"
20#include "misc/pq/length.h"
21#include "misc/pq/units.h"
24#include "misc/range.h"
25#include "misc/stringutils.h"
26#include "misc/test/testdata.h"
27#include "misc/variant.h"
28
29using namespace swift::misc;
30using namespace swift::misc::aviation;
31using namespace swift::misc::physical_quantities;
32using namespace swift::misc::geo;
33using namespace swift::misc::network;
34using namespace swift::misc::test;
35
36namespace swift::sample
37{
39 {
40 // ATC stations
41 const CAtcStation station1(CTestData::getMunichTower());
42 CAtcStation station2(station1);
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
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::fromValue(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
static CFrequencyUnit MHz()
Megahertz.
Definition units.h:380
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:621
CSequence findBy(Predicate p) const
Return a copy containing only those elements for which a given predicate returns true.
Definition sequence.h:407
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
void clear()
Removes all elements in the sequence.
Definition sequence.h:288
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 physical_quantities::CFrequency & getFrequency() const
Get frequency.
Definition atcstation.h:135
const CCallsign & getCallsign() const
Get callsign.
Definition atcstation.h:84
QString getControllerRealName() const
Get controller name.
Definition atcstation.h:108
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:74
static const swift::misc::aviation::CAtcStation & getMunichApproach()
Munich approach.
static const swift::misc::aviation::CAtcStation & getMunichTower()
Munich tower.
static int samples()
Run the samples.
Generate data for testing purposes.
Definition testdata.h:45
Free functions in swift::misc.