Writing about color mappings and RMSE, small fixes.
[fic.git] / debug.h
blobf6fc378cea27acdcde1da1bbc6aaa6b97193f141
1 #ifndef DEBUG_HEADER_
2 #define DEBUG_HEADER_
4 /** Defining my own assert macro */
5 #undef assert
6 #ifdef NDEBUG
7 #define DEBUG_ONLY(expr)
8 #define assert(expr) void(0)
9 #else
10 inline void assert_fail_() {
11 int *i=0, j=*i;
12 *i=j;
14 #define DEBUG_ONLY(expr) expr
15 #define assert(expr) ( expr ? void(0) : assert_fail_() )
16 #endif
18 #define NOSPACE /* empty */
21 /** Cast that is "dynamic" (with assert) in debug mode and "static" in release mode */
22 template <class T,class U> inline T debugCast(U toCast) {
23 #ifdef NDEBUG
24 return static_cast<T>(toCast);
25 #else
26 if (!toCast)
27 return 0; // skip the assertion
28 T result= dynamic_cast<T>(toCast);
29 assert(result);
30 return result;
31 #endif
34 #ifdef NDEBUG
35 #define DECLARE_debugModule
36 #else
37 #define DECLARE_debugModule public: \
38 virtual QWidget* debugModule(QPixmap &pixmap,const QPoint &click)
39 #endif
41 #ifndef NDEBUG
42 extern int pos;
43 inline void STREAM_POS(std::istream &file) { pos= file.tellg(); }
44 inline void STREAM_POS(std::ostream &file) { pos= file.tellp(); }
45 #else
46 inline void STREAM_POS(std::ios&) {}
47 #endif
49 #endif // DEBUG_HEADER_