-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.hpp
67 lines (61 loc) · 1.58 KB
/
Message.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
#ifndef __MESSAGE_HPP__
#define __MESSAGE_HPP__
#include <stdio.h>
#include <stdlib.h>
PRJ_BEGIN
/// STR(X): turns X into a string literature
/// XSTR(X): turns X into string of expansion of macro X
#define STR(X) #X
#define XSTR(X) STR(X)
#ifdef MESSAGE_ON
#define ASSERT(x) \
do{if(!(x)){ \
fprintf(stderr,"[FAILED: "STR(x)"] "__FILE__":%d\n",__LINE__); \
fflush(stderr); \
exit(EXIT_FAILURE); \
}}while(0)
#define ASSERT_MSG(x,msg) \
do{if(!(x)){ \
fprintf(stderr,"[FAILED: "STR(x)"] "__FILE__":%d\n",__LINE__); \
fprintf(stderr,"> "msg"\n"); \
fflush(stderr); \
exit(EXIT_FAILURE); \
}}while(0)
#define ASSERT_MSGV(x,fmt,...) \
do{if(!(x)){ \
fprintf(stderr,"[FAILED: "STR(x)"] "__FILE__":%d\n",__LINE__); \
fprintf(stderr,"> "fmt"\n",__VA_ARGS__); \
fflush(stderr); \
exit(EXIT_FAILURE); \
}}while(0)
#define WARN(msg) \
do{ \
fprintf(stderr,"[WARNING] "msg"\n"); \
fflush(stderr); \
}while(0)
#define WARNV(fmt,...) \
do{ \
fprintf(stderr,"[WARNING] "fmt"\n",__VA_ARGS__); \
fflush(stderr); \
}while(0)
#define INFO(msg) \
do{ \
fprintf(stderr,"[INFO] "msg"\n"); \
fflush(stderr); \
}while(0)
#define INFOV(fmt,...) \
do{ \
fprintf(stderr,"[INFO] "fmt"\n",__VA_ARGS__); \
fflush(stderr); \
}while(0)
#else
#define ASSERT(x) do{x;}while(0)
#define ASSERT_MSG(x,msg) do{x;}while(0)
#define ASSERT_MSGV(x,fmt,...) do{x;}while(0)
#define WARN(msg) do{}while(0)
#define WARNV(fmt,...) do{}while(0)
#define INFO(msg) do{}while(0)
#define INFOV(fmt,...) do{}while(0)
#endif
PRJ_END
#endif //__MESSAGE_HPP__