File indexing completed on 2025-09-14 09:02:52
0001
0002
0003
0004 #ifndef QTCLASSHELPERMACROS_H
0005 #define QTCLASSHELPERMACROS_H
0006
0007 #include <QtCore/qtconfigmacros.h>
0008
0009 #if 0
0010 #pragma qt_class(QtClassHelperMacros)
0011 #pragma qt_sync_stop_processing
0012 #endif
0013
0014 QT_BEGIN_NAMESPACE
0015
0016 #if defined(__cplusplus)
0017
0018
0019
0020
0021
0022
0023 #define Q_DISABLE_COPY(Class) \
0024 Class(const Class &) = delete;\
0025 Class &operator=(const Class &) = delete;
0026
0027 #define Q_DISABLE_COPY_MOVE(Class) \
0028 Q_DISABLE_COPY(Class) \
0029 Class(Class &&) = delete; \
0030 Class &operator=(Class &&) = delete;
0031
0032 #define Q_DISABLE_COPY_X(Class, reason) \
0033 Class(const Class &) Q_DECL_EQ_DELETE_X(reason);\
0034 Class &operator=(const Class &) Q_DECL_EQ_DELETE_X(reason);
0035
0036 #define Q_DISABLE_COPY_MOVE_X(Class, reason) \
0037 Q_DISABLE_COPY_X(Class, reason) \
0038 Class(Class &&) Q_DECL_EQ_DELETE_X(reason); \
0039 Class &operator=(Class &&) Q_DECL_EQ_DELETE_X(reason);
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 #define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Class) \
0074 Class &operator=(Class &&other) noexcept { \
0075 Class moved(std::move(other)); \
0076 swap(moved); \
0077 return *this; \
0078 }
0079
0080 #define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class) \
0081 Class &operator=(Class &&other) noexcept { \
0082 swap(other); \
0083 return *this; \
0084 }
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 #define QT_DECLARE_RO5_SMF_AS_DEFAULTED(Class) \
0105 ~Class() = default; \
0106 Class(const Class &) = default; \
0107 Class(Class &&) = default; \
0108 Class &operator=(const Class &) = default; \
0109 Class &operator=(Class &&) = default;
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129 #define QT_DEFINE_TAG_STRUCT(TAG) \
0130 struct TAG { explicit TAG () = default; }
0131 #define QT_DEFINE_TAG(TAG) \
0132 constexpr QT_DEFINE_TAG_STRUCT(TAG ## _t) TAG{}
0133
0134
0135 template <typename T> inline T *qGetPtrHelper(T *ptr) noexcept { return ptr; }
0136 template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype(ptr.get())
0137 { static_assert(noexcept(ptr.get()), "Smart d pointers for Q_DECLARE_PRIVATE must have noexcept get()"); return ptr.get(); }
0138
0139 class QObject;
0140 class QObjectPrivate;
0141 namespace QtPrivate {
0142 template <typename ObjPrivate> void assertObjectType(QObjectPrivate *d);
0143 inline const QObject *getQObject(const QObjectPrivate *d);
0144 }
0145
0146 #define Q_DECLARE_PRIVATE(Class) \
0147 inline Class##Private* d_func() noexcept \
0148 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr));) } \
0149 inline const Class##Private* d_func() const noexcept \
0150 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));) } \
0151 friend class Class##Private;
0152
0153 #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
0154 inline Class##Private* d_func() noexcept \
0155 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr));) } \
0156 inline const Class##Private* d_func() const noexcept \
0157 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr));) } \
0158 friend class Class##Private;
0159
0160 #define Q_DECLARE_PUBLIC(Class) \
0161 inline Class* q_func() noexcept { return static_cast<Class *>(q_ptr); } \
0162 inline const Class* q_func() const noexcept { return static_cast<const Class *>(q_ptr); } \
0163 friend class Class; \
0164 friend const QObject *QtPrivate::getQObject(const QObjectPrivate *d); \
0165 template <typename ObjPrivate> friend void QtPrivate::assertObjectType(QObjectPrivate *d);
0166
0167 #define Q_D(Class) Class##Private * const d = d_func()
0168 #define Q_Q(Class) Class * const q = q_func()
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207 #define Q_DECLARE_SHARED(TYPE) \
0208 QT_DECLARE_ADL_SWAP(TYPE) \
0209 Q_DECLARE_TYPEINFO(TYPE, Q_RELOCATABLE_TYPE); \
0210
0211
0212 #define Q_DECLARE_SHARED_NS(NS, TYPE) \
0213 QT_DECLARE_ADL_SWAP(TYPE) \
0214 } \
0215 Q_DECLARE_TYPEINFO(NS :: TYPE, Q_RELOCATABLE_TYPE); \
0216 namespace NS { \
0217
0218
0219 #define Q_DECLARE_SHARED_NS_EXT(NS, TYPE) \
0220 namespace NS { \
0221 QT_DECLARE_ADL_SWAP(TYPE) \
0222 } \
0223 Q_DECLARE_TYPEINFO(NS :: TYPE, Q_RELOCATABLE_TYPE); \
0224
0225
0226 #define QT_DECLARE_ADL_SWAP(TYPE) \
0227 inline void swap(TYPE &value1, TYPE &value2) \
0228 noexcept(noexcept(value1.swap(value2))) \
0229 { value1.swap(value2); }
0230
0231 #endif
0232
0233 QT_END_NAMESPACE
0234
0235 #endif