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>
26#ifndef QT_NO_DATASTREAM
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)
121 explicit SegmentStorage(
const int *
first,
const int *last)
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; }
138 {
return isUsingPointer() ? pointer_segments->
size() : (inline_segments[InlineSegmentMarker] >> 1); }
143 inline_segments[InlineSegmentMarker] =
qint8(1 + 2 *
len);
150 return isUsingPointer() ?
152 inline_segments[InlineSegmentStartIdx +
index];
155 void setSegments(
int len,
int maj,
int min = 0,
int mic = 0)
158 int data[] = { maj, min, mic };
161 setVector(
len, maj, min, mic);
168 if (
len > InlineSegmentCount)
179#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
182#elif Q_BYTE_ORDER == Q_BIG_ENDIAN
184 dummy |=
quintptr(
data[
i] & 0xFF) << (8 * (
sizeof(
void *) -
i - 1));
189 inline_segments[InlineSegmentStartIdx +
i] =
data[
i] & 0xFF;
193 Q_CORE_EXPORT
void setVector(
int len,
int maj,
int min,
int mic);
204 friend constexpr bool comparesEqual(
const It &lhs,
const It &rhs)
205 {
Q_ASSERT(lhs.v == rhs.v);
return lhs.i == rhs.i; }
214 using iterator_category = std::random_access_iterator_tag;
216#ifdef QT_COMPILER_HAS_LWG3346
217 using element_type =
const int;
225 pointer operator->()
const {
return {**
this}; }
227 It &operator++() { ++
i;
return *
this; }
228 It operator++(
int) {
auto copy = *
this; ++*
this;
return copy; }
230 It &operator--() { --
i;
return *
this; }
231 It operator--(
int) {
auto copy = *
this; --*
this;
return copy; }
241 {
Q_ASSERT(lhs.v == rhs.v);
return lhs.i - rhs.i; }
278 { m_segments.setSegments(1, maj); }
281 { m_segments.setSegments(2, maj, min); }
284 { m_segments.setSegments(3, maj, min, mic); }
286 [[nodiscard]]
inline bool isNull() const noexcept
303 [[nodiscard]] Q_CORE_EXPORT QList<int>
segments()
const;
306 {
return (m_segments.size() >
index) ? m_segments.at(
index) : 0; }
309 {
return m_segments.size(); }
333#if QT_DEPRECATED_SINCE(6, 4) && QT_POINTER_SIZE != 4
345 *suffixIndex = int(
n);
353#if QT_CORE_REMOVED_SINCE(6, 4)
373#ifndef QT_NO_DATASTREAM
381#ifndef QT_NO_DEBUG_STREAM
\inmodule QtCore\reentrant
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
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,...
friend Q_CORE_EXPORT QDataStream & operator>>(QDataStream &in, QVersionNumber &version)
Reads a version number from stream in and stores it in version.
const_reverse_iterator rend() const noexcept
bool isNull() const noexcept
Returns true if there are zero numerical segments, otherwise returns false.
int minorVersion() const noexcept
Returns the minor version number, that is, the second segment.
friend Qt::strong_ordering compareThreeWay(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
QVersionNumber(QSpan< const int > args)
static Q_CORE_EXPORT QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2)
QVersionNumber QVersionNumber::commonPrefix(const QVersionNumber &v1, ...
const_reverse_iterator crbegin() const noexcept
int majorVersion() const noexcept
Returns the major version number, that is, the first segment.
Q_WEAK_OVERLOAD QVersionNumber(const QList< int > &seg)
Constructs a version number from the list of numbers contained in seg.
It::value_type value_type
QVersionNumber() noexcept
Produces a null version.
const_iterator cbegin() const noexcept
static Q_CORE_EXPORT QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex=nullptr)
const_iterator constBegin() const noexcept
const_iterator begin() const noexcept
friend bool comparesEqual(const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
const_iterator end() const noexcept
qsizetype segmentCount() const noexcept
Returns the number of integers stored in segments().
bool isNormalized() const noexcept
Returns true if the version number does not contain any trailing zeros, otherwise returns false.
const_iterator cend() const noexcept
It::difference_type difference_type
const_reverse_iterator rbegin() const noexcept
Q_CORE_EXPORT QString toString() const
Returns a string with all of the segments delimited by a period ({.}).
Q_CORE_EXPORT QVersionNumber normalized() const
Returns an equivalent version number but with all trailing zeros removed.
QVersionNumber(int maj, int min, int mic)
Constructs a QVersionNumber consisting of the major, minor, and micro version numbers maj,...
QVersionNumber(int maj, int min)
Constructs a QVersionNumber consisting of the major and minor version numbers maj and min,...
const_reverse_iterator crend() const noexcept
QVersionNumber(int maj)
Constructs a QVersionNumber consisting of just the major version number maj.
std::reverse_iterator< const_iterator > const_reverse_iterator
int segmentAt(qsizetype index) const noexcept
Returns the segment value at index.
friend Q_CORE_EXPORT size_t qHash(const QVersionNumber &key, size_t seed)
int microVersion() const noexcept
Returns the micro version number, that is, the third segment.
const_iterator constEnd() const noexcept
reference const_reference
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,...
Q_WEAK_OVERLOAD QVersionNumber(QList< int > &&seg)
Move-constructs a version number from the list of numbers contained in seg.
\inmodule QtCore \title Classes and helpers for defining comparison operators \keyword qtcompare
QSet< QString >::iterator it
Combined button and popup list for selecting options.
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
static jboolean copy(JNIEnv *, jobject)
#define Q_DECLARE_STRONGLY_ORDERED(...)
#define Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(...)
#define QT_WARNING_DISABLE_GCC(text)
constexpr timespec operator+(const timespec &t1, const timespec &t2)
constexpr timespec operator*(const timespec &t1, int mul)
constexpr timespec & operator+=(timespec &t1, const timespec &t2)
constexpr timespec operator-(const timespec &t1, const timespec &t2)
bool comparesEqual(const QDir &lhs, const QDir &rhs)
GLint GLfloat GLfloat GLfloat v2
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
#define QT_DEPRECATED_VERSION_X_6_4(text)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
QT_BEGIN_NAMESPACE typedef signed char qint8
Qt::weak_ordering compareThreeWay(const QUrl &lhs, const QUrl &rhs)
Q_CORE_EXPORT size_t qHash(const QVersionNumber &key, size_t seed=0)
Q_CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QVersionNumber &version)
Q_CORE_EXPORT QDataStream & operator>>(QDataStream &in, QVersionNumber &version)
if(qFloatDistance(a, b)<(1<< 7))
[0]
QTextStream out(stdout)
[7]