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 {
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(PrivateFSD);
35  return e;
36  }
37 
39  {
40  static const QString u("unknown");
41  static const QString v("VATSIM");
42  static const QString fsd("FSD");
43  static const QString no("no system");
44 
45  switch (this->getSystem())
46  {
47  case VATSIM: return v;
48  case PrivateFSD: return fsd;
49  case NoSystem: return no;
50  case Unspecified:
51  default: return u;
52  }
53  }
54 
56  {
57  if (index.isMyself()) { return QVariant::fromValue(*this); }
58  const auto i = index.frontCasted<ColumnIndex>();
59  switch (i)
60  {
61  case IndexSystem: return QVariant::fromValue(m_system);
62  case IndexSystemString: return QVariant::fromValue(this->getSystemString());
63  default: return CValueObject::propertyByIndex(index);
64  }
65  }
66 
68  {
69  if (index.isMyself())
70  {
71  (*this) = variant.value<CEcosystem>();
72  return;
73  }
74  const auto i = index.frontCasted<ColumnIndex>();
75  switch (i)
76  {
77  case IndexSystem: m_system = variant.toInt(); break;
78  default: CValueObject::setPropertyByIndex(index, variant); break;
79  }
80  }
81 
82  int CEcosystem::comparePropertyByIndex(CPropertyIndexRef index, const CEcosystem &compareValue) const
83  {
84  if (index.isMyself()) { return Compare::compare(m_system, compareValue.m_system); }
85  const auto i = index.frontCasted<ColumnIndex>();
86  switch (i)
87  {
88  case IndexSystem: return Compare::compare(m_system, compareValue.m_system);
89  default: break;
90  }
91  SWIFT_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString()));
92  return 0;
93  }
94 } // 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:158
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:165
Ecosystem of server belonging together.
Definition: ecosystem.h:21
@ NoSystem
no relevant ecosystem
Definition: ecosystem.h:34
@ PrivateFSD
Private FSD environment.
Definition: ecosystem.h:36
int comparePropertyByIndex(CPropertyIndexRef index, const CEcosystem &compareValue) const
Compare for index.
Definition: ecosystem.cpp:82
static const CEcosystem & vatsim()
VATSIM eco system.
Definition: ecosystem.cpp:26
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: ecosystem.cpp:67
System getSystem() const
Get system.
Definition: ecosystem.h:46
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
Definition: ecosystem.cpp:55
static const CEcosystem & privateFsd()
FSD private.
Definition: ecosystem.cpp:32
static const CEcosystem & unspecified()
Unspecified.
Definition: ecosystem.cpp:20
QString convertToQString(bool i18n=false) const
Cast as QString.
Definition: ecosystem.cpp:14
const QString & getSystemString() const
Get the system string.
Definition: ecosystem.cpp:38
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
T value() const &const
#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