SpinParser  1.0
Assert.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 #include "lib/Exception.hpp"
11 
12 #ifdef ENABLE_ASSERTIONS
13  #define ___STR(x) #x
14  #define ___STRING(x) ___STR(x)
15  #define __LOCATION __FILE__ ":" ___STRING(__LINE__)
16 #endif
17 
21 #define __RESOLVE_ASSERT_OVERLOAD(_1, _2, FUNCTIONNAME, ...) FUNCTIONNAME
22 
26 #define ASSERT(...) __RESOLVE_ASSERT_OVERLOAD(__VA_ARGS__, __ASSERT_OVERLOAD2, __ASSERT_OVERLOAD1)(__VA_ARGS__)
27 
28 #ifdef ENABLE_ASSERTIONS
29 
34  #define __ASSERT_OVERLOAD1(x) if (!(x)) throw Exception(Exception::Type::AssertionFail, "Assertion failed at " __LOCATION ". Expression " #x " should be true.");
35 
42  #define __ASSERT_OVERLOAD2(x, msg) if (!(x)) throw Exception(Exception::Type::AssertionFail, "Assertion failed at " __LOCATION ". " msg);
43 #else
44 
49  #define __ASSERT_OVERLOAD1(x)
50 
57  #define __ASSERT_OVERLOAD2(x, msg)
58 #endif
Exception.hpp
Descriptor object for exceptions.