swift
platform.h
Go to the documentation of this file.
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 
6 #ifndef SWIFT_MISC_PLATFORM_H
7 #define SWIFT_MISC_PLATFORM_H
8 
9 #include <QString>
10 
11 #include "misc/metaclass.h"
12 #include "misc/propertyindexref.h"
13 #include "misc/swiftmiscexport.h"
14 #include "misc/valueobject.h"
15 
17 
18 namespace swift::misc
19 {
23  class SWIFT_MISC_EXPORT CPlatform : public CValueObject<CPlatform>
24  {
25  public:
28  {
29  IndexPlatform = CPropertyIndexRef::GlobalIndexCPlatform
30  };
31 
34  {
35  UnknownOs = 0,
36  Win32 = 1 << 0,
37  Win64 = 1 << 1,
38  Linux = 1 << 2,
39  MacOS = 1 << 3,
40  Independent = 1 << 4,
41  AllWindows = Win32 | Win64,
42  All = AllWindows | Linux | MacOS,
43  All32 = Win32,
44  All64 = Win64 | Linux | MacOS
45  };
46  Q_DECLARE_FLAGS(Platform, PlatformFlag)
47 
48 
49  CPlatform() {}
50 
52  CPlatform(const QString &p);
53 
55  CPlatform(Platform p);
56 
58  Platform getPlatform() const { return static_cast<Platform>(m_platform); }
59 
61  PlatformFlag getPlatformFlag() const;
62 
64  bool matchesAny(const CPlatform &otherPlatform) const;
65 
67  int numberPlatforms() const;
68 
70  bool isSinglePlatform() const;
71 
73  bool isAnyWindows() const;
74 
76  QString getPlatformName() const;
77 
79  void setPlatform(Platform p) { m_platform = p; }
80 
82  bool isUnknown() const { return m_platform == static_cast<int>(UnknownOs); }
83 
85  void setPlatform(const QString &p) { setPlatform(stringToPlatform(p)); }
86 
88  CIcons::IconIndex toIcon() const;
89 
91  QString convertToQString(bool i18n = false) const;
92 
94  QVariant propertyByIndex(CPropertyIndexRef index) const;
95 
97  void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant);
98 
100  int comparePropertyByIndex(CPropertyIndexRef index, const CPlatform &compareValue) const;
101 
103  operator QString() { return this->toQString(); }
104 
106  static Platform stringToPlatform(const QString &str);
107 
109  const static CPlatform &stringToPlatformObject(const QString &str);
110 
112  static const CPlatform &currentPlatform();
113 
115  static bool isCurrentPlatform(const QString &platform);
116 
118  static bool isCurrentPlatform(const CPlatform &platform);
119 
121  static bool canRunOnCurrentPlatform(const CPlatform &platform);
122 
124  static const CPlatform &win32Platform();
125 
127  static const CPlatform &win64Platform();
128 
130  static const CPlatform &linuxPlatform();
131 
133  static const CPlatform &macOSPlatform();
134 
136  static const CPlatform &unknownOs();
137 
139  static const CPlatform &allOs();
140 
142  static const CPlatform &independent();
143 
144  private:
145  int m_platform = static_cast<int>(UnknownOs);
146 
148  CPlatform,
149  SWIFT_METAMEMBER(platform));
150  };
151 } // namespace swift::misc
152 
153 Q_DECLARE_METATYPE(swift::misc::CPlatform)
154 Q_DECLARE_METATYPE(swift::misc::CPlatform::Platform)
155 Q_DECLARE_METATYPE(swift::misc::CPlatform::PlatformFlag)
156 Q_DECLARE_OPERATORS_FOR_FLAGS(swift::misc::CPlatform::Platform)
157 
158 #endif // SWIFT_MISC_PLATFORM_H
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
Platform (i.e.
Definition: platform.h:24
void setPlatform(const QString &p)
Set platform.
Definition: platform.h:85
void setPlatform(Platform p)
Set platform.
Definition: platform.h:79
Platform getPlatform() const
Platform.
Definition: platform.h:58
bool isUnknown() const
Unknown?
Definition: platform.h:82
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65