Photon Common Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
assertion.h
Go to the documentation of this file.
1#pragma once
2
3#include "Common/config.h"
4#include "Common/macro.h"
5
6#include <string>
7
8namespace ph::detail
9{
10
12 const std::string& filename,
13 const std::string& lineNumber,
14 const std::string& condition,
15 const std::string& message);
16
18
19}// end namespace ph::detail
20
21#if PH_DEBUG
22
23#define PH_ASSERT_MSG(condition, failMessage)\
24 do\
25 {\
26 if(!(condition))\
27 {\
28 ::ph::detail::output_assertion_message(\
29 std::string(__FILE__),\
30 std::to_string(__LINE__),\
31 std::string(#condition),\
32 std::string((failMessage)));\
33 \
34 ::ph::detail::on_assertion_failed();\
35 }\
36 } while(0)
37
38#define PH_INTERNAL_RANGE_MSG(value, lowerBound, upperBound, lowerBoundSymbol, upperBoundSymbol)\
39 (std::string(#value) + " = " + std::to_string(value) + ", asserted to be in range = " + \
40 lowerBoundSymbol + std::to_string(lowerBound) + ", " + std::to_string(upperBound) + upperBoundSymbol)
41
42#else
43
44#define PH_ASSERT_MSG(condition, message) PH_NO_OP()
45#define PH_INTERNAL_RANGE_MSG(value, lowerBound, upperBound, lowerBoundSymbol, upperBoundSymbol) PH_NO_OP()
46
47#endif
48
49#define PH_ASSERT(condition)\
50 PH_ASSERT_MSG(condition, "")
51
52#define PH_ASSERT_UNREACHABLE_SECTION()\
53 PH_ASSERT_MSG(false, "executing supposedly unreachable code")
54
55#define PH_ASSERT_EQ(a, b)\
56 PH_ASSERT_MSG(a == b, std::string(#a) + " = " + std::to_string(a) + ", " + #b + " = " + std::to_string(b))
57
58#define PH_ASSERT_NE(a, b)\
59 PH_ASSERT_MSG(a != b, std::string(#a) + " = " + std::to_string(a) + ", " + #b + " = " + std::to_string(b))
60
61#define PH_ASSERT_GT(a, b)\
62 PH_ASSERT_MSG(a > b, std::string(#a) + " = " + std::to_string(a) + ", " + #b + " = " + std::to_string(b))
63
64#define PH_ASSERT_LT(a, b)\
65 PH_ASSERT_MSG(a < b, std::string(#a) + " = " + std::to_string(a) + ", " + #b + " = " + std::to_string(b))
66
67#define PH_ASSERT_GE(a, b)\
68 PH_ASSERT_MSG(a >= b, std::string(#a) + " = " + std::to_string(a) + ", " + #b + " = " + std::to_string(b))
69
70#define PH_ASSERT_LE(a, b)\
71 PH_ASSERT_MSG(a <= b, std::string(#a) + " = " + std::to_string(a) + ", " + #b + " = " + std::to_string(b))
72
75#define PH_ASSERT_IN_RANGE(value, begin, end)\
76 PH_ASSERT_MSG(begin <= value && value < end, PH_INTERNAL_RANGE_MSG(value, begin, end, "[", ")"))
77
80#define PH_ASSERT_IN_RANGE_INCLUSIVE(value, lowerBound, upperBound)\
81 PH_ASSERT_MSG(lowerBound <= value && value <= upperBound, PH_INTERNAL_RANGE_MSG(value, lowerBound, upperBound, "[", "]"))
82
85#define PH_ASSERT_IN_RANGE_EXCLUSIVE(value, lowerBound, upperBound)\
86 PH_ASSERT_MSG(lowerBound < value && value < upperBound, PH_INTERNAL_RANGE_MSG(value, lowerBound, upperBound, "(", ")"))
87
88
89namespace ph::detail
90{
91
92template<typename T>
93inline constexpr bool DEPENDENT_FALSE = false;
94
95}// end namespace ph::detail
96
97#define PH_STATIC_ASSERT_DEPENDENT_FALSE(DependentType, message)\
98 static_assert(::ph::detail::DEPENDENT_FALSE<DependentType>, #message)
Configurations for the entire toolset.
Useful macro definitions for general operations.
Implementation detail mainly for internal usages.
Definition assertion.h:9
void output_assertion_message(const std::string &filename, const std::string &lineNumber, const std::string &condition, const std::string &message)
Definition assertion.cpp:11
constexpr bool DEPENDENT_FALSE
Definition assertion.h:93
void on_assertion_failed()
Definition assertion.cpp:29