AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
Assert.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include <cassert>
   15#include "AUI/api.h"
   16#include "AUI/Util/APreprocessor.h"
   17
   18//NOLINTBEGIN(modernize-*,cppcoreguidelines-macro-usage,bugprone-macro-parentheses)
   19
   20namespace aui::assertion::detail {
   21    inline void checkArgs(bool cond, const char* what = nullptr) {}
   22
   23    API_AUI_CORE void triggerAssertion(const char* message);
   24}
   25
   26
   27
   28#if AUI_DEBUG
   29#define AUI_IMPL_ASSERT(cond) assert(cond); ::aui::assertion::detail::checkArgs(cond)
   30#define AUI_IMPL_ASSERTX(cond, what) assert((cond) && what); ::aui::assertion::detail::checkArgs(cond, what)
   31#define AUI_IMPL_FAIL(what) assert(false && what); ::aui::assertion::detail::checkArgs(false, what)
   32#else
   33#define AUI_IMPL_ASSERT(cond) if (!(cond)) ::aui::assertion::detail::triggerAssertion("assertion failed: " AUI_PP_STRINGIZE(cond))
   34#define AUI_IMPL_ASSERTX(cond, what) if (!(cond)) ::aui::assertion::detail::triggerAssertion("assertion failed: " AUI_PP_STRINGIZE(cond) ": " what); ::aui::assertion::detail::checkArgs(cond, what)
   35#define AUI_IMPL_FAIL(what) ::aui::assertion::detail::triggerAssertion(what); ::aui::assertion::detail::checkArgs(false, what)
   36#endif
   37
   55#define AUI_ASSERT(condition) AUI_IMPL_ASSERT(condition)
   56
   74#define AUI_ASSERTX(condition, what) AUI_IMPL_ASSERTX(condition, what)
   75
   94#define AUI_ASSERT_NO_CONDITION(what) AUI_IMPL_FAIL(what)
   95
   96//NOLINTEND(modernize-*,cppcoreguidelines-macro-usage,bugprone-macro-parentheses)