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 @code{.cpp}
40 openfluid::base::SchedulingRequest runStep()
41 {
42  openfluid::core::SpatialUnit* TU;
43  openfluid::core::DateTime BeginDate,EndDate;
44  openfluid::core::EventsCollection EvColl;
45  OFDBG_LOCATE;
46  BeginDate = OPENFLUID_GetCurrentDate();
47  EndDate = OPENFLUID_GetCurrentDate() + OPENFLUID_GetDefaultDeltaT() - 1;
48  OPENFLUID_UNITS_ORDERED_LOOP("TU",TU)
49  {
50  OFDBG_UNIT_EXTENDED(TU);
51  EvColl.clear();
52  OPENFLUID_GetEvents(TU,BeginDate,EndDate,EvColl);
53  OFDBG_EVENTCOLLECTION(EvColl);
54  }
55  return DefaultDeltaT();
56 }
57 @endcode
58 
59 */
60 
61 
62 #ifndef __OPENFLUID_DEBUG_HPP__
63 #define __OPENFLUID_DEBUG_HPP__
64 
65 
66 // =====================================================================
67 // =====================================================================
68 
69 
70 // OpenFLUID:stylecheck:!incs
71 
72 
73 #ifndef NDEBUG
74 
75 #include <iostream>
76 #include <openfluid/config.hpp>
77 
78 #define OFDBG_ENABLED 1
79 #define OFDBG_OUTSTREAM std::cout
80 
81 #else
82 
83 #define OFDBG_ENABLED 0
84 #define OFDBG_OUTSTREAM
85 
86 #endif
87 
88 
89 // =====================================================================
90 // =====================================================================
91 
92 
93 /**
94  @def OFDBG_LOCATE
95  Displays file/line location where the macro is called
96 */
97 
98 
99 #ifndef NDEBUG
100 
101 #define OFDBG_LOCATE \
102  {\
103  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " File " << __FILE__ << ", Line " << __LINE__ << std::endl;\
104  }
105 
106 #else
107 
108 #define OFDBG_LOCATE ;
109 
110 #endif
111 
112 
113 // =====================================================================
114 // =====================================================================
115 
116 
117 #ifndef NDEBUG
118 
119 #define OFDBG_BANNER \
120  { \
121  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << std::endl; \
122  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " OpenFLUID debugging mode is enabled" << std::endl; \
123  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << std::endl; \
124  }
125 
126 #else
127 
128 #define OFDBG_BANNER
129 
130 #endif
131 
132 
133 // =====================================================================
134 // =====================================================================
135 
136 
137 /**
138  @def OFDBG_MESSAGE
139  Displays the given message
140 */
141 
142 
143 #ifndef NDEBUG
144 
145 #define OFDBG_MESSAGE(stream) \
146  { OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " " << stream << std::endl; }
147 
148 #else
149 
150 #define OFDBG_MESSAGE(stream)
151 
152 #endif
153 
154 
155 // =====================================================================
156 // =====================================================================
157 
158 
159 /**
160  @def OFDBG_UNIT
161  Displays information about the given spatial unit
162 */
163 
164 
165 #ifndef NDEBUG
166 
167 #define OFDBG_UNIT(unitptr) \
168  {\
169  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Unit class " << (unitptr)->getClass()\
170  << ", ID " << (unitptr)->getID() << std::endl;\
171  }
172 
173 #else
174 
175 #define OFDBG_UNIT(unitptr)
176 
177 #endif
178 
179 
180 // =====================================================================
181 // =====================================================================
182 
183 
184 /**
185  @def OFDBG_UNIT_EXTENDED
186  Displays extended information about the given spatial unit
187 */
188 
189 
190 #ifndef NDEBUG
191 
192 #define OFDBG_UNIT_EXTENDED(unitptr) \
193  { \
194  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Unit class " << (unitptr)->getClass()\
195  << ", ID " << (unitptr)->getID() << std::endl; \
196  std::vector<openfluid::core::AttributeName_t> _M_DBG_AttrsNames = (unitptr)->attributes()->getAttributesNames(); \
197  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - Attributes: "; \
198  for (unsigned int i=0; i<_M_DBG_AttrsNames.size();i++) OFDBG_OUTSTREAM << _M_DBG_AttrsNames[i] << " , "; \
199  OFDBG_OUTSTREAM << std::endl; \
200  std::vector<openfluid::core::VariableName_t> _M_DBG_VarNames = (unitptr)->variables()->getVariablesNames(); \
201  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - Variables: "; \
202  for (unsigned int i=0; i<_M_DBG_VarNames.size();i++) OFDBG_OUTSTREAM << _M_DBG_VarNames[i] << " , "; \
203  OFDBG_OUTSTREAM << std::endl; \
204  }
205 
206 #else
207 
208 #define OFDBG_UNIT_EXTENDED(unitptr)
209 
210 #endif
211 
212 
213 // =====================================================================
214 // =====================================================================
215 
216 
217 /**
218  @def OFDBG_EVENT
219  Displays information about the given event
220 */
221 
222 
223 #ifndef NDEBUG
224 
225 #define OFDBG_EVENT(eventptr) \
226  { \
227  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX\
228  << " Event at " << (eventptr)->getDateTime().getAsISOString() << std::endl; \
229  openfluid::core::Event::EventInfosMap_t::iterator _M_DBG_EvInfoiter; \
230  for (_M_DBG_EvInfoiter = (eventptr)->getInfos().begin();\
231  _M_DBG_EvInfoiter != (eventptr)->getInfos().end();++_M_DBG_EvInfoiter) \
232  { \
233  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - "\
234  << (*_M_DBG_EvInfoiter).first << " = " << (*_M_DBG_EvInfoiter).second.get() << std::endl; \
235  } \
236  }
237 
238 #else
239 
240 #define OFDBG_EVENT(eventptr)
241 
242 #endif
243 
244 
245 // =====================================================================
246 // =====================================================================
247 
248 
249 /**
250 @def OFDBG_EVENTCOLLECTION
251 Displays information about the given event collection
252 */
253 
254 
255 #ifndef NDEBUG
256 
257 #define OFDBG_EVENTCOLLECTION(eventcoll) \
258  { \
259  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Event collection size : "\
260  << eventcoll.eventsList()->size() << std::endl; \
261  openfluid::core::EventsList_t::iterator _M_DBG_EvListiter; \
262  for (_M_DBG_EvListiter=(EvColl.eventsList())->begin();\
263  _M_DBG_EvListiter != (EvColl.eventsList())->end(); ++_M_DBG_EvListiter) \
264  { \
265  OFDBG_EVENT(&(*_M_DBG_EvListiter)); \
266  } \
267  }
268 
269 #else
270 
271 #define OFDBG_EVENTCOLLECTION(eventcoll)
272 
273 #endif
274 
275 
276 #endif /* __OPENFLUID_DEBUG_HPP__ */