All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
39 
40 #ifndef __OPENFLUID_DEBUG_HPP__
41 #define __OPENFLUID_DEBUG_HPP__
42 
43 // =====================================================================
44 // =====================================================================
45 
46 
47 #ifndef NDEBUG
48 
49 #include <iostream>
50 #include <openfluid/config.hpp>
51 
52 #define OFDBG_ENABLED 1
53 #define OFDBG_OUTSTREAM std::cout
54 
55 #else
56 
57 #define OFDBG_ENABLED 0
58 #define OFDBG_OUTSTREAM
59 
60 #endif
61 
62 
63 // =====================================================================
64 // =====================================================================
65 
66 
67 #ifndef NDEBUG
68 
69 #define OFDBG_LOCATE \
70  {\
71  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " File " << __FILE__ << ", Line " << __LINE__ << std::endl;\
72  }
73 
74 #else
75 
76 #define OFDBG_LOCATE ;
77 
78 #endif
79 
80 
81 // =====================================================================
82 // =====================================================================
83 
84 
85 #ifndef NDEBUG
86 
87 #define OFDBG_BANNER \
88  { \
89  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << std::endl; \
90  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " OpenFLUID debugging mode is enabled" << std::endl; \
91  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << std::endl; \
92  }
93 
94 #else
95 
96 #define OFDBG_BANNER
97 
98 #endif
99 
100 
101 // =====================================================================
102 // =====================================================================
103 
104 
105 #ifndef NDEBUG
106 
107 #define OFDBG_MESSAGE(stream) \
108  { OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " " << stream << std::endl; }
109 
110 #else
111 
112 #define OFDBG_MESSAGE(stream)
113 
114 #endif
115 
116 
117 // =====================================================================
118 // =====================================================================
119 
120 
121 #ifndef NDEBUG
122 
123 #define OFDBG_UNIT(unitptr) \
124  {\
125  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Unit class " << (unitptr)->getClass()\
126  << ", ID " << (unitptr)->getID() << std::endl;\
127  }
128 
129 #else
130 
131 #define OFDBG_UNIT(unitptr)
132 
133 #endif
134 
135 
136 // =====================================================================
137 // =====================================================================
138 
139 
140 #ifndef NDEBUG
141 
142 #define OFDBG_UNIT_EXTENDED(unitptr) \
143  { \
144  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Unit class " << (unitptr)->getClass()\
145  << ", ID " << (unitptr)->getID() << std::endl; \
146  std::vector<openfluid::core::AttributeName_t> _M_DBG_AttrsNames = (unitptr)->attributes()->getAttributesNames(); \
147  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - Attributes: "; \
148  for (unsigned int i=0; i<_M_DBG_AttrsNames.size();i++) OFDBG_OUTSTREAM << _M_DBG_AttrsNames[i] << " , "; \
149  OFDBG_OUTSTREAM << std::endl; \
150  std::vector<openfluid::core::VariableName_t> _M_DBG_VarNames = (unitptr)->variables()->getVariablesNames(); \
151  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - Variables: "; \
152  for (unsigned int i=0; i<_M_DBG_VarNames.size();i++) OFDBG_OUTSTREAM << _M_DBG_VarNames[i] << " , "; \
153  OFDBG_OUTSTREAM << std::endl; \
154  }
155 
156 #else
157 
158 #define OFDBG_UNIT_EXTENDED(unitptr)
159 
160 #endif
161 
162 
163 // =====================================================================
164 // =====================================================================
165 
166 
167 #ifndef NDEBUG
168 
169 #define OFDBG_EVENT(eventptr) \
170  { \
171  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX\
172  << " Event at " << (eventptr)->getDateTime().getAsISOString() << std::endl; \
173  openfluid::core::Event::EventInfosMap_t::iterator _M_DBG_EvInfoiter; \
174  for (_M_DBG_EvInfoiter = (eventptr)->getInfos().begin();\
175  _M_DBG_EvInfoiter != (eventptr)->getInfos().end();++_M_DBG_EvInfoiter) \
176  { \
177  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " - "\
178  << (*_M_DBG_EvInfoiter).first << " = " << (*_M_DBG_EvInfoiter).second.get() << std::endl; \
179  } \
180  }
181 
182 #else
183 
184 #define OFDBG_EVENT(eventptr)
185 
186 #endif
187 
188 
189 // =====================================================================
190 // =====================================================================
191 
192 
193 #ifndef NDEBUG
194 
195 #define OFDBG_EVENTCOLLECTION(eventcoll) \
196  { \
197  OFDBG_OUTSTREAM << openfluid::config::DEBUG_PREFIX << " Event collection size : "\
198  << eventcoll.eventsList()->size() << std::endl; \
199  openfluid::core::EventsList_t::iterator _M_DBG_EvListiter; \
200  for (_M_DBG_EvListiter=(EvColl.eventsList())->begin();\
201  _M_DBG_EvListiter != (EvColl.eventsList())->end(); ++_M_DBG_EvListiter) \
202  { \
203  OFDBG_EVENT(&(*_M_DBG_EvListiter)); \
204  } \
205  }
206 
207 #else
208 
209 #define OFDBG_EVENTCOLLECTION(eventcoll)
210 
211 #endif
212 
213 
214 #endif /* __OPENFLUID_DEBUG_HPP__ */