swift
propertyindexref.h
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 
5 
6 #ifndef SWIFT_MISC_PROPERTYINDEXREF_H
7 #define SWIFT_MISC_PROPERTYINDEXREF_H
8 
9 #include <QVector>
10 
11 #include "misc/swiftmiscexport.h"
12 #include "misc/typetraits.h"
13 
14 namespace swift::misc
15 {
20  {
21  public:
24  {
25  GlobalIndexCValueObject = 10,
26  GlobalIndexCPhysicalQuantity = 100,
27  GlobalIndexCStatusMessage = 200,
28  GlobalIndexCNameVariantPair = 300,
29  GlobalIndexITimestampBased = 400,
30  GlobalIndexIOrderable = 500,
31  GlobalIndexINullable = 600,
32  GlobalIndexCIdentifier = 700,
33  GlobalIndexCRgbColor = 800,
34  GlobalIndexCCountry = 900,
35  GlobalIndexCPlatform = 1000,
36  GlobalIndexCApplicationInfo = 1100,
37  GlobalIndexCDirectories = 1200,
38  GlobalIndexCCrashInfo = 1300,
39  GlobalIndexCCrashSettings = 1400,
40  GlobalIndexCAircraftVelocity = 1900,
41  GlobalIndexCCallsign = 2000,
42  GlobalIndexCAircraftSituation = 2100,
43  GlobalIndexCAircraftSituationChange = 2200,
44  GlobalIndexCAtcStation = 2300,
45  GlobalIndexCInformationMessage = 2400,
46  GlobalIndexCAirport = 2500,
47  GlobalIndexCAircraftParts = 2600,
48  GlobalIndexCAircraftLights = 2700,
49  GlobalIndexCLivery = 2800,
50  GlobalIndexCFlightPlan = 2900,
51  GlobalIndexCSimBriefData = 3000,
52  GlobalIndexCComSystem = 3100,
53  GlobalIndexCModulator = 3200,
54  GlobalIndexCTransponder = 3300,
55  GlobalIndexCAircraftCategory = 3500,
56  GlobalIndexCAircraftIcaoCode = 3600,
57  GlobalIndexCAirlineIcaoCode = 3700,
58  GlobalIndexCAirportIcaoCode = 3800,
59  GlobalIndexCMetar = 4000,
60  GlobalIndexCCloudLayer = 4100,
61  GlobalIndexCPresentWeather = 4200,
62  GlobalIndexCWindLayer = 4300,
63  GlobalIndexCWeatherScenario = 4700,
64  GlobalIndexCOnGroundInfo = 4800,
65  GlobalIndexICoordinateGeodetic = 5000,
66  GlobalIndexICoordinateWithRelativePosition = 5100,
67  GlobalIndexCCoordinateGeodetic = 5200,
68  GlobalIndexCElevationPlane = 5300,
69  GlobalIndexCClient = 6000,
70  GlobalIndexCUser = 6100,
71  GlobalIndexCAuthenticatedUser = 6200,
72  GlobalIndexCRole = 6300,
73  GlobalIndexCServer = 6400,
74  GlobalIndexCFsdSetup = 6500,
75  GlobalIndexCUrl = 6800,
76  GlobalIndexCUrlLog = 6900,
77  GlobalIndexCRemoteFile = 7000,
78  GlobalIndexCEcosystem = 7100,
79  GlobalIndexCRawFsdMessage = 7200,
80  GlobalIndexCAircraftModel = 8000,
81  GlobalIndexCSimulatedAircraft = 8100,
82  GlobalIndexCTextMessage = 8200,
83  GlobalIndexCSimulatorInternals = 8300,
84  GlobalIndexCSimulatorSettings = 8400,
85  GlobalIndexCSwiftPluignSettings = 8500,
86  GlobalIndexCSimulatorMessageSettings = 8600,
87  GlobalIndexCModelSettings = 8700,
88  GlobalIndexCAircraftCfgEntries = 8800,
89  GlobalIndexCDistributor = 8900,
90  GlobalIndexCVPilotModelRule = 9000,
91  GlobalIndexCAudioDeviceInfo = 10000,
92  GlobalIndexCSettingKeyboardHotkey = 11000,
93  GlobalIndexCKeyboardKey = 11100,
94  GlobalIndexCJoystickButton = 11200,
95  GlobalIndexIDatastore = 12000,
96  GlobalIndexIDatastoreInteger = 12100,
97  GlobalIndexIDatastoreString = 12200,
98  GlobalIndexCDbInfo = 12300,
99  GlobalIndexCGlobalSetup = 13000,
100  GlobalIndexCArtifact = 13100,
101  GlobalIndexCDistribution = 13200,
102  GlobalIndexCUpdateInfo = 13300,
103  GlobalIndexCVatsimSetup = 13400,
104  GlobalIndexCLauncherSetup = 13500,
105  GlobalIndexCGuiStateDbOwnModelsComponent = 14000,
106  GlobalIndexCGuiStateDbOwnModelSetComponent = 14100,
107  GlobalIndexCDockWidgetSettings = 14200,
108  GlobalIndexCNavigatorSettings = 14300,
109  GlobalIndexCSettingsReaders = 14400,
110  GlobalIndexCViewUpdateSettings = 14500,
111  GlobalIndexCGeneralGuiSettings = 14600,
112  GlobalIndexCTextMessageSettings = 14700,
113  GlobalIndexCAtcStationsSettings = 14800,
114  GlobalIndexRawFsdMessageSettings = 14900,
115  GlobalIndexCInterpolatioRenderingSetup = 16000,
116  GlobalIndexCMatchingStatisticsEntry = 16100,
117  GlobalIndexCAircraftMatcherSetup = 16200,
118  GlobalIndexCXSwiftBusSettings = 16300,
119  GlobalIndexCFGSwiftBusSettings = 16400,
120  GlobalIndexSwiftPilotClient = 17000,
121  GlobalIndexSwiftCore = 17100,
122  GlobalIndexSwiftLauncher = 17200,
123  GlobalIndexLineNumber = 20000,
124  GlobalIndexEmpty = 20001
125  };
126 
128  CPropertyIndexRef(int index);
129 
131  explicit CPropertyIndexRef(const QVector<int> &indexes);
132 
134  explicit CPropertyIndexRef(QVector<int> &&) = delete;
135 
137  Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const;
138 
140  bool isNested() const;
141 
143  bool isMyself() const;
144 
146  bool isEmpty() const;
147 
149  int frontToInt() const;
150 
152  bool startsWith(int index) const;
153 
155  QString toQString(bool i18n = false) const;
156 
158  template <class CastType>
159  CastType frontCasted() const
160  {
161  static_assert(std::is_enum_v<CastType> || std::is_integral_v<CastType>,
162  "CastType must be an enum or integer");
163  return static_cast<CastType>(frontToInt());
164  }
165 
167  template <class EnumType>
168  bool startsWithPropertyIndexEnum(EnumType ev) const
169  {
170  static_assert(std::is_enum_v<EnumType>, "Argument must be an enum");
171  return this->startsWith(static_cast<int>(ev));
172  }
173 
175  auto comparator() const
176  {
177  return [index = *this](const auto &a, const auto &b) {
178  using T = std::decay_t<decltype(a)>;
179  if constexpr (THasComparePropertyByIndex<T>::value) { return a.comparePropertyByIndex(index, b); }
180  else if constexpr (THasPropertyByIndex<T>::value)
181  {
182  return compare(a.propertyByIndex(index), b.propertyByIndex(index));
183  }
184  else
185  {
186  qFatal("Not implemented");
187  return 0;
188  }
189  };
190  }
191 
193  static CPropertyIndexRef empty() { return -1; }
194 
195  private:
196  const int *m_begin = nullptr;
197  int m_sizeOrIndex = -1;
198  };
199 } // namespace swift::misc
200 
201 #endif // SWIFT_MISC_PROPERTYINDEXREF_H
Non-owning reference to a CPropertyIndex with a subset of its features.
auto comparator() const
Return a predicate function which can compare two objects based on this index.
static CPropertyIndexRef empty()
an empty property index
GlobalIndex
Global index, make sure the indexes are unqiue (for using them in class hierarchy)
bool startsWithPropertyIndexEnum(EnumType ev) const
Compare with index given by enum.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
CPropertyIndexRef(QVector< int > &&)=delete
Forbid accidental constructor from an rvalue.
Free functions in swift::misc.
Trait which is true if the expression a.compareByPropertyIndex(b, i) is valid when a and b are instan...
Definition: typetraits.h:135
Trait which is true if the expression a.propertyByIndex(i) is valid with a is an instance of T and i ...
Definition: typetraits.h:150
#define SWIFT_MISC_EXPORT
Export a class or function from the library.