6#ifndef QVERSIONNUMBER_H
7#define QVERSIONNUMBER_H
9#include <QtCore/qcompare.h>
10#include <QtCore/qcontainertools_impl.h>
11#include <QtCore/qlist.h>
12#include <QtCore/qmetatype.h>
13#include <QtCore/qnamespace.h>
14#include <QtCore/qspan.h>
15#include <QtCore/qstring.h>
16#include <QtCore/qtypeinfo.h>
17#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 2
18#include <QtCore/qtyperevision.h>
24Q_CORE_EXPORT size_t qHash(
const QVersionNumber &key, size_t seed = 0);
26#ifndef QT_NO_DATASTREAM
34
35
36
37
38
39
43 InlineSegmentMarker = Q_BYTE_ORDER == Q_LITTLE_ENDIAN ? 0 :
sizeof(
void *) - 1,
44 InlineSegmentStartIdx = !InlineSegmentMarker,
45 InlineSegmentCount =
sizeof(
void *) - 1
47 static_assert(InlineSegmentCount >= 3);
56 qint8 inline_segments[
sizeof(
void *)];
57 QList<
int> *pointer_segments;
61 SegmentStorage()
noexcept : dummy(1) {}
63 SegmentStorage(
const QList<
int> &seg)
65 if (dataFitsInline(seg.data(), seg.size()))
66 setInlineData(seg.data(), seg.size());
71 Q_CORE_EXPORT
void setListData(
const QList<
int> &seg);
73 SegmentStorage(
const SegmentStorage &other)
75 if (other.isUsingPointer())
76 setListData(*other.pointer_segments);
81 SegmentStorage &operator=(
const SegmentStorage &other)
83 if (isUsingPointer() && other.isUsingPointer()) {
84 *pointer_segments = *other.pointer_segments;
85 }
else if (other.isUsingPointer()) {
86 setListData(*other.pointer_segments);
89 delete pointer_segments;
95 SegmentStorage(SegmentStorage &&other)
noexcept
101 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(SegmentStorage)
103 void swap(SegmentStorage &other)
noexcept
105 std::swap(dummy, other.dummy);
108 explicit SegmentStorage(QList<
int> &&seg)
110 if (dataFitsInline(std::as_const(seg).data(), seg.size()))
111 setInlineData(std::as_const(seg).data(), seg.size());
113 setListData(std::move(seg));
116 Q_CORE_EXPORT
void setListData(QList<
int> &&seg);
118 explicit SegmentStorage(QSpan<
const int> args)
119 : SegmentStorage(args.begin(), args.end()) {}
121 explicit SegmentStorage(
const int *first,
const int *last)
123 if (dataFitsInline(first, last - first)) {
124 setInlineData(first, last - first);
126 setListData(first, last);
130 Q_CORE_EXPORT
void setListData(
const int *first,
const int *last);
132 ~SegmentStorage() {
if (isUsingPointer())
delete pointer_segments; }
134 bool isUsingPointer()
const noexcept
135 {
return (inline_segments[InlineSegmentMarker] & 1) == 0; }
137 qsizetype size()
const noexcept
138 {
return isUsingPointer() ? pointer_segments->size() : (inline_segments[InlineSegmentMarker] >> 1); }
140 void setInlineSize(qsizetype len)
142 Q_ASSERT(len <= InlineSegmentCount);
143 inline_segments[InlineSegmentMarker] = qint8(1 + 2 * len);
146 Q_CORE_EXPORT
void resize(qsizetype len);
148 int at(qsizetype index)
const
150 return isUsingPointer() ?
151 pointer_segments->at(index) :
152 inline_segments[InlineSegmentStartIdx + index];
155 void setSegments(
int len,
int maj,
int min = 0,
int mic = 0)
157 if (maj == qint8(maj) && min == qint8(min) && mic == qint8(mic)) {
158 int data[] = { maj, min, mic };
159 setInlineData(data, len);
161 setVector(len, maj, min, mic);
166 static bool dataFitsInline(
const int *data, qsizetype len)
168 if (len > InlineSegmentCount)
170 for (qsizetype i = 0; i < len; ++i)
171 if (data[i] != qint8(data[i]))
175 void setInlineData(
const int *data, qsizetype len)
177 Q_ASSERT(len <= InlineSegmentCount);
179#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
180 for (qsizetype i = 0; i < len; ++i)
181 dummy |= quintptr(data[i] & 0xFF) << (8 * (i + 1));
182#elif Q_BYTE_ORDER == Q_BIG_ENDIAN
183 for (qsizetype i = 0; i < len; ++i)
184 dummy |= quintptr(data[i] & 0xFF) << (8 * (
sizeof(
void *) - i - 1));
188 for (qsizetype i = 0; i < len; ++i)
189 inline_segments[InlineSegmentStartIdx + i] = data[i] & 0xFF;
193 Q_CORE_EXPORT
void setVector(
int len,
int maj,
int min,
int mic);
202 explicit constexpr It(
const QVersionNumber *vn, qsizetype idx)
noexcept : v(vn), i(idx) {}
204 friend constexpr bool comparesEqual(
const It &lhs,
const It &rhs)
205 { Q_ASSERT(lhs.v == rhs.v);
return lhs.i == rhs.i; }
206 friend constexpr Qt::strong_ordering compareThreeWay(
const It &lhs,
const It &rhs)
207 { Q_ASSERT(lhs.v == rhs.v);
return Qt::compareThreeWay(lhs.i, rhs.i); }
209 friend constexpr bool operator==(It lhs, It rhs) {
210 return comparesEqual(lhs, rhs);
212#ifdef __cpp_lib_three_way_comparison
213 friend constexpr std::strong_ordering operator<=>(It lhs, It rhs) {
214 return compareThreeWay(lhs, rhs);
217 friend constexpr bool operator!=(It lhs, It rhs) {
218 return !operator==(lhs, rhs);
220 friend constexpr bool operator<(It lhs, It rhs) {
221 return is_lt(compareThreeWay(lhs, rhs));
223 friend constexpr bool operator<=(It lhs, It rhs) {
224 return is_lteq(compareThreeWay(lhs, rhs));
226 friend constexpr bool operator>(It lhs, It rhs) {
227 return is_gt(compareThreeWay(lhs, rhs));
229 friend constexpr bool operator>=(It lhs, It rhs) {
230 return is_gteq(compareThreeWay(lhs, rhs));
238 using iterator_category = std::random_access_iterator_tag;
239 using value_type =
int;
240#ifdef QT_COMPILER_HAS_LWG3346
241 using element_type =
const int;
243 using difference_type = qptrdiff;
244 using size_type = qsizetype;
245 using reference = value_type;
246 using pointer = QtPrivate::ArrowProxy<reference>;
248 reference operator*()
const {
return v->segmentAt(i); }
249 pointer operator->()
const {
return {**
this}; }
251 It &operator++() { ++i;
return *
this; }
252 It operator++(
int) {
auto copy = *
this; ++*
this;
return copy; }
254 It &operator--() { --i;
return *
this; }
255 It operator--(
int) {
auto copy = *
this; --*
this;
return copy; }
257 It &operator+=(difference_type n) { i += n;
return *
this; }
258 friend It operator+(It it, difference_type n) { it += n;
return it; }
259 friend It operator+(difference_type n, It it) {
return it + n; }
261 It &operator-=(difference_type n) { i -= n;
return *
this; }
262 friend It operator-(It it, difference_type n) { it -= n;
return it; }
264 friend difference_type operator-(It lhs, It rhs)
265 { Q_ASSERT(lhs.v == rhs.v);
return lhs.i - rhs.i; }
267 reference operator[](difference_type n)
const {
return *(*
this + n); }
271 using const_iterator = It;
274 using value_type = It::value_type;
277 using reference = It::reference;
278 using const_reference = reference;
330 {
return (m_segments.size() > index) ? m_segments.at(index) : 0; }
333 {
return m_segments.size(); }
335 [[
nodiscard]] const_iterator
begin()
const noexcept {
return const_iterator{
this, 0}; }
336 [[
nodiscard]] const_iterator
end()
const noexcept {
return begin() + segmentCount(); }
357#if QT_DEPRECATED_SINCE(6
, 4
) && QT_POINTER_SIZE != 4
377#if QT_CORE_REMOVED_SINCE(6
, 4
)
387 return lhs.segmentCount() == rhs.segmentCount() && compare(lhs, rhs) == 0;
392 int c = compare(lhs, rhs);
393 return Qt::compareThreeWay(c, 0);
397#ifndef QT_NO_DATASTREAM
405#ifndef QT_NO_DEBUG_STREAM
\inmodule QtCore\reentrant
constexpr int segmentCount() const
QVersionNumber version() const
friend bool operator<=(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept
friend bool operator<(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept
QOperatingSystemVersionBase()=default
friend bool operator>=(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept
constexpr QOperatingSystemVersionBase(OSType osType, int vmajor, int vminor=-1, int vmicro=-1)
bool isAnyOfType(std::initializer_list< OSType > types) const
constexpr int majorVersion() const
static Q_CORE_EXPORT bool isAnyOfType(std::initializer_list< OSType > types, OSType type)
constexpr int minorVersion() const
constexpr int microVersion() const
friend bool operator>(QOperatingSystemVersionBase lhs, QOperatingSystemVersionBase rhs) noexcept
friend Qt::partial_ordering compareThreeWay(const QOperatingSystemVersionBase &lhs, const QOperatingSystemVersionBase &rhs) noexcept
static constexpr OSType currentType()
constexpr OSType type() const
static Q_CORE_EXPORT int compare(QOperatingSystemVersionBase v1, QOperatingSystemVersionBase v2) noexcept
static constexpr QOperatingSystemVersionBase MacOSSequoia
static constexpr QOperatingSystemVersionBase Windows11_21H2
\variable QOperatingSystemVersion::Windows11_21H2
static constexpr QOperatingSystemVersionBase AndroidNougat
\variable QOperatingSystemVersion::AndroidNougat
static constexpr QOperatingSystemVersionBase Android10
\variable QOperatingSystemVersion::Android10
static constexpr QOperatingSystemVersionBase MacOSSierra
\variable QOperatingSystemVersion::MacOSSierra
static constexpr QOperatingSystemVersionBase OSXYosemite
\variable QOperatingSystemVersion::OSXYosemite
static constexpr QOperatingSystemVersionBase Android12L
\variable QOperatingSystemVersion::Android12L
static constexpr QOperatingSystemVersionBase Windows10_1909
\variable QOperatingSystemVersion::Windows10_1909
static constexpr QOperatingSystemVersionBase AndroidKitKat
\variable QOperatingSystemVersion::AndroidKitKat
static constexpr QOperatingSystemVersionBase AndroidJellyBean
\variable QOperatingSystemVersion::MacOSSonoma
static constexpr QOperatingSystemVersionBase AndroidOreo_MR1
\variable QOperatingSystemVersion::AndroidOreo_MR1
static constexpr QOperatingSystemVersionBase Android13
\variable QOperatingSystemVersion::Android13
static constexpr QOperatingSystemVersionBase MacOSCatalina
\variable QOperatingSystemVersion::MacOSCatalina
static constexpr QOperatingSystemVersionBase AndroidLollipop_MR1
\variable QOperatingSystemVersion::AndroidLollipop_MR1
static constexpr QOperatingSystemVersionBase Windows10
\variable QOperatingSystemVersion::Windows10
static constexpr QOperatingSystemVersionBase Windows10_1903
\variable QOperatingSystemVersion::Windows10_1903
static constexpr QOperatingSystemVersionBase Android12
\variable QOperatingSystemVersion::Android12
static constexpr OSType currentType()
Returns the current OS type without constructing a QOperatingSystemVersion instance.
static constexpr QOperatingSystemVersionBase Windows11_23H2
static constexpr QOperatingSystemVersionBase OSXElCapitan
\variable QOperatingSystemVersion::OSXElCapitan
static constexpr QOperatingSystemVersionBase MacOSMojave
\variable QOperatingSystemVersion::MacOSMojave
static constexpr QOperatingSystemVersionBase Windows8
\variable QOperatingSystemVersion::Windows8
static constexpr QOperatingSystemVersionBase AndroidNougat_MR1
\variable QOperatingSystemVersion::AndroidNougat_MR1
static constexpr QOperatingSystemVersionBase Android14
static constexpr QOperatingSystemVersionBase Windows10_2004
\variable QOperatingSystemVersion::Windows10_2004
static constexpr QOperatingSystemVersionBase MacOSHighSierra
\variable QOperatingSystemVersion::MacOSHighSierra
static constexpr QOperatingSystemVersionBase Windows10_21H2
\variable QOperatingSystemVersion::Windows10_21H2
constexpr QOperatingSystemVersion(const QOperatingSystemVersionBase &osversion)
static constexpr QOperatingSystemVersionBase AndroidMarshmallow
\variable QOperatingSystemVersion::AndroidMarshmallow
constexpr QOperatingSystemVersion(OSType osType, int vmajor, int vminor=-1, int vmicro=-1)
Constructs a QOperatingSystemVersion consisting of the OS type osType, and major, minor,...
static constexpr QOperatingSystemVersionBase AndroidJellyBean_MR2
\variable QOperatingSystemVersion::AndroidJellyBean_MR2
static constexpr QOperatingSystemVersionBase Windows10_20H2
\variable QOperatingSystemVersion::Windows10_20H2
static constexpr QOperatingSystemVersionBase AndroidPie
\variable QOperatingSystemVersion::AndroidPie
static constexpr QOperatingSystemVersionBase AndroidOreo
\variable QOperatingSystemVersion::AndroidOreo
static constexpr QOperatingSystemVersionBase OSXMavericks
\variable QOperatingSystemVersion::Windows11_23H2
static constexpr QOperatingSystemVersionBase MacOSMonterey
\variable QOperatingSystemVersion::MacOSMonterey
static constexpr QOperatingSystemVersionBase Windows7
\variable QOperatingSystemVersion::Windows7
static constexpr QOperatingSystemVersionBase MacOSVentura
\variable QOperatingSystemVersion::MacOSVentura
static constexpr QOperatingSystemVersionBase Windows10_1809
\variable QOperatingSystemVersion::Windows10_1809
static constexpr QOperatingSystemVersionBase AndroidJellyBean_MR1
\variable QOperatingSystemVersion::AndroidJellyBean_MR1
static constexpr QOperatingSystemVersionBase MacOSBigSur
\variable QOperatingSystemVersion::MacOSBigSur
constexpr OSType type() const
Returns the OS type identified by the QOperatingSystemVersion.
static constexpr QOperatingSystemVersionBase AndroidLollipop
\variable QOperatingSystemVersion::AndroidLollipop
static constexpr QOperatingSystemVersionBase Windows8_1
\variable QOperatingSystemVersion::Windows8_1
static constexpr QOperatingSystemVersionBase Windows11_24H2
static constexpr QOperatingSystemVersionBase Windows10_21H1
\variable QOperatingSystemVersion::Windows10_21H1
static constexpr QOperatingSystemVersionBase Windows11_22H2
\variable QOperatingSystemVersion::Windows11_22H2
static constexpr QOperatingSystemVersionBase Windows10_22H2
\variable QOperatingSystemVersion::Windows10_22H2
static constexpr QOperatingSystemVersionBase Android11
\variable QOperatingSystemVersion::Android11
static constexpr QOperatingSystemVersionBase MacOSSonoma
static constexpr QOperatingSystemVersionBase Windows11
\variable QOperatingSystemVersion::Windows11
QVersionNumber(std::initializer_list< int > args)
Constructs a version number from the std::initializer_list specified by args.
Q_CORE_EXPORT bool isPrefixOf(const QVersionNumber &other) const noexcept
Returns true if the current version number is contained in the other version number,...
const_reverse_iterator crbegin() const noexcept
const_iterator cbegin() const noexcept
friend Qt::strong_ordering compareThreeWay(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
const_iterator end() const noexcept
const_iterator constEnd() const noexcept
QVersionNumber() noexcept
Produces a null version.
friend bool comparesEqual(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
const_reverse_iterator crend() const noexcept
const_reverse_iterator rbegin() const noexcept
qsizetype segmentCount() const noexcept
Returns the number of integers stored in segments().
const_reverse_iterator rend() const noexcept
const_iterator constBegin() const noexcept
const_iterator cend() const noexcept
int segmentAt(qsizetype index) const noexcept
Returns the segment value at index.
static Q_CORE_EXPORT int compare(const QVersionNumber &v1, const QVersionNumber &v2) noexcept
Compares v1 with v2 and returns an integer less than, equal to, or greater than zero,...
const_iterator begin() const noexcept
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
static int compareVersionComponents(int lhs, int rhs) noexcept
Q_DECLARE_TYPEINFO(QOperatingSystemVersion, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QVersionNumber, Q_RELOCATABLE_TYPE)