// Copyright (C) 2020 The Qt Company Ltd. // Copyright (C) 2019 Intel Corporation. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QGLOBAL_H #define QGLOBAL_H #if 0 #pragma qt_class(QtGlobal) #endif #ifdef __cplusplus # include # include # include # include #endif #ifndef __ASSEMBLER__ # include # include # include #endif #include #ifdef QT_BOOTSTRAPPED #include #else #include #include #endif #include #include /* These two macros makes it possible to turn the builtin line expander into a * string literal. */ #define QT_STRINGIFY2(x) #x #define QT_STRINGIFY(x) QT_STRINGIFY2(x) inline void qt_noop(void) {} #include #include #include #include #include #include /* Avoid "unused parameter" warnings */ #define Q_UNUSED(x) (void)x; #ifndef __ASSEMBLER__ QT_BEGIN_NAMESPACE /* No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols for Qt's internal unit tests. If you want slower loading times and more symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL. */ #if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED) # define Q_AUTOTEST_EXPORT Q_DECL_EXPORT #elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED) # define Q_AUTOTEST_EXPORT Q_DECL_IMPORT #else # define Q_AUTOTEST_EXPORT #endif #define Q_INIT_RESOURCE(name) \ do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); \ QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (false) #define Q_CLEANUP_RESOURCE(name) \ do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); \ QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (false) /* * If we're compiling C++ code: * - and this is a non-namespace build, declare qVersion as extern "C" * - and this is a namespace build, declare it as a regular function * (we're already inside QT_BEGIN_NAMESPACE / QT_END_NAMESPACE) * If we're compiling C code, simply declare the function. If Qt was compiled * in a namespace, qVersion isn't callable anyway. */ #if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC) extern "C" #endif Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOEXCEPT; #if defined(__cplusplus) #ifndef Q_CONSTRUCTOR_FUNCTION # define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \ namespace { \ static const struct AFUNC ## _ctor_class_ { \ inline AFUNC ## _ctor_class_() { AFUNC(); } \ } AFUNC ## _ctor_instance_; \ } # define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC) #endif #ifndef Q_DESTRUCTOR_FUNCTION # define Q_DESTRUCTOR_FUNCTION0(AFUNC) \ namespace { \ static const struct AFUNC ## _dtor_class_ { \ inline AFUNC ## _dtor_class_() { } \ inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \ } AFUNC ## _dtor_instance_; \ } # define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC) #endif /* moc compats (signals/slots) */ #ifndef QT_MOC_COMPAT # define QT_MOC_COMPAT #else # undef QT_MOC_COMPAT # define QT_MOC_COMPAT #endif #ifdef QT_ASCII_CAST_WARNINGS # define QT_ASCII_CAST_WARN \ Q_DECL_DEPRECATED_X("Use fromUtf8, QStringLiteral, or QLatin1StringView") #else # define QT_ASCII_CAST_WARN #endif /* Utility macros and inline functions */ #ifndef Q_FORWARD_DECLARE_OBJC_CLASS # ifdef __OBJC__ # define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname # else # define Q_FORWARD_DECLARE_OBJC_CLASS(classname) class classname # endif #endif #ifndef Q_FORWARD_DECLARE_CF_TYPE # define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref #endif #ifndef Q_FORWARD_DECLARE_MUTABLE_CF_TYPE # define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref #endif #ifndef Q_FORWARD_DECLARE_CG_TYPE #define Q_FORWARD_DECLARE_CG_TYPE(type) typedef const struct type *type ## Ref; #endif #ifndef Q_FORWARD_DECLARE_MUTABLE_CG_TYPE #define Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) typedef struct type *type ## Ref; #endif #ifdef Q_OS_DARWIN // Implemented in qcore_mac_objc.mm class Q_CORE_EXPORT QMacAutoReleasePool { public: QMacAutoReleasePool(); ~QMacAutoReleasePool(); private: Q_DISABLE_COPY(QMacAutoReleasePool) void *pool; }; #endif // Q_OS_DARWIN Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() noexcept; /* Debugging and error handling */ #if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG) # define QT_DEBUG #endif #if 0 #pragma qt_class(QFunctionPointer) #endif typedef void (*QFunctionPointer)(); #if !defined(Q_UNIMPLEMENTED) # define Q_UNIMPLEMENTED() qWarning("Unimplemented code.") #endif QT_WARNING_PUSH // warning: noexcept-expression evaluates to 'false' because of a call to 'void swap(..., ...)' QT_WARNING_DISABLE_GCC("-Wnoexcept") namespace QtPrivate { namespace SwapExceptionTester { // insulate users from the "using std::swap" below using std::swap; // import std::swap template void checkSwap(T &t) noexcept(noexcept(swap(t, t))); // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator)) } } // namespace QtPrivate // Documented in ../tools/qalgorithm.qdoc template constexpr void qSwap(T &value1, T &value2) noexcept(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1))) { using std::swap; swap(value1, value2); } // pure compile-time micro-optimization for our own headers, so not documented: template constexpr inline void qt_ptr_swap(T* &lhs, T* &rhs) noexcept { T *tmp = lhs; lhs = rhs; rhs = tmp; } QT_WARNING_POP Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1); Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2); Q_CORE_EXPORT void qFreeAligned(void *ptr); // this adds const to non-const objects (like std::as_const) template constexpr typename std::add_const::type &qAsConst(T &t) noexcept { return t; } // prevent rvalue arguments: template void qAsConst(const T &&) = delete; // like std::exchange template constexpr T qExchange(T &t, U &&newValue) noexcept(std::conjunction_v, std::is_nothrow_assignable>) { T old = std::move(t); t = std::forward(newValue); return old; } // like std::to_underlying template constexpr std::underlying_type_t qToUnderlying(Enum e) noexcept { return static_cast>(e); } #define QT_MODULE(x) QT_END_NAMESPACE // We need to keep QTypeInfo, QSysInfo, QFlags, qDebug & family in qglobal.h for compatibility with Qt 4. // Be careful when changing the order of these files. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif /* __cplusplus */ #endif /* !__ASSEMBLER__ */ #endif /* QGLOBAL_H */