-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmacro.hpp
92 lines (65 loc) · 2.34 KB
/
macro.hpp
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
///
// @author : Ruan E. Formigoni ([email protected])
// @file : macro
///
#pragma once
// Ec wrapper
#define lec(fun, ...) \
ns_log::ec([]<typename... Args>(Args&&... args){ return fun(std::forward<Args>(args)...); }, __VA_ARGS__)
// Throw
#define qthrow_if(cond, msg) \
if (cond) { throw std::runtime_error(msg); }
#define dthrow_if(cond, msg) \
if (cond) { ns_log::debug()(msg); throw std::runtime_error(msg); }
#define ithrow_if(cond, msg) \
if (cond) { ns_log::info()(msg); throw std::runtime_error(msg); }
#define ethrow_if(cond, msg) \
if (cond) { ns_log::error()(msg); throw std::runtime_error(msg); }
// Exit
#define qexit_if(cond, ret) \
if (cond) { exit(ret); }
#define dexit_if(cond, msg, ret) \
if (cond) { ns_log::debug()(msg); exit(ret); }
#define iexit_if(cond, msg, ret) \
if (cond) { ns_log::info()(msg); exit(ret); }
#define eexit_if(cond, msg, ret) \
if (cond) { ns_log::error()(msg); exit(ret); }
// Return
#define qreturn_if(cond, ...) \
if (cond) { return __VA_ARGS__; }
#define dreturn_if(cond, msg, ...) \
if (cond) { ns_log::debug()(msg); return __VA_ARGS__; }
#define ireturn_if(cond, msg, ...) \
if (cond) { ns_log::info()(msg); return __VA_ARGS__; }
#define ereturn_if(cond, msg, ...) \
if (cond) { ns_log::error()(msg); return __VA_ARGS__; }
#define return_if_else(cond, val1, val2) \
if (cond) { return val1; } else { return val2; }
// Break
#define qbreak_if(cond) \
if ( (cond) ) { break; }
#define ebreak_if(cond, msg) \
if ( (cond) ) { ns_log::error()(msg); break; }
#define ibreak_if(cond, msg) \
if ( (cond) ) { ns_log::info()(msg); break; }
#define dbreak_if(cond, msg) \
if ( (cond) ) { ns_log::debug()(msg); break; }
// Continue
#define qcontinue_if(cond) \
if ( (cond) ) { continue; }
#define econtinue_if(cond, msg) \
if ( (cond) ) { ns_log::error()(msg); continue; }
#define icontinue_if(cond, msg) \
if ( (cond) ) { ns_log::info()(msg); continue; }
#define dcontinue_if(cond, msg) \
if ( (cond) ) { ns_log::debug()(msg); continue; }
// Abort
#define eabort_if(cond, msg) \
if ( (cond) ) { ns_log::error()(msg); std::abort(); }
// Conditional log
#define elog_if(cond, msg) \
if ( (cond) ) { ns_log::error()(msg); }
#define ilog_if(cond, msg) \
if ( (cond) ) { ns_log::info()(msg); }
#define dlog_if(cond, msg) \
if ( (cond) ) { ns_log::debug()(msg); }