| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QSSGASSERT_P_H |
| 5 | #define QSSGASSERT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qglobal.h> |
| 19 | #include <QtQuick3DUtils/qtquick3dutilsexports.h> |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | Q_QUICK3DUTILS_EXPORT void qssgWriteAssertLocation(const char *msg); |
| 24 | |
| 25 | QT_END_NAMESPACE |
| 26 | |
| 27 | #ifdef QT_DEBUG |
| 28 | #define QSSG_DEBUG_COND(cond) (cond) |
| 29 | #else |
| 30 | #define QSSG_DEBUG_COND(cond) (true || (cond)) |
| 31 | #endif // QT_DEBUG |
| 32 | |
| 33 | #define QSSG_ASSERT_STRINGIFY_HELPER(x) #x |
| 34 | #define QSSG_ASSERT_STRINGIFY(x) QSSG_ASSERT_STRINGIFY_HELPER(x) |
| 35 | #define QSSG_ASSERT_STRING_X(msg) QT_PREPEND_NAMESPACE(qssgWriteAssertLocation)(msg) |
| 36 | #define QSSG_ASSERT_STRING(cond) QSSG_ASSERT_STRING_X(\ |
| 37 | "\"" cond"\" in file " __FILE__ ", line " QSSG_ASSERT_STRINGIFY(__LINE__)) |
| 38 | |
| 39 | // The 'do {...} while (0)' idiom is not used for the main block here to be |
| 40 | // able to use 'break' and 'continue' as 'actions'. |
| 41 | |
| 42 | #define QSSG_ASSERT(cond, action) if (Q_LIKELY(cond)) {} else { QSSG_ASSERT_STRING(#cond); action; } do {} while (0) |
| 43 | #define QSSG_ASSERT_X(cond, msg, action) if (Q_LIKELY(cond)) {} else { QSSG_ASSERT_STRING_X(msg); action; } do {} while (0) |
| 44 | #define QSSG_CHECK(cond) if (Q_LIKELY(cond)) {} else { QSSG_ASSERT_STRING(#cond); } do {} while (0) |
| 45 | #define QSSG_CHECK_X(cond, msg) if (Q_LIKELY(cond)) {} else { QSSG_ASSERT_STRING_X(msg); } do {} while (0) |
| 46 | #define QSSG_GUARD(cond) ((Q_LIKELY(cond)) ? true : (QSSG_ASSERT_STRING(#cond), false)) |
| 47 | #define QSSG_GUARD_X(cond, msg) ((Q_LIKELY(cond)) ? true : (QSSG_ASSERT_STRING_X(msg), false)) |
| 48 | |
| 49 | #endif // QSSGASSERT_P_H |
| 50 | |