sculpto
assert.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file assert.h
3 * \brief Assertion macros definition module.
4 *
5 * \author Sabitov Kirill
6 * \date 18 June 2022
7 *********************************************************************/
8
9#pragma once
10
13
15#ifdef _DEBUG
16# if defined(SCL_PLATFORM_WINDOWS)
17# define SCL_DEBUGBREAK() __debugbreak()
18# elif defined(SCL_PLATFORM_LINUX)
19# include <signal.h>
20# define SCL_DEBUGBREAK() raise(SIGTRAP)
21# else
22# error "Platform doesn't support debugbreak yet!"
23#endif
24# define SCL_ENABLE_ASSERTS
25#else
26# define SCL_DEBUGBREAK()
27#endif
28
29#ifdef SCL_ASSERTION_ENABLED
30# ifdef SCL_PLATFORM_WINDOWS
31# include <intrin.h>
32# endif
33 /*!*
34 * Core module assertion function.
35 *
36 * \param Expr - expression to be calculated.
37 * If 0 - assertion message showed in logger and debug break occures.
38 * \param Msg - message to be displayed in case of assertion faield.
39 * \return None.
40 */
41# define SCL_CORE_ASSERT(Expr, ...) \
42 { \
43 if (!(Expr)) \
44 { \
45 SCL_CORE_ERROR(__VA_ARGS__); \
46 SCL_DEBUGBREAK(); \
47 } \
48 }
49
50
51 /*!*
52 * Assertion function.
53 *
54 * \param Expr - expression to be calculated.
55 * If 0 - assertion message showed in logger and debug break occures.
56 * \param Msg - message to be displayed in case of assertion faield.
57 * \return None.
58 */
59# define SCL_ASSERT(Expr, ...) \
60 { \
61 if (!(Expr)) \
62 { \
63 SCL_ERROR(__VA_ARGS__); \
64 SCL_DEBUGBREAK(); \
65 } \
66 }
67
68#else
69# define SCL_CORE_ASSERT(expr, ...) (expr)
70# define SCL_ASSERT(expr, ...) (expr)
71#endif