swift
ecosystem.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
7 #include "misc/iconlist.h"
8 #include "misc/verify.h"
9 
10 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::network, CEcosystem)
11 
12 namespace swift::misc::network
13 {
14  QString CEcosystem::convertToQString(bool i18n) const
15  {
16  Q_UNUSED(i18n);
17  return this->getSystemString();
18  }
19 
21  {
22  static const CEcosystem e(Unspecified);
23  return e;
24  }
25 
27  {
28  static const CEcosystem e(VATSIM);
29  return e;
30  }
31 
33  {
34  static const CEcosystem e(Swift);
35  return e;
36  }
37 
39  {
40  static const CEcosystem e(SwiftTest);
41  return e;
42  }
43 
45  {
46  static const CEcosystem e(PrivateFSD);
47  return e;
48  }
49 
50  const QString &CEcosystem::getSystemString() const
51  {
52  static const QString u("unknown");
53  static const QString v("VATSIM");
54  static const QString s("swift");
55  static const QString st("swift (testing)");
56  static const QString fsd("FSD (private)");
57  static const QString no("no system");
58 
59  switch (this->getSystem())
60  {
61  case VATSIM: return v;
62  case Swift: return s;
63  case SwiftTest: return st;
64  case PrivateFSD: return fsd;
65  case NoSystem: return no;
66  case Unspecified:
67  default: return u;
68  }
69  }
70 
72  {
73  if (index.isMyself()) { return QVariant::fromValue(*this); }
74  const ColumnIndex i = index.frontCasted<ColumnIndex>();
75  switch (i)
76  {
77  case IndexSystem: return QVariant::fromValue(m_system);
78  case IndexSystemString: return QVariant::fromValue(this->getSystemString());
79  default: return CValueObject::propertyByIndex(index);
80  }
81  }
82 
83  void CEcosystem::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
84  {
85  if (index.isMyself())
86  {
87  (*this) = variant.value<CEcosystem>();
88  return;
89  }
90  const ColumnIndex i = index.frontCasted<ColumnIndex>();
91  switch (i)
92  {
93  case IndexSystem: m_system = variant.toInt(); break;
94  default: CValueObject::setPropertyByIndex(index, variant); break;
95  }
96  }
97 
98  int CEcosystem::comparePropertyByIndex(CPropertyIndexRef index, const CEcosystem &compareValue) const
99  {
100  if (index.isMyself()) { return Compare::compare(m_system, compareValue.m_system); }
101  const ColumnIndex i = index.frontCasted<ColumnIndex>();
102  switch (i)
103  {
104  case IndexSystem: return Compare::compare(m_system, compareValue.m_system);
105  default: break;
106  }
107  SWIFT_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString()));
108  return 0;
109  }
110 } // namespace swift::misc::network
Non-owning reference to a CPropertyIndex with a subset of its features.
QString toQString(bool i18n=false) const
Cast as QString.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
Ecosystem of server belonging together.
Definition: ecosystem.h:21
@ SwiftTest
swift test server
Definition: ecosystem.h:36
@ NoSystem
no relevant ecosystem
Definition: ecosystem.h:34
@ PrivateFSD
Private FSD environment.
Definition: ecosystem.h:38
int comparePropertyByIndex(CPropertyIndexRef index, const CEcosystem &compareValue) const
Compare for index.
Definition: ecosystem.cpp:98
static const CEcosystem & vatsim()
VATSIM eco system.
Definition: ecosystem.cpp:26
static const CEcosystem & swiftTest()
swift test eco system
Definition: ecosystem.cpp:38
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: ecosystem.cpp:83
System getSystem() const
Get system.
Definition: ecosystem.h:48
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
Definition: ecosystem.cpp:71
static const CEcosystem & privateFsd()
FSD private.
Definition: ecosystem.cpp:44
static const CEcosystem & unspecified()
Unspecified.
Definition: ecosystem.cpp:20
static const CEcosystem & swift()
swift eco system
Definition: ecosystem.cpp:32
QString convertToQString(bool i18n=false) const
Cast as QString.
Definition: ecosystem.cpp:14
const QString & getSystemString() const
Get the system string.
Definition: ecosystem.cpp:50
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition: verify.h:26