-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.h
113 lines (99 loc) · 2.71 KB
/
common.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
/*!
* \file common.h
* \brief Common functions and macros.
* \author Joachim Valente <[email protected]>
*/
#ifndef TL_COMMON_H
#define TL_COMMON_H
//--------------------- Included for easy debugging ---------------
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
//-------------------- Macros for safety checks ------------------------
/*!
* \brief Die if `condition` is not verified.
*/
#define CHECK(condition) \
do { \
if (!(condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << std::endl; \
std::exit(EXIT_FAILURE); \
} \
} while (false)
/*!
* \brief Die if `x` is nullptr.
*/
#define CHECK_NOTNULL(x) CHECK(x != nullptr)
/*!
* \brief Die with `message` if `condition` is not verified.
*/
#define CHECK_MSG(condition, message) \
do { \
if (!(condition)) { \
std::cerr << "Assertion `" #condition "` failed in " << __FILE__ \
<< " line " << __LINE__ << ": " << message << std::endl; \
std::exit(EXIT_FAILURE); \
} \
} while (false)
/*!
* \brief Die.
*/
#define DIE \
do { \
std::cerr << "Killed in " << __FILE__ \
<< " line " << __LINE__ << std::endl; \
std::exit(EXIT_FAILURE); \
} while (false)
/*!
* \brief Die with message.
*/
#define DIE_MSG(message) \
do { \
std::cerr << "Killed in " << __FILE__ \
<< " line " << __LINE__ << ": " << message << std::endl; \
std::exit(EXIT_FAILURE); \
} while (false)
//---------------------- Macros for debugging -----------------------
/*!
* \brief Print a warning.
*/
#define WARNING(message) \
do { \
std::cerr << "Warning in " << __FILE__ \
<< " line " << __LINE__ << ": " << message << std::endl; \
} while (false)
/*!
* \brief Print info.
*/
#define INFO(message) \
do { \
std::cout << "[INFO] " << message << std::endl; \
} while (false)
//------------------------- Other macros ------------------------------
//! \cond DoxygenIgnore
// Trick to allow semi-colon at the end of macros used outside functions.
#define MACRO_END \
extern void nL3ewN8Too8Um2kCCU1NnIL4Q9z8phYslgWk7W8JrvunxPA8L8whgSyDPL4lJyxEU
//! \endcond
/*!
* \brief Use enum as bit flags.
*/
#define BITFLAGS(classname) \
; \
inline classname operator|(classname a, classname b) \
{ \
return static_cast<classname>(static_cast<int>(a) | static_cast<int>(b)); \
} \
MACRO_END
/*!
* \brief Disallow copy and assign.
*/
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(TypeName&) = delete; \
void operator=(TypeName) = delete
/*!
* \brief Silence warning about unused variable.
*/
#define UNUSED(a) ((void)(a))
#endif // TL_COMMON_H