debug.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file debug.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 
38  Example of use:
39  @snippet help.snippets.debug/DebugSim.cpp debug
40 
41 */
42 
43 
44 #ifndef __OPENFLUID_DEBUG_HPP__
45 #define __OPENFLUID_DEBUG_HPP__
46 
47 
48 // =====================================================================
49 // =====================================================================
50 
51 
52 // OpenFLUID:stylecheck:!incs
53 
54 
55 #ifndef NDEBUG
56 
57 #include <iostream>
58 #include <openfluid/config.hpp>
59 
60 #define OFDBG_ENABLED 1
61 #define OFDBG_OUTSTREAM std::cout
62 
63 #else
64 
65 #define OFDBG_ENABLED 0
66 #define OFDBG_OUTSTREAM
67 
68 #endif
69 
70 
71 // =====================================================================
72 // =====================================================================
73 
74 
75 /**
76  @def OFDBG_LOCATE
77  Displays file/line location where the macro is called
78 */
79 
80 
81 #ifndef NDEBUG
82 
83 #define OFDBG_LOCATE \
84  {\
85  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " File " << __FILE__ << ", Line " << __LINE__ << std::endl;\
86  }
87 
88 #else
89 
90 #define OFDBG_LOCATE ;
91 
92 #endif
93 
94 
95 // =====================================================================
96 // =====================================================================
97 
98 
99 #ifndef NDEBUG
100 
101 #define OFDBG_BANNER \
102  { \
103  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << std::endl; \
104  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " OpenFLUID debugging mode is enabled" << std::endl; \
105  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << std::endl; \
106  }
107 
108 #else
109 
110 #define OFDBG_BANNER
111 
112 #endif
113 
114 
115 // =====================================================================
116 // =====================================================================
117 
118 
119 /**
120  @def OFDBG_MESSAGE
121  Displays the given message
122 */
123 
124 
125 #ifndef NDEBUG
126 
127 #define OFDBG_MESSAGE(stream) \
128  { OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " " << stream << std::endl; }
129 
130 #else
131 
132 #define OFDBG_MESSAGE(stream)
133 
134 #endif
135 
136 
137 // =====================================================================
138 // =====================================================================
139 
140 
141 /**
142  @def OFDBG_UNIT
143  Displays information about the given spatial unit
144 */
145 
146 
147 #ifndef NDEBUG
148 
149 #define OFDBG_UNIT(unitptr) \
150  {\
151  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Unit class " << (unitptr)->getClass()\
152  << ", ID " << (unitptr)->getID() << std::endl;\
153  }
154 
155 #else
156 
157 #define OFDBG_UNIT(unitptr)
158 
159 #endif
160 
161 
162 // =====================================================================
163 // =====================================================================
164 
165 
166 /**
167  @def OFDBG_UNIT_EXTENDED
168  Displays extended information about the given spatial unit
169 */
170 
171 
172 #ifndef NDEBUG
173 
174 #define OFDBG_UNIT_EXTENDED(unitptr) \
175  { \
176  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Unit class " << (unitptr)->getClass()\
177  << ", ID " << (unitptr)->getID() << std::endl; \
178  std::vector<openfluid::core::AttributeName_t> _M_DBG_AttrsNames = (unitptr)->attributes()->getAttributesNames(); \
179  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - Attributes: "; \
180  for (unsigned int i=0; i<_M_DBG_AttrsNames.size();i++) OFDBG_OUTSTREAM << _M_DBG_AttrsNames[i] << " , "; \
181  OFDBG_OUTSTREAM << std::endl; \
182  std::vector<openfluid::core::VariableName_t> _M_DBG_VarNames = (unitptr)->variables()->getVariablesNames(); \
183  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - Variables: "; \
184  for (unsigned int i=0; i<_M_DBG_VarNames.size();i++) OFDBG_OUTSTREAM << _M_DBG_VarNames[i] << " , "; \
185  OFDBG_OUTSTREAM << std::endl; \
186  }
187 
188 #else
189 
190 #define OFDBG_UNIT_EXTENDED(unitptr)
191 
192 #endif
193 
194 
195 // =====================================================================
196 // =====================================================================
197 
198 
199 /**
200  @def OFDBG_EVENT
201  Displays information about the given event
202 */
203 
204 
205 #ifndef NDEBUG
206 
207 #define OFDBG_EVENT(eventptr) \
208  { \
209  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX\
210  << " Event at " << (eventptr)->getDateTime().getAsISOString() << std::endl; \
211  openfluid::core::Event::EventInfosMap_t::iterator _M_DBG_EvInfoiter; \
212  for (_M_DBG_EvInfoiter = (eventptr)->getInfos().begin();\
213  _M_DBG_EvInfoiter != (eventptr)->getInfos().end();++_M_DBG_EvInfoiter) \
214  { \
215  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - "\
216  << (*_M_DBG_EvInfoiter).first << " = " << (*_M_DBG_EvInfoiter).second.get() << std::endl; \
217  } \
218  }
219 
220 #else
221 
222 #define OFDBG_EVENT(eventptr)
223 
224 #endif
225 
226 
227 // =====================================================================
228 // =====================================================================
229 
230 
231 /**
232 @def OFDBG_EVENTCOLLECTION
233 Displays information about the given event collection
234 */
235 
236 
237 #ifndef NDEBUG
238 
239 #define OFDBG_EVENTCOLLECTION(eventcoll) \
240  { \
241  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Event collection size : "\
242  << eventcoll.eventsList()->size() << std::endl; \
243  openfluid::core::EventsList_t::iterator _M_DBG_EvListiter; \
244  for (_M_DBG_EvListiter=(EvColl.eventsList())->begin();\
245  _M_DBG_EvListiter != (EvColl.eventsList())->end(); ++_M_DBG_EvListiter) \
246  { \
247  OFDBG_EVENT(&(*_M_DBG_EvListiter)); \
248  } \
249  }
250 
251 #else
252 
253 #define OFDBG_EVENTCOLLECTION(eventcoll)
254 
255 #endif
256 
257 
258 #endif /* __OPENFLUID_DEBUG_HPP__ */