File indexing completed on 2026-08-04 09:21:28
0001
0002
0003
0004
0005 #ifndef QTCLASSHELPERMACROS_H
0006 #define QTCLASSHELPERMACROS_H
0007
0008 #include <QtCore/qtconfigmacros.h>
0009
0010 #if 0
0011 #pragma qt_class(QtClassHelperMacros)
0012 #pragma qt_sync_stop_processing
0013 #endif
0014
0015 QT_BEGIN_NAMESPACE
0016
0017 #if defined(__cplusplus)
0018
0019
0020
0021
0022
0023
0024 #define Q_DISABLE_COPY(Class) \
0025 Class(const Class &) = delete;\
0026 Class &operator=(const Class &) = delete;
0027
0028 #define Q_DISABLE_COPY_MOVE(Class) \
0029 Q_DISABLE_COPY(Class) \
0030 Class(Class &&) = delete; \
0031 Class &operator=(Class &&) = delete;
0032
0033 #define Q_DISABLE_COPY_X(Class, reason) \
0034 Class(const Class &) Q_DECL_EQ_DELETE_X(reason);\
0035 Class &operator=(const Class &) Q_DECL_EQ_DELETE_X(reason);
0036
0037 #define Q_DISABLE_COPY_MOVE_X(Class, reason) \
0038 Q_DISABLE_COPY_X(Class, reason) \
0039 Class(Class &&) Q_DECL_EQ_DELETE_X(reason); \
0040 Class &operator=(Class &&) Q_DECL_EQ_DELETE_X(reason);
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
0074 #define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Class) \
0075 Class &operator=(Class &&other) noexcept { \
0076 Class moved(std::move(other)); \
0077 swap(moved); \
0078 return *this; \
0079 }
0080
0081 #define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class) \
0082 Class &operator=(Class &&other) noexcept { \
0083 swap(other); \
0084 return *this; \
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 #define QT_DECLARE_RO5_SMF_AS_DEFAULTED(Class) \
0106 ~Class() = default; \
0107 Class(const Class &) = default; \
0108 Class(Class &&) = default; \
0109 Class &operator=(const Class &) = default; \
0110 Class &operator=(Class &&) = default;
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 #define QT_DEFINE_TAG_STRUCT(TAG) \
0131 struct TAG { explicit TAG () = default; }
0132 #define QT_DEFINE_TAG(TAG) \
0133 constexpr QT_DEFINE_TAG_STRUCT(TAG ## _t) TAG{}
0134
0135
0136 template <typename T> inline T *qGetPtrHelper(T *ptr) noexcept { return ptr; }
0137 template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype(ptr.get())
0138 { static_assert(noexcept(ptr.get()), "Smart d pointers for Q_DECLARE_PRIVATE must have noexcept get()"); return ptr.get(); }
0139
0140 class QObject;
0141 class QObjectPrivate;
0142 namespace QtPrivate {
0143 template <typename ObjPrivate> void assertObjectType(QObjectPrivate *d);
0144 inline const QObject *getQObject(const QObjectPrivate *d);
0145 }
0146
0147 #define Q_DECLARE_PRIVATE(Class) \
0148 inline Class##Private* d_func() noexcept \
0149 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr));) } \
0150 inline const Class##Private* d_func() const noexcept \
0151 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));) } \
0152 friend class Class##Private;
0153
0154 #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
0155 inline Class##Private* d_func() noexcept \
0156 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr));) } \
0157 inline const Class##Private* d_func() const noexcept \
0158 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr));) } \
0159 friend class Class##Private;
0160
0161 #define Q_DECLARE_PUBLIC(Class) \
0162 inline Class* q_func() noexcept { return static_cast<Class *>(q_ptr); } \
0163 inline const Class* q_func() const noexcept { return static_cast<const Class *>(q_ptr); } \
0164 friend class Class; \
0165 friend const QObject *QtPrivate::getQObject(const QObjectPrivate *d); \
0166 template <typename ObjPrivate> friend void QtPrivate::assertObjectType(QObjectPrivate *d);
0167
0168 #define Q_D(Class) Class##Private * const d = d_func()
0169 #define Q_Q(Class) Class * const q = q_func()
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
0208 #define Q_DECLARE_SHARED(TYPE) \
0209 QT_DECLARE_ADL_SWAP(TYPE) \
0210 Q_DECLARE_TYPEINFO(TYPE, Q_RELOCATABLE_TYPE); \
0211
0212
0213 #define Q_DECLARE_SHARED_NS(NS, TYPE) \
0214 QT_DECLARE_ADL_SWAP(TYPE) \
0215 } \
0216 Q_DECLARE_TYPEINFO(NS :: TYPE, Q_RELOCATABLE_TYPE); \
0217 namespace NS { \
0218
0219
0220 #define Q_DECLARE_SHARED_NS_EXT(NS, TYPE) \
0221 namespace NS { \
0222 QT_DECLARE_ADL_SWAP(TYPE) \
0223 } \
0224 Q_DECLARE_TYPEINFO(NS :: TYPE, Q_RELOCATABLE_TYPE); \
0225
0226
0227 #define QT_DECLARE_ADL_SWAP(TYPE) \
0228 inline void swap(TYPE &value1, TYPE &value2) \
0229 noexcept(noexcept(value1.swap(value2))) \
0230 { value1.swap(value2); }
0231
0232 #endif
0233
0234 QT_END_NAMESPACE
0235
0236 #endif