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