8#include <QtCore/qglobal.h>
9#include <QtCore/qtcore-config.h>
11#if QT_CONFIG(sharedmemory) || QT_CONFIG(systemsemaphore)
12# include <QtCore/qstring.h>
13# include <QtCore/qobjectdefs.h>
17class QNativeIpcKeyPrivate;
20 Q_GADGET_EXPORT(Q_CORE_EXPORT)
22 enum class Type : quint16 {
27 PosixRealtime = 0x100,
32 static constexpr Type DefaultTypeForOs =
39 static Type legacyDefaultTypeForOs()
noexcept;
41 constexpr QNativeIpcKey()
noexcept =
default;
43 explicit constexpr QNativeIpcKey(Type type)
noexcept
48 Q_IMPLICIT QNativeIpcKey(
const QString &k, Type type = DefaultTypeForOs)
49 : key(k), typeAndFlags{type}
53 QNativeIpcKey(
const QNativeIpcKey &other)
54 : d(other.d), key(other.key), typeAndFlags(other.typeAndFlags)
60 QNativeIpcKey(QNativeIpcKey &&other)
noexcept
61 : d(std::exchange(other.d,
nullptr)), key(std::move(other.key)),
62 typeAndFlags(std::move(other.typeAndFlags))
65 move_internal(std::move(other));
74 QNativeIpcKey &operator=(
const QNativeIpcKey &other)
76 typeAndFlags = other.typeAndFlags;
78 if (isSlowPath() || other.isSlowPath())
79 return assign_internal(other);
84 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QNativeIpcKey)
85 void swap(QNativeIpcKey &other)
noexcept
87 std::swap(d, other.d);
89 typeAndFlags.swap(other.typeAndFlags);
92 bool isEmpty()
const noexcept
97 bool isValid()
const noexcept
99 return type() != Type{};
102 constexpr Type type()
const noexcept
104 return typeAndFlags.type;
107 constexpr void setType(Type type)
110 return setType_internal(type);
111 typeAndFlags.type = type;
114 QString nativeKey()
const noexcept
118 void setNativeKey(
const QString &newKey)
122 setNativeKey_internal(newKey);
125 Q_CORE_EXPORT QString toString()
const;
126 Q_CORE_EXPORT
static QNativeIpcKey fromString(
const QString &string);
129 struct TypeAndFlags {
130 Type type = DefaultTypeForOs;
131 quint16 reserved1 = {};
132 quint32 reserved2 = {};
134 void swap(TypeAndFlags &other)
noexcept
136 std::swap(type, other.type);
137 std::swap(reserved1, other.reserved1);
138 std::swap(reserved2, other.reserved2);
141 friend constexpr bool operator==(
const TypeAndFlags &lhs,
const TypeAndFlags &rhs)
noexcept
143 return lhs.type == rhs.type &&
144 lhs.reserved1 == rhs.reserved1 &&
145 lhs.reserved2 == rhs.reserved2;
149 QNativeIpcKeyPrivate *d =
nullptr;
151 TypeAndFlags typeAndFlags;
153 friend class QNativeIpcKeyPrivate;
154 constexpr bool isSlowPath()
const noexcept
155 {
return Q_UNLIKELY(d); }
158 friend size_t qHash(
const QNativeIpcKey &ipcKey, size_t seed = 0)
noexcept {
return 0; }
160 friend Q_CORE_EXPORT size_t qHash(
const QNativeIpcKey &ipcKey, size_t seed)
noexcept;
161 friend size_t qHash(
const QNativeIpcKey &ipcKey)
noexcept
162 {
return qHash(ipcKey, 0); }
165 Q_CORE_EXPORT
void copy_internal(
const QNativeIpcKey &other);
166 Q_CORE_EXPORT
void move_internal(QNativeIpcKey &&other)
noexcept;
167 Q_CORE_EXPORT QNativeIpcKey &assign_internal(
const QNativeIpcKey &other);
168 Q_CORE_EXPORT
void destroy_internal()
noexcept;
169 Q_CORE_EXPORT
void setType_internal(Type);
170 Q_CORE_EXPORT
void setNativeKey_internal(
const QString &);
171 Q_DECL_PURE_FUNCTION Q_CORE_EXPORT
static int
172 compare_internal(
const QNativeIpcKey &lhs,
const QNativeIpcKey &rhs)
noexcept;
175 Q_DECL_CONST_FUNCTION Q_CORE_EXPORT
static Type defaultTypeForOs_internal()
noexcept;
177 friend bool comparesEqual(
const QNativeIpcKey &lhs,
const QNativeIpcKey &rhs)
noexcept
179 if (!(lhs.typeAndFlags == rhs.typeAndFlags))
181 if (lhs.key != rhs.key)
185 return compare_internal(lhs, rhs) == 0;
187 Q_DECLARE_EQUALITY_COMPARABLE(QNativeIpcKey)
191Q_DECLARE_SHARED(QNativeIpcKey)
193inline auto QNativeIpcKey::legacyDefaultTypeForOs()
noexcept -> Type
196 return Type::Windows;
197#elif defined(QT_POSIX_IPC)
198 return Type::PosixRealtime;
199#elif defined(Q_OS_DARWIN)
200 return defaultTypeForOs_internal();
202 return Type::SystemV;
Combined button and popup list for selecting options.