Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
Assert.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** Assert.hpp
6*/
7
8/*
9** MIT License
10**
11** Copyright (c) 2025 Robin Toillon
12**
13** Permission is hereby granted, free of charge, to any person obtaining
14** a copy of this software and associated documentation files (the
15** "Software"), to deal in the Software without restriction, including
16** without limitation the rights to use, copy, modify, merge, publish,
17** distribute, sublicense, and/or sell copies of the Software, and to
18** permit persons to whom the Software is furnished to do so, subject to
19** the following conditions:
20**
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
23**
24** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31*/
32
41#ifndef RTYPE_ASSERT_HPP_
42 #define RTYPE_ASSERT_HPP_
43
44 #include "RType/Logger.hpp"
45 #include <cstdlib>
46
56 #if defined(_MSC_VER)
57 #define RTP_DEBUG_BREAK() __debugbreak()
58 #elif defined(__GNUC__) || defined(__clang__)
59 #define RTP_DEBUG_BREAK() __builtin_trap()
60 #else
61 #define RTP_DEBUG_BREAK() std::abort()
62 #endif
63
64 #ifdef NDEBUG
78 #ifdef __cpp_attribute_assume
79 #define RTP_ASSERT(condition, ...) [[assume(condition)]]
80 #else
81 #define RTP_ASSERT(condition, ...) ((void)0)
82 #endif
83
94 #define RTP_VERIFY(condition, msg, ...) \
95 do { \
96 if (!(condition)) [[unlikely]] { \
97 rtp::log::error("Verify failed: " msg, ##__VA_ARGS__); \
98 } \
99 } while(0)
100
101 #else
113 #define RTP_ASSERT(condition, msg, ...) \
114 do { \
115 if (!(condition)) [[unlikely]] { \
116 rtp::log::fatal("ASSERTION FAILED: " msg, ##__VA_ARGS__); \
117 RTP_DEBUG_BREAK(); \
118 } \
119 } while(0)
120
130 #define RTP_VERIFY(condition, msg, ...) \
131 RTP_ASSERT(condition, msg, ##__VA_ARGS__)
132
133 #endif
134
135#endif /* !RTYPE_ASSERT_HPP_ */
Logger declaration with support for multiple log levels.