GPR5100 - Rollback
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1
4#pragma once
5
6#include <cstdlib>
7#include "utils/log.h"
8#include <fmt/format.h>
9
10namespace core
11{
12
17class AssertException final : public std::exception
18{
19public:
20 AssertException(std::string_view msg) : msg_(msg) {}
21 [[nodiscard]] const char* what() const noexcept override { return msg_.c_str(); }
22private:
23 std::string msg_;
24};
25
26}
27
28#ifdef GPR_ASSERT
29# ifdef GPR_ABORT
30#define gpr_assert(Expr, Msg) \
31 if(!(Expr)) \
32 { \
33 core::LogError(fmt::format("Assert failed:\t{}\nSource:\t\t{}, line {}", \
34 #Msg, __FILE__,__LINE__)); \
35 std::abort(); \
36 }
37# ifdef GPR_ABORT_WARN
38
39#define gpr_warn(Expr, Msg) \
40 if(!(Expr)) \
41 { \
42 core::LogWarning(fmt::format("Warning Assert failed:\t{}\nSource:\t\t{}, line {}", \
43 #Msg, __FILE__,__LINE__)); \
44 std::abort(); \
45 }
46
47# else
48
49#define gpr_warn(Expr, Msg) \
50 if (!(Expr)) \
51 { \
52 core::LogWarning(fmt::format("Warning Assert failed:\t{}\nSource:\t\t{}, line {}", \
53 #Msg, __FILE__, __LINE__)); \
54 }
55# endif
56# else
57#define gpr_assert(Expr, Msg) \
58 if(!(Expr)) \
59 { \
60 core::LogError(fmt::format("Assert failed:\t{}\nSource:\t\t{}, line {}", \
61 #Msg, __FILE__,__LINE__)); \
62 throw core::AssertException(Msg); \
63 }
64# ifdef GPR_ABORT_WARN
65
66#define gpr_warn(Expr, Msg) \
67 if(!(Expr)) \
68 { \
69 core::LogWarning(fmt::format("Warning Assert failed:\t{}\nSource:\t\t{}, line {}", \
70 #Msg, __FILE__,__LINE__)); \
71 throw core::AssertException(Msg); \
72 }
73
74# else
75
76#define gpr_warn(Expr, Msg) \
77 if (!(Expr)) \
78 { \
79 core::LogWarning(fmt::format("Warning Assert failed:\t{}\nSource:\t\t{}, line {}", \
80 #Msg, __FILE__, __LINE__)); \
81 }
82# endif
83# endif
84#else
85#define gpr_assert(Expr, Msg) \
86 void(0);
87#define gpr_warn(Expr, Msg) \
88 void(0);
89#endif
AssertException is an exception type used for the project assertation when the user need the applicat...
Definition: assert.h:18