radarlib  1.4.4
debug.hpp
Go to the documentation of this file.
1 /*
2  * Radar Library
3  *
4  * Copyright (C) 2009-2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Author: Guido Billi <guidobilli@gmail.com>
21  */
22 
27 #ifndef __RADAR_DEBUG_HPP__
28 #define __RADAR_DEBUG_HPP__
29 
30 #include <iostream>
31 #include <cstdio>
32 #include <string>
33 #include <iomanip>
34 #include <limits>
35 
36 #include <radarlib/defs.h>
37 
38 /*=============================================================================*/
39 /* INTERNAL MACROS USED FOR DEBUGGING */
40 /* TO ENABLE THEESE MACROS CODE YOU MUST COMPILE WITH -D_DEBUG */
41 /*=============================================================================*/
42 
43 #ifdef _DEBUG
44 
45  #define DEBUG(values) do { std::cout.setf(std::ios::fixed); std::cout << "DEBUG: " << values << std::endl; } while (0)
46  #define DEBUGIF(cond,values) do { if (cond) { std::cout.setf(std::ios::fixed); std::cout << "DEBUG: " << values << std::endl; } } while (0)
47 
48  #define DEBUG_WAIT { getchar(); }
49  #define DEBUG_HERE { std::cout << "DEBUG: " << __FUNCTION__ << std::endl; }
50  #define DEBUG_BEEP { putc(7, stdout); }
51 
52  #define DEBUG_ASSERT(cond) do { bool res = cond; if (!res) { DEBUG("ASSERT FAILED: " << #cond << "\t("<< __FILE__ << ":" << __FUNCTION__ << ")"); DEBUG_BEEP; DEBUG_WAIT; } } while (0)
53 
54  #define DEBUG_CODE if (1)
55 
56  template <class T> inline void DEBUG_DUMP(const char* str, const T* values, size_t num)
57  {
58  std::cout.setf(std::ios::fixed);
59  std::cout << str;
60  for (size_t i=0; i<num; i++)
61  std::cout << (int)values[i] << " ";
62  std::cout << std::endl;
63  }
64  template <class T> inline void DEBUG_DUMP(const T* values, size_t num)
65  {
66  DEBUG_DUMP<T>("", values, num);
67  }
68  inline void DEBUG_DUMP(const char* value, size_t num) { DEBUG_DUMP<char> ("", value, num); }
69  inline void DEBUG_DUMP(const unsigned char* value, size_t num) { DEBUG_DUMP<unsigned char> ("", value, num); }
70  inline void DEBUG_DUMP(const short* value, size_t num) { DEBUG_DUMP<short> ("", value, num); }
71  inline void DEBUG_DUMP(const unsigned short* value, size_t num) { DEBUG_DUMP<unsigned short> ("", value, num); }
72  inline void DEBUG_DUMP(const int* value, size_t num) { DEBUG_DUMP<int> ("", value, num); }
73  inline void DEBUG_DUMP(const unsigned int* value, size_t num) { DEBUG_DUMP<unsigned int> ("", value, num); }
74  inline void DEBUG_DUMP(const long* value, size_t num) { DEBUG_DUMP<long> ("", value, num); }
75  inline void DEBUG_DUMP(const unsigned long* value, size_t num) { DEBUG_DUMP<unsigned long> ("", value, num); }
76  inline void DEBUG_DUMP(const float* value, size_t num) { DEBUG_DUMP<float> ("", value, num); }
77  inline void DEBUG_DUMP(const double* value, size_t num) { DEBUG_DUMP<double> ("", value, num); }
78 
79 #else
80 
81  #define DEBUG(values) do { } while (0)
82  #define DEBUGIF(cond,values) do { } while (0)
83 
84  #define DEBUG_WAIT {}
85  #define DEBUG_HERE {}
86  #define DEBUG_BEEP {}
87 
88  #define DEBUG_ASSERT(cond) do {} while(0)
89 
90  #define DEBUG_CODE if (0)
91 
92  template <class T> inline void DEBUG_DUMP(const char* str, const T* values, size_t num) { }
93  template <class T> inline void DEBUG_DUMP(const T* values, size_t num) { }
94 
95  inline void DEBUG_DUMP(const char* value, size_t num) { }
96  inline void DEBUG_DUMP(const unsigned char* value, size_t num) { }
97  inline void DEBUG_DUMP(const short* value, size_t num) { }
98  inline void DEBUG_DUMP(const unsigned short* value, size_t num) { }
99  inline void DEBUG_DUMP(const int* value, size_t num) { }
100  inline void DEBUG_DUMP(const unsigned int* value, size_t num) { }
101  inline void DEBUG_DUMP(const long* value, size_t num) { }
102  inline void DEBUG_DUMP(const unsigned long* value, size_t num) { }
103  inline void DEBUG_DUMP(const float* value, size_t num) { }
104  inline void DEBUG_DUMP(const double* value, size_t num) { }
105 
106 #endif
107 
108 /*=============================================================================*/
109 
110 #endif
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
Internal library macros.