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