File indexing completed on 2024-05-12 03:48:29

0001 /*
0002     SPDX-FileCopyrightText: 2006-2011 the LibQxt project <http://libqxt.org, foundation@libqxt.org>
0003     SPDX-FileCopyrightText: 2006-2008 Adam Higerd
0004     SPDX-License-Identifier: BSD-3-Clause
0005 */
0006 
0007 #ifndef QXTGLOBAL_H
0008 #define QXTGLOBAL_H
0009 
0010 #include <QtGlobal>
0011 
0012 #define QXT_VERSION 0x000700
0013 #define QXT_VERSION_STR "0.7.0"
0014 
0015 //--------------------------global macros------------------------------
0016 
0017 #ifndef QXT_NO_MACROS
0018 
0019 #ifndef _countof
0020 #define _countof(x) (sizeof(x) / sizeof(*x))
0021 #endif
0022 
0023 #endif // QXT_NO_MACROS
0024 
0025 //--------------------------export macros------------------------------
0026 
0027 #define QXT_DLLEXPORT DO_NOT_USE_THIS_ANYMORE
0028 
0029 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0030 #if defined(BUILD_QXT_CORE)
0031 #define QXT_CORE_EXPORT Q_DECL_EXPORT
0032 #else
0033 #define QXT_CORE_EXPORT Q_DECL_IMPORT
0034 #endif
0035 #else
0036 #define QXT_CORE_EXPORT
0037 #endif // BUILD_QXT_CORE
0038 
0039 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0040 #if defined(BUILD_QXT_GUI)
0041 #define QXT_GUI_EXPORT Q_DECL_EXPORT
0042 #else
0043 #define QXT_GUI_EXPORT Q_DECL_IMPORT
0044 #endif
0045 #else
0046 #define QXT_GUI_EXPORT
0047 #endif // BUILD_QXT_GUI
0048 
0049 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0050 #if defined(BUILD_QXT_NETWORK)
0051 #define QXT_NETWORK_EXPORT Q_DECL_EXPORT
0052 #else
0053 #define QXT_NETWORK_EXPORT Q_DECL_IMPORT
0054 #endif
0055 #else
0056 #define QXT_NETWORK_EXPORT
0057 #endif // BUILD_QXT_NETWORK
0058 
0059 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0060 #if defined(BUILD_QXT_SQL)
0061 #define QXT_SQL_EXPORT Q_DECL_EXPORT
0062 #else
0063 #define QXT_SQL_EXPORT Q_DECL_IMPORT
0064 #endif
0065 #else
0066 #define QXT_SQL_EXPORT
0067 #endif // BUILD_QXT_SQL
0068 
0069 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0070 #if defined(BUILD_QXT_WEB)
0071 #define QXT_WEB_EXPORT Q_DECL_EXPORT
0072 #else
0073 #define QXT_WEB_EXPORT Q_DECL_IMPORT
0074 #endif
0075 #else
0076 #define QXT_WEB_EXPORT
0077 #endif // BUILD_QXT_WEB
0078 
0079 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0080 #if defined(BUILD_QXT_BERKELEY)
0081 #define QXT_BERKELEY_EXPORT Q_DECL_EXPORT
0082 #else
0083 #define QXT_BERKELEY_EXPORT Q_DECL_IMPORT
0084 #endif
0085 #else
0086 #define QXT_BERKELEY_EXPORT
0087 #endif // BUILD_QXT_BERKELEY
0088 
0089 #if !defined(QXT_STATIC) && !defined(QXT_DOXYGEN_RUN)
0090 #if defined(BUILD_QXT_ZEROCONF)
0091 #define QXT_ZEROCONF_EXPORT Q_DECL_EXPORT
0092 #else
0093 #define QXT_ZEROCONF_EXPORT Q_DECL_IMPORT
0094 #endif
0095 #else
0096 #define QXT_ZEROCONF_EXPORT
0097 #endif // QXT_ZEROCONF_EXPORT
0098 
0099 #if defined(BUILD_QXT_CORE) || defined(BUILD_QXT_GUI) || defined(BUILD_QXT_SQL) || defined(BUILD_QXT_NETWORK) || defined(BUILD_QXT_WEB)                        \
0100     || defined(BUILD_QXT_BERKELEY) || defined(BUILD_QXT_ZEROCONF)
0101 #define BUILD_QXT
0102 #endif
0103 
0104 QXT_CORE_EXPORT const char* qxtVersion();
0105 
0106 #ifndef QT_BEGIN_NAMESPACE
0107 #define QT_BEGIN_NAMESPACE
0108 #endif
0109 
0110 #ifndef QT_END_NAMESPACE
0111 #define QT_END_NAMESPACE
0112 #endif
0113 
0114 #ifndef QT_FORWARD_DECLARE_CLASS
0115 #define QT_FORWARD_DECLARE_CLASS(Class) class Class;
0116 #endif
0117 
0118 #define QXT_DECLARE_PRIVATE(PUB)                                                                                                                               \
0119     friend class PUB##Private;                                                                                                                                 \
0120     QxtPrivateInterface<PUB, PUB##Private> qxt_d;
0121 #define QXT_DECLARE_PUBLIC(PUB) friend class PUB;
0122 #define QXT_INIT_PRIVATE(PUB) qxt_d.setPublic(this);
0123 #define QXT_D(PUB) PUB##Private& d = qxt_d()
0124 #define QXT_P(PUB) PUB& p = qxt_p()
0125 
0126 template<typename PUB>
0127 class QxtPrivate {
0128 public:
0129     virtual ~QxtPrivate() = default;
0130     inline void QXT_setPublic(PUB* pub) {
0131         qxt_p_ptr = pub;
0132     }
0133 
0134 protected:
0135     inline PUB& qxt_p() {
0136         return *qxt_p_ptr;
0137     }
0138     inline const PUB& qxt_p() const {
0139         return *qxt_p_ptr;
0140     }
0141     inline PUB* qxt_ptr() {
0142         return qxt_p_ptr;
0143     }
0144     inline const PUB* qxt_ptr() const {
0145         return qxt_p_ptr;
0146     }
0147 
0148 private:
0149     PUB* qxt_p_ptr;
0150 };
0151 
0152 template<typename PUB, typename PVT>
0153 class QxtPrivateInterface {
0154     friend class QxtPrivate<PUB>;
0155 
0156 public:
0157     QxtPrivateInterface() {
0158         pvt = new PVT;
0159     }
0160     ~QxtPrivateInterface() {
0161         delete pvt;
0162     }
0163 
0164     inline void setPublic(PUB* pub) {
0165         pvt->QXT_setPublic(pub);
0166     }
0167     inline PVT& operator()() {
0168         return *static_cast<PVT*>(pvt);
0169     }
0170     inline const PVT& operator()() const {
0171         return *static_cast<PVT*>(pvt);
0172     }
0173     inline PVT* operator->() {
0174         return static_cast<PVT*>(pvt);
0175     }
0176     inline const PVT* operator->() const {
0177         return static_cast<PVT*>(pvt);
0178     }
0179 
0180 private:
0181     QxtPrivateInterface(const QxtPrivateInterface&) {
0182     }
0183     QxtPrivateInterface& operator=(const QxtPrivateInterface& i) {
0184         return i;
0185     }
0186     QxtPrivate<PUB>* pvt;
0187 };
0188 
0189 #endif // QXT_GLOBAL