ARTS  2.4.0(git:4fb77825)
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 // Use this macro around function parameter names and variable definitions
35 // which are only used in assertions
36 #define DEBUG_ONLY(...) __VA_ARGS__
37 
38 // Use this macro to output a counter value everytime a
39 // certain place is reached
40 #define DEBUG_COUNTER(n) \
41  { \
42  static Index n = 0; \
43  std::cerr << "DBG: " << #n << ": " << ++n << std::endl; \
44  }
45 
46 // Print value of expression for debugging
47 #define DEBUG_PRINT(e) \
48  { std::cerr << "DBG: " << (e) << std::endl; }
49 
50 // Print expression and value for debugging
51 #define DEBUG_VAR(e) \
52  { std::cerr << "DBG: " << #e << ": " << (e) << std::endl; }
53 
54 // Print expression and value with the given fp precision for debugging
55 #define DEBUG_VAR_FLT(p, e) \
56  { \
57  std::streamsize old_p = std::cerr.precision(); \
58  std::cerr << "DBG: " << #e << ": " << std::setprecision(p) << (e) \
59  << std::endl \
60  << std::setprecision(old_p); \
61  }
62 
63 #else
64 
65 #define DEBUG_ONLY(...)
66 
67 #define DEBUG_COUNTER(n)
68 
69 #define DEBUG_PRINT(e)
70 
71 #define DEBUG_VAR(e)
72 
73 #define DEBUG_VAR_FLT(p, e)
74 
75 #endif /* NDEBUG */
76 
77 #endif /* debug_h */