7#include <QtCore/qglobal.h>
8#include <QtCore/qtcore-config.h>
10#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
11# include <QtCore/qstring.h>
12# include <QtCore/qobjectdefs.h>
16class QNativeIpcKeyPrivate;
19 Q_GADGET_EXPORT(Q_CORE_EXPORT)
21 enum class Type : quint16 {
26 PosixRealtime = 0x100,
31 static constexpr Type DefaultTypeForOs =
38 static Type legacyDefaultTypeForOs()
noexcept;
40 constexpr QNativeIpcKey()
noexcept =
default;
42 explicit constexpr QNativeIpcKey(Type type)
noexcept
47 Q_IMPLICIT QNativeIpcKey(
const QString &k, Type type = DefaultTypeForOs)
48 : key(k), typeAndFlags{type}
52 QNativeIpcKey(
const QNativeIpcKey &other)
53 : d(other.d), key(other.key), typeAndFlags(other.typeAndFlags)
59 QNativeIpcKey(QNativeIpcKey &&other)
noexcept
60 : d(std::exchange(other.d,
nullptr)), key(std::move(other.key)),
61 typeAndFlags(std::move(other.typeAndFlags))
64 move_internal(std::move(other));
73 QNativeIpcKey &operator=(
const QNativeIpcKey &other)
75 typeAndFlags = other.typeAndFlags;
77 if (isSlowPath() || other.isSlowPath())
78 return assign_internal(other);
83 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QNativeIpcKey)
84 void swap(QNativeIpcKey &other)
noexcept
86 std::swap(d, other.d);
88 typeAndFlags.swap(other.typeAndFlags);
91 bool isEmpty()
const noexcept
96 bool isValid()
const noexcept
98 return type() != Type{};
101 constexpr Type type()
const noexcept
103 return typeAndFlags.type;
106 constexpr void setType(Type type)
109 return setType_internal(type);
110 typeAndFlags.type = type;
113 QString nativeKey()
const noexcept
117 void setNativeKey(
const QString &newKey)
121 setNativeKey_internal(newKey);
124 Q_CORE_EXPORT QString toString()
const;
125 Q_CORE_EXPORT
static QNativeIpcKey fromString(
const QString &string);
128 struct TypeAndFlags {
129 Type type = DefaultTypeForOs;
130 quint16 reserved1 = {};
131 quint32 reserved2 = {};
133 void swap(TypeAndFlags &other)
noexcept
135 std::swap(type, other.type);
136 std::swap(reserved1, other.reserved1);
137 std::swap(reserved2, other.reserved2);
140 friend constexpr bool operator==(
const TypeAndFlags &lhs,
const TypeAndFlags &rhs)
noexcept
142 return lhs.type == rhs.type &&
143 lhs.reserved1 == rhs.reserved1 &&
144 lhs.reserved2 == rhs.reserved2;
148 QNativeIpcKeyPrivate *d =
nullptr;
150 TypeAndFlags typeAndFlags;
152 friend class QNativeIpcKeyPrivate;
153 constexpr bool isSlowPath()
const noexcept
154 {
return Q_UNLIKELY(d); }
157 friend size_t qHash(
const QNativeIpcKey &ipcKey, size_t seed = 0)
noexcept {
return 0; }
159 friend Q_CORE_EXPORT size_t qHash(
const QNativeIpcKey &ipcKey, size_t seed)
noexcept;
160 friend size_t qHash(
const QNativeIpcKey &ipcKey)
noexcept
161 {
return qHash(ipcKey, 0); }
164 Q_CORE_EXPORT
void copy_internal(
const QNativeIpcKey &other);
165 Q_CORE_EXPORT
void move_internal(QNativeIpcKey &&other)
noexcept;
166 Q_CORE_EXPORT QNativeIpcKey &assign_internal(
const QNativeIpcKey &other);
167 Q_CORE_EXPORT
void destroy_internal()
noexcept;
168 Q_CORE_EXPORT
void setType_internal(Type);
169 Q_CORE_EXPORT
void setNativeKey_internal(
const QString &);
170 Q_DECL_PURE_FUNCTION Q_CORE_EXPORT
static int
171 compare_internal(
const QNativeIpcKey &lhs,
const QNativeIpcKey &rhs)
noexcept;
174 Q_DECL_CONST_FUNCTION Q_CORE_EXPORT
static Type defaultTypeForOs_internal()
noexcept;
176 friend bool comparesEqual(
const QNativeIpcKey &lhs,
const QNativeIpcKey &rhs)
noexcept
178 if (!(lhs.typeAndFlags == rhs.typeAndFlags))
180 if (lhs.key != rhs.key)
184 return compare_internal(lhs, rhs) == 0;
186 Q_DECLARE_EQUALITY_COMPARABLE(QNativeIpcKey)
190Q_DECLARE_SHARED(QNativeIpcKey)
192inline auto QNativeIpcKey::legacyDefaultTypeForOs()
noexcept -> Type
195 return Type::Windows;
196#elif defined(QT_POSIX_IPC)
197 return Type::PosixRealtime;
198#elif defined(Q_OS_DARWIN)
199 return defaultTypeForOs_internal();
201 return Type::SystemV;
Combined button and popup list for selecting options.