-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMacros.h
114 lines (88 loc) · 3.28 KB
/
Macros.h
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
/*
This file is part of the Util library.
Copyright (C) 2007-2012 Benjamin Eikel <[email protected]>
Copyright (C) 2007-2012 Claudius Jähn <[email protected]>
Copyright (C) 2007-2012 Ralf Petring <[email protected]>
This library is subject to the terms of the Mozilla Public License, v. 2.0.
You should have received a copy of the MPL along with this library; see the
file LICENSE. If not, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef MACROS_H_INCLUDED
#define MACROS_H_INCLUDED
#include <string>
#include <stdexcept>
namespace Util {
//! @addtogroup util_helper
//! @{
enum output_priority_t {
OUTPUT_DEBUG,
OUTPUT_WARNING,
OUTPUT_ERROR
};
UTILAPI void output(output_priority_t priority,const std::string & message);
UTILAPI std::string composeDebugMessage(const std::string & message,const char * file, int line);
//! @}
}
#ifdef DEBUG_MODE
#define DEBUG(M) \
Util::output(Util::OUTPUT_DEBUG, Util::composeDebugMessage(M, __FILE__, __LINE__))
#else
#define DEBUG(M)
#endif
#define WARN(M) \
Util::output(Util::OUTPUT_WARNING, Util::composeDebugMessage(M, __FILE__, __LINE__))
#define WARN_AND_RETURN(M,V) \
Util::output(Util::OUTPUT_WARNING, Util::composeDebugMessage(M, __FILE__, __LINE__)); return V
#define WARN_IF(C,M) \
if(C) Util::output(Util::OUTPUT_WARNING, Util::composeDebugMessage(M, __FILE__, __LINE__))
#define WARN_AND_RETURN_IF(C,M,V) \
do{ if(C) { \
Util::output(Util::OUTPUT_WARNING, Util::composeDebugMessage(M, __FILE__, __LINE__)); \
return V; \
}} while(false)
#define FAIL() \
do{ \
const std::string msg = Util::composeDebugMessage( "Runtime error.", __FILE__, __LINE__);\
Util::output(Util::OUTPUT_ERROR, msg);\
throw std::runtime_error(msg);\
}while(false)
#define FAIL_IF(C) \
do{ \
if (C) FAIL(); \
}while(false)
//! Use this macro if a parameter value can not be applied in the context of a function (e.g. wrong color format)
#define INVALID_ARGUMENT_EXCEPTION(msg) \
do{ \
throw std::invalid_argument( Util::composeDebugMessage(msg, __FILE__, __LINE__) );\
}while(false)
//! Macros for disabling compiler warnings when using including library headers or or for code that produces warnings which can not be fixed
#define GCC_DIAG_STR(s) #s
#define GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
#define GCC_DIAG_PRAGMA(x) GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
#ifdef __clang__
#define COMPILER_WARN_PUSH GCC_DIAG_PRAGMA(push)
#define COMPILER_WARN_POP GCC_DIAG_PRAGMA(pop)
#define COMPILER_WARN_OFF_CLANG(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_STR(x))
#define COMPILER_WARN_OFF_GCC(x)
#define COMPILER_WARN_OFF(x) COMPILER_WARN_OFF_CLANG(x)
#elif __GNUC__
#define COMPILER_WARN_PUSH GCC_DIAG_PRAGMA(push)
#define COMPILER_WARN_POP GCC_DIAG_PRAGMA(pop)
#define COMPILER_WARN_OFF_CLANG(x)
#define COMPILER_WARN_OFF_GCC(x) GCC_DIAG_PRAGMA(ignored GCC_DIAG_STR(x))
#define COMPILER_WARN_OFF(x) COMPILER_WARN_OFF_GCC(x)
#else
#define COMPILER_WARN_PUSH
#define COMPILER_WARN_POP
#define COMPILER_WARN_OFF(x)
#define COMPILER_WARN_OFF_GCC(x)
#define COMPILER_WARN_OFF_CLANG(x)
#endif
//! Macro for simplifying creation of getter/setter methods
#define GETSET(type, var, _default)\
private:\
type _##var = _default;\
public:\
inline type get##var() const { return _##var; }\
inline void set##var(const type& val) { _##var = val; }
#endif // MACROS_H_INCLUDED