-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathassert-custom.hpp
More file actions
168 lines (144 loc) · 3.45 KB
/
Copy pathassert-custom.hpp
File metadata and controls
168 lines (144 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Custom header-only run-time testing and printing.
*
* This file is part of dae-cpp.
*
* dae-cpp is licensed under the MIT license.
* A copy of the license can be found in the LICENSE file.
*
* Copyright (c) 2024-2025 Ivan Korotkin
*/
#ifndef DAECPP_ASSERT_CUSTOM_H
#define DAECPP_ASSERT_CUSTOM_H
#include <iostream>
namespace daecpp_namespace_name
{
/*
* ERROR(error message)
*
* Prints error message and aborts with error code -1.
*
* Example:
* ERROR("v = " << v);
*/
#define ERROR(msg) \
{ \
std::cerr << "\nERROR: " << msg << "\nThis error is fatal." << std::endl; \
exit(-1); \
}
/*
* WARNING(warning message)
*
* Prints warning message.
*
* Example:
* WARNING("v = " << v);
*/
#ifdef TESTING
#define WARNING(msg)
#else
#define WARNING(msg) \
std::cerr << "WARNING: " << msg << std::endl;
#endif
/*
* NOTE(note message)
*
* Prints a note.
*
* Example:
* NOTE("v = " << v);
*/
#ifdef TESTING
#define NOTE(msg)
#else
#define NOTE(msg) \
std::cerr << "NOTE: " << msg << std::endl;
#endif
/*
* PRINT(condition, message)
*
* Prints a message if condition (e.g., verbosity level) is true and flushes the output.
*
* Example:
* NOTE(verbosity > 1, "v = " << v);
*/
#ifdef TESTING
#define PRINT(condition, msg)
#else
#define PRINT(condition, msg) \
if (condition) \
{ \
std::cout << msg << std::endl; \
}
#endif
/*
* ASSERT(expression, error message)
*
* Prints error message and aborts with error code -1 if expression is false.
*
* Example:
* ASSERT(v > 0, "Variable v is negative or zero: v = " << v);
*/
#define ASSERT(expression, msg) \
if (!(expression)) \
{ \
ERROR(msg); \
}
/*
* CHECK(expression, warning message)
*
* Prints a warning message if expression is false.
*
* Example:
* CHECK(v > 0, "Variable v is negative or zero: v = " << v);
*/
#define CHECK(expression, msg) \
if (!(expression)) \
{ \
WARNING(msg); \
}
#ifdef DEBUG
/*
* Same as ERROR(message) but works only if DEBUG is defined.
*/
#define DEBUG_ERROR(msg) ERROR(msg)
/*
* Same as WARNING(message) but works only if DEBUG is defined.
*/
#define DEBUG_WARNING(msg) WARNING(msg)
/*
* Same as NOTE(message) but works only if DEBUG is defined.
*/
#define DEBUG_NOTE(msg) NOTE(msg)
/*
* Same as ASSERT(expression, error message) but works only if DEBUG is defined.
*/
#define DEBUG_ASSERT(expression, msg) ASSERT(expression, msg)
/*
* Same as CHECK(expression, warning message) but works only if DEBUG is defined.
*/
#define DEBUG_CHECK(expression, msg) CHECK(expression, msg)
#else // #ifdef DEBUG
/*
* DEBUG is not defined. This macro does nothing.
*/
#define DEBUG_ERROR(msg)
/*
* DEBUG is not defined. This macro does nothing.
*/
#define DEBUG_WARNING(msg)
/*
* DEBUG is not defined. This macro does nothing.
*/
#define DEBUG_NOTE(msg)
/*
* DEBUG is not defined. This macro does nothing.
*/
#define DEBUG_ASSERT(expression, msg)
/*
* DEBUG is not defined. This macro does nothing.
*/
#define DEBUG_CHECK(expression, msg)
#endif // #ifdef DEBUG
} // namespace daecpp_namespace_name
#endif // DAECPP_ASSERT_CUSTOM_H