ARTS  2.2.66
debug.h
Go to the documentation of this file.
1 /* Copyright (C) 2013
2  Oliver Lemke <olemke@core-dump.info>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License as published by the
6  Free Software Foundation; either version 2, or (at your option) any
7  later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17  USA. */
18 
27 #ifndef debug_h
28 #define debug_h
29 
30 #ifndef NDEBUG
31 
32 #include <iostream>
33 
34 
35 // Use this macro around function parameter names and variable definitions
36 // which are only used in assertions
37 #define DEBUG_ONLY(...) __VA_ARGS__
38 
39 // Use this macro to output a counter value everytime a
40 // certain place is reached
41 #define DEBUG_COUNTER(n) \
42 { \
43  static Index n = 0; \
44  std::cerr << "DBG: " << #n << ": " << ++n << std::endl; \
45 }
46 
47 // Print value of expression for debugging
48 #define DEBUG_PRINT(e) \
49 { \
50  std::cerr << "DBG: " << (e) << std::endl; \
51 }
52 
53 // Print expression and value for debugging
54 #define DEBUG_VAR(e) \
55 { \
56  std::cerr << "DBG: " << #e << ": " << (e) << std::endl; \
57 }
58 
59 // Print expression and value with the given fp precision for debugging
60 #define DEBUG_VAR_FLT(p, e) \
61 { \
62  std::streamsize old_p = std::cerr.precision(); \
63  std::cerr << "DBG: " << #e << ": " << std::setprecision(p) \
64  << (e) << std::endl << std::setprecision(old_p); \
65 }
66 
67 #else
68 
69 #define DEBUG_ONLY(...)
70 
71 #define DEBUG_COUNTER(n)
72 
73 #define DEBUG_PRINT(e)
74 
75 #define DEBUG_VAR(e)
76 
77 #define DEBUG_VAR_FLT(p, e)
78 
79 #endif /* NDEBUG */
80 
81 #endif /* debug_h */
82 
83