File indexing completed on 2025-01-18 10:07:39
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
0033
0034
0035
0036
0037
0038
0039
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 #define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(Class) \
0065 Class &operator=(Class &&other) noexcept { \
0066 Class moved(std::move(other)); \
0067 swap(moved); \
0068 return *this; \
0069 }
0070
0071 #define QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(Class) \
0072 Class &operator=(Class &&other) noexcept { \
0073 swap(other); \
0074 return *this; \
0075 }
0076
0077 template <typename T> inline T *qGetPtrHelper(T *ptr) noexcept { return ptr; }
0078 template <typename Ptr> inline auto qGetPtrHelper(Ptr &ptr) noexcept -> decltype(ptr.get())
0079 { static_assert(noexcept(ptr.get()), "Smart d pointers for Q_DECLARE_PRIVATE must have noexcept get()"); return ptr.get(); }
0080
0081 class QObject;
0082 class QObjectPrivate;
0083 namespace QtPrivate {
0084 template <typename ObjPrivate> void assertObjectType(QObjectPrivate *d);
0085 inline const QObject *getQObject(const QObjectPrivate *d);
0086 }
0087
0088 #define Q_DECLARE_PRIVATE(Class) \
0089 inline Class##Private* d_func() noexcept \
0090 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr));) } \
0091 inline const Class##Private* d_func() const noexcept \
0092 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr));) } \
0093 friend class Class##Private;
0094
0095 #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
0096 inline Class##Private* d_func() noexcept \
0097 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr));) } \
0098 inline const Class##Private* d_func() const noexcept \
0099 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr));) } \
0100 friend class Class##Private;
0101
0102 #define Q_DECLARE_PUBLIC(Class) \
0103 inline Class* q_func() noexcept { return static_cast<Class *>(q_ptr); } \
0104 inline const Class* q_func() const noexcept { return static_cast<const Class *>(q_ptr); } \
0105 friend class Class; \
0106 friend const QObject *QtPrivate::getQObject(const QObjectPrivate *d); \
0107 template <typename ObjPrivate> friend void QtPrivate::assertObjectType(QObjectPrivate *d);
0108
0109 #define Q_D(Class) Class##Private * const d = d_func()
0110 #define Q_Q(Class) Class * const q = q_func()
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 #define Q_DECLARE_SHARED(TYPE) \
0123 Q_DECLARE_TYPEINFO(TYPE, Q_RELOCATABLE_TYPE); \
0124 inline void swap(TYPE &value1, TYPE &value2) \
0125 noexcept(noexcept(value1.swap(value2))) \
0126 { value1.swap(value2); }
0127
0128 #endif
0129
0130 QT_END_NAMESPACE
0131
0132 #endif