1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include <QtCore/qglobal.h>
41
42#ifndef QOPERATINGSYSTEMVERSION_H
43#define QOPERATINGSYSTEMVERSION_H
44
45QT_BEGIN_NAMESPACE
46
47class QString;
48class QVersionNumber;
49
50class Q_CORE_EXPORT QOperatingSystemVersion
51{
52public:
53 enum OSType {
54 Unknown = 0,
55 Windows,
56 MacOS,
57 IOS,
58 TvOS,
59 WatchOS,
60 Android
61 };
62
63 static const QOperatingSystemVersion WindowsVista;
64 static const QOperatingSystemVersion Windows7;
65 static const QOperatingSystemVersion Windows8;
66 static const QOperatingSystemVersion Windows8_1;
67 static const QOperatingSystemVersion Windows10;
68
69 static const QOperatingSystemVersion OSXMavericks;
70 static const QOperatingSystemVersion OSXYosemite;
71 static const QOperatingSystemVersion OSXElCapitan;
72 static const QOperatingSystemVersion MacOSSierra;
73 static const QOperatingSystemVersion MacOSHighSierra;
74 static const QOperatingSystemVersion MacOSMojave;
75
76 static const QOperatingSystemVersion AndroidJellyBean;
77 static const QOperatingSystemVersion AndroidJellyBean_MR1;
78 static const QOperatingSystemVersion AndroidJellyBean_MR2;
79 static const QOperatingSystemVersion AndroidKitKat;
80 static const QOperatingSystemVersion AndroidLollipop;
81 static const QOperatingSystemVersion AndroidLollipop_MR1;
82 static const QOperatingSystemVersion AndroidMarshmallow;
83 static const QOperatingSystemVersion AndroidNougat;
84 static const QOperatingSystemVersion AndroidNougat_MR1;
85 static const QOperatingSystemVersion AndroidOreo;
86
87 Q_DECL_CONSTEXPR QOperatingSystemVersion(OSType osType,
88 int vmajor, int vminor = -1, int vmicro = -1)
89 : m_os(osType),
90 m_major(qMax(-1, vmajor)),
91 m_minor(vmajor < 0 ? -1 : qMax(-1, vminor)),
92 m_micro(vmajor < 0 || vminor < 0 ? -1 : qMax(-1, vmicro))
93 { }
94
95 static QOperatingSystemVersion current();
96
97 static Q_DECL_CONSTEXPR OSType currentType()
98 {
99#if defined(Q_OS_WIN)
100 return Windows;
101#elif defined(Q_OS_MACOS)
102 return MacOS;
103#elif defined(Q_OS_IOS)
104 return IOS;
105#elif defined(Q_OS_TVOS)
106 return TvOS;
107#elif defined(Q_OS_WATCHOS)
108 return WatchOS;
109#elif defined(Q_OS_ANDROID)
110 return Android;
111#else
112 return Unknown;
113#endif
114 }
115
116 Q_DECL_CONSTEXPR int majorVersion() const { return m_major; }
117 Q_DECL_CONSTEXPR int minorVersion() const { return m_minor; }
118 Q_DECL_CONSTEXPR int microVersion() const { return m_micro; }
119
120 Q_DECL_CONSTEXPR int segmentCount() const
121 { return m_micro >= 0 ? 3 : m_minor >= 0 ? 2 : m_major >= 0 ? 1 : 0; }
122
123 bool isAnyOfType(std::initializer_list<OSType> types) const;
124 Q_DECL_CONSTEXPR OSType type() const { return m_os; }
125 QString name() const;
126
127 friend bool operator>(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs)
128 { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(lhs, rhs) > 0; }
129
130 friend bool operator>=(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs)
131 { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(lhs, rhs) >= 0; }
132
133 friend bool operator<(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs)
134 { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(lhs, rhs) < 0; }
135
136 friend bool operator<=(const QOperatingSystemVersion &lhs, const QOperatingSystemVersion &rhs)
137 { return lhs.type() == rhs.type() && QOperatingSystemVersion::compare(lhs, rhs) <= 0; }
138
139private:
140 QOperatingSystemVersion() = default;
141 OSType m_os;
142 int m_major;
143 int m_minor;
144 int m_micro;
145
146 static int compare(const QOperatingSystemVersion &v1, const QOperatingSystemVersion &v2);
147};
148Q_DECLARE_TYPEINFO(QOperatingSystemVersion, QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ? Q_RELOCATABLE_TYPE : Q_PRIMITIVE_TYPE);
149
150#ifndef QT_NO_DEBUG_STREAM
151class QDebug;
152Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QOperatingSystemVersion &ov);
153#endif
154
155QT_END_NAMESPACE
156
157#endif // QOPERATINGSYSTEMVERSION_H
158