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