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