swift
Loading...
Searching...
No Matches
ssrequipment.cpp
1// SPDX-FileCopyrightText: Copyright (C) swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
4#include "ssrequipment.h"
5
6SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::aviation, CSsrEquipment)
7
8namespace swift::misc::aviation
9{
10 CSsrEquipment::CSsrEquipment(SSrEquipment equipment) : m_equipment(equipment)
11 {
12 if (m_equipment == SSrEquipment())
13 {
14 m_equipment = None;
15 }
16 }
17
19 {
20
21 if (equipment.isEmpty())
22 {
23 return;
24 }
25
26 m_equipment = {}; // Clear default flag
27
28 auto append_equipment_flag_if_exist = [&equipment, this](SsrEquipmentOption flag) {
29 QString str = flagToString(flag);
30 if (equipment.contains(str))
31 {
32 equipment = equipment.remove(str);
33 m_equipment |= flag;
34 }
35 };
36
37 append_equipment_flag_if_exist(None);
38 append_equipment_flag_if_exist(ModeA);
39 append_equipment_flag_if_exist(ModeAC);
40 append_equipment_flag_if_exist(ModeSTypeE);
41 append_equipment_flag_if_exist(ModeSTypeH);
42 append_equipment_flag_if_exist(ModeSTypeI);
43 append_equipment_flag_if_exist(ModeSTypeL);
44 append_equipment_flag_if_exist(ModeSTypeX);
45 append_equipment_flag_if_exist(ModeSTypeP);
46 append_equipment_flag_if_exist(ModeSTypeS);
47 append_equipment_flag_if_exist(AdsBB1);
48 append_equipment_flag_if_exist(AdsBB2);
49 append_equipment_flag_if_exist(AdsBU1);
50 append_equipment_flag_if_exist(AdsBU2);
51 append_equipment_flag_if_exist(AdsBV1);
52 append_equipment_flag_if_exist(AdsBV2);
53 append_equipment_flag_if_exist(AdsCD1);
54 append_equipment_flag_if_exist(AdsCG1);
55
56 if (!equipment.isEmpty() && m_equipment == SSrEquipment())
57 {
58 // Default if nothing correct is provided
59 m_equipment = None;
60 }
61 }
62
64 {
65 QStringList list;
66
67 // Append flag (as string) to list if flag exists in current equipment
68 auto append_flag_if_exist = [&list, this](SsrEquipmentOption flag) {
69 if (m_equipment.testFlag(flag)) list << flagToString(flag);
70 };
71
72 append_flag_if_exist(None);
73 append_flag_if_exist(ModeA);
74 append_flag_if_exist(ModeAC);
75 append_flag_if_exist(ModeSTypeE);
76 append_flag_if_exist(ModeSTypeH);
77 append_flag_if_exist(ModeSTypeI);
78 append_flag_if_exist(ModeSTypeL);
79 append_flag_if_exist(ModeSTypeX);
80 append_flag_if_exist(ModeSTypeP);
81 append_flag_if_exist(ModeSTypeS);
82 append_flag_if_exist(AdsBB1);
83 append_flag_if_exist(AdsBB2);
84 append_flag_if_exist(AdsBU1);
85 append_flag_if_exist(AdsBU2);
86 append_flag_if_exist(AdsBV1);
87 append_flag_if_exist(AdsBV2);
88 append_flag_if_exist(AdsCD1);
89 append_flag_if_exist(AdsCG1);
90
91 return list;
92 }
93
95 {
96 const QString equipmentString = enabledOptions().join("");
97 Q_ASSERT_X(!equipmentString.isEmpty(), Q_FUNC_INFO, "Equipment string should not be empty");
98 return equipmentString;
99 }
100
101 QString CSsrEquipment::flagToString(CSsrEquipment::SSrEquipment flag)
102 {
103 if (flag == None)
104 {
105 static const QString q("N");
106 return q;
107 }
108 if (flag == ModeA)
109 {
110 static const QString q("A");
111 return q;
112 }
113 if (flag == ModeAC)
114 {
115 static const QString q("C");
116 return q;
117 }
118 if (flag == ModeSTypeE)
119 {
120 static const QString q("E");
121 return q;
122 }
123 if (flag == ModeSTypeH)
124 {
125 static const QString q("H");
126 return q;
127 }
128 if (flag == ModeSTypeI)
129 {
130 static const QString q("I");
131 return q;
132 }
133 if (flag == ModeSTypeL)
134 {
135 static const QString q("L");
136 return q;
137 }
138 if (flag == ModeSTypeX)
139 {
140 static const QString q("X");
141 return q;
142 }
143 if (flag == ModeSTypeP)
144 {
145 static const QString q("P");
146 return q;
147 }
148 if (flag == ModeSTypeS)
149 {
150 static const QString q("S");
151 return q;
152 }
153 if (flag == AdsBB1)
154 {
155 static const QString q("B1");
156 return q;
157 }
158 if (flag == AdsBB2)
159 {
160 static const QString q("B2");
161 return q;
162 }
163 if (flag == AdsBU1)
164 {
165 static const QString q("U1");
166 return q;
167 }
168 if (flag == AdsBU2)
169 {
170 static const QString q("U2");
171 return q;
172 }
173 if (flag == AdsBV1)
174 {
175 static const QString q("V1");
176 return q;
177 }
178 if (flag == AdsBV2)
179 {
180 static const QString q("V2");
181 return q;
182 }
183 if (flag == AdsCD1)
184 {
185 static const QString q("D1");
186 return q;
187 }
188 if (flag == AdsCG1)
189 {
190 static const QString q("G1");
191 return q;
192 }
193 return {};
194 }
195
197 {
198 // In order as they appear in the final string
199 static const QStringList r(
200 { "N", "A", "C", "E", "H", "I", "L", "X", "P", "S", "B1", "B2", "U1", "U2", "V1", "V2", "D1", "G1" });
201 return r;
202 }
203
204} // namespace swift::misc::aviation
CSsrEquipment()=default
Create default SSR equipment with "None" equipment enabled.
QStringList enabledOptions() const
Get all enabled SSR equipment codes of this object as a list.
SsrEquipmentOption
Surveillance equipment options.
QString convertToQString(bool i18n=false) const
Get the SSR equipment string of this object (for example "LB1").
static QStringList allEquipmentLetters()
Get all possible SSR equipment code letters.
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QString join(QChar separator) const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67