CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsIoMacros.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
33 #pragma once
34 
35 #include <exception>
36 
41 
43 #define NOARG
44 
49 #define CEPS_IO_DECIMAL_PRECISION 8
50 
55 #define CEPS_WARNING "WARNING"
60 #define CEPS_ERROR "FATAL ERROR"
65 #define CEPS_COLORED_WARNING "\033[1m\033[34mWARNING\033[0m"
70 #define CEPS_COLORED_ERROR "\033[1m\033[31mFATAL_ERROR\033[0m"
71 /*
72  * @def CEPS_SEPARATOR_LENGTH
73  * @brief Number of characters in separator lines
74  */
75 #define CEPS_SEPARATOR_LENGTH 77
80 #define CEPS_STRING_SEPARATOR std::string (CEPS_SEPARATOR_LENGTH, '-')
85 #define CEPS_SEPARATOR CEPS_SAYS (CEPS_STRING_SEPARATOR)
86 
91 #define CEPS_SAYS_IN_PROGRESS(message) \
92  do \
93  { \
94  if (ceps::isDebug ()) \
95  { \
96  ceps::debugLog () << "\r · " << message << std::flush; \
97  } \
98  if (ceps::isVerbose ()) \
99  { \
100  std::cout << "\r · " << message << std::flush; \
101  } \
102  } while (false)
103 
108 #define CEPS_SAYS(message) \
109  do \
110  { \
111  if (ceps::isDebug ()) \
112  { \
113  ceps::debugLog () << " · " << message << std::endl; \
114  } \
115  if (ceps::isVerbose ()) \
116  { \
117  std::cout << " · " << message << std::endl; \
118  } \
119  } while (false)
124 #define CEPS_SAYS_IN_GREEN(message) \
125  do \
126  { \
127  if (ceps::isDebug ()) \
128  { \
129  ceps::debugLog () << " · " << message << std::endl; \
130  } \
131  if (ceps::isVerbose ()) \
132  { \
133  std::cout << " · \033[1m\033[32;1m" << message << "\033[0m"<< std::endl; \
134  } \
135  } while (false)
136 
137 
142 #define CEPS_SAYS_NOENDL(message) \
143  do \
144  { \
145  if (ceps::isDebug ()) \
146  { \
147  ceps::debugLog () << " · " << message; \
148  } \
149  if (ceps::isVerbose ()) \
150  { \
151  std::cout << " · " << message; \
152  } \
153  std::flush(std::cout); \
154  } while (false)
155 
160 #define CEPS_SAYS_INLINE(message) \
161  do \
162  { \
163  if (ceps::isDebug ()) \
164  { \
165  ceps::debugLog () << message << std::endl; \
166  } \
167  if (ceps::isVerbose ()) \
168  { \
169  std::cout << message << std::endl; \
170  } \
171  } while (false)
172 
177 #define CEPS_SAYS_IF(condition, message) \
178  do \
179  { \
180  if (condition) \
181  { \
182  CEPS_SAYS (message); \
183  } \
184  } while (false)
185 
186 #ifdef CEPS_DEBUG_ENABLED
191  #define CEPS_WARNS(message) \
192  do \
193  { \
194  if (ceps::isWarnings()) \
195  { \
196  std::ostringstream oss; \
197  oss << message; \
198  CepsException ___e(oss.str(),true); \
199  std::cerr << ___e.errorMessage(true) << std::endl; \
200  ceps::debugLog() << ___e.errorMessage(false) << std::endl; \
201  } \
202  } while (false)
203 
209  #define CEPS_WARNS_IF(condition, message) \
210  do \
211  { \
212  if ((condition) && ceps::isWarnings ()) \
213  { \
214  std::ostringstream oss; \
215  oss << message; \
216  CepsException ___e(oss.str(),true); \
217  std::cerr << ___e.errorMessage(true) << std::endl; \
218  ceps::debugLog() << ___e.errorMessage(false) << std::endl; \
219  } \
220  } while (false)
221 #else
226  #define CEPS_WARNS(message) \
227  do \
228  { \
229  if (ceps::isWarnings()) \
230  { \
231  std::ostringstream oss; \
232  oss << message; \
233  CepsException ___e(oss.str(),true); \
234  std::cerr << ___e.errorMessage(true) << std::endl; \
235  } \
236  } while (false)
237 
243  #define CEPS_WARNS_IF(condition, message) \
244  do \
245  { \
246  if ((condition) && ceps::isWarnings()) \
247  { \
248  std::ostringstream oss; \
249  oss << message; \
250  CepsException ___e(oss.str(),true); \
251  std::cerr << ___e.errorMessage(true) << std::endl; \
252  } \
253  } while (false)
254 #endif
255 
256  //std::cerr << ceps::warningReportString(oss.str(),__FILE__,__LINE__,__PRETTY_FUNCTION__,true);
257 // ==========================================================================
258 // Assertion (and stop) macros
259 
264 #define CEPS_ABORT(message) \
265  do { \
266  std::ostringstream oss; \
267  oss << message; \
268  throw CepsException(oss.str()); \
269  } while (false)
270 
275 #define CEPS_ABORT_IF(condition,message)\
276  do { \
277  if (condition) \
278  { \
279  std::ostringstream oss; \
280  oss << message; \
281  throw CepsException(oss.str()); \
282  } \
283  } while (false)
284 
289 #define CEPS_CHECK_IS_NAN(value, message) \
290  CEPS_WARNS_IF( \
291  std::isnan(value) or ! std::isfinite(value), "Value is NaN or infinity.\n · " << message \
292  )
293 
294 // ==========================================================================
295 // Utility for debugging
296 //
297 // Use CEPS_DISPLAY_VAL(foo,bar,...) to print the names
298 // and values of variables foo, bar, etc in a std::ostream.
299 // Example:
300 // myFile << CEPS_DISPLAY_VAL(foo,bar) << std::endl;
301 //
302 // Use DISP(foo,bar); for direct printing on std::cout
303 
308 #define CEPS_DVAL_1(_0, ...) "\"" << #_0 << "\" : " << _0
313 #define CEPS_DVAL_2(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_1(__VA_ARGS__)
318 #define CEPS_DVAL_3(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_2(__VA_ARGS__)
323 #define CEPS_DVAL_4(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_3(__VA_ARGS__)
328 #define CEPS_DVAL_5(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_4(__VA_ARGS__)
333 #define CEPS_DVAL_6(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_5(__VA_ARGS__)
338 #define CEPS_DVAL_7(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_6(__VA_ARGS__)
343 #define CEPS_DVAL_8(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_7(__VA_ARGS__)
348 #define CEPS_DVAL_9(_0, ...) CEPS_DVAL_1 (_0) << ", " << CEPS_DVAL_8(__VA_ARGS__)
353 #define VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
358 #define VA_NARGS(...) VA_NARGS_IMPL(_, ##__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
365 #define CEPS_CONCAT_2(x, y) x##y
370 #define CEPS_CONCAT(x, y) CEPS_CONCAT_2(x, y)
375 #define CEPS_DVAL_CALL(N, ...) CEPS_CONCAT(CEPS_DVAL_, N) (__VA_ARGS__)
381 #define CEPS_DISPLAY_VAL(...) CEPS_DVAL_CALL(VA_NARGS (__VA_ARGS__), __VA_ARGS__)
387 #define DISP(...) std::cout << CEPS_DISPLAY_VAL(__VA_ARGS__) << std::endl
388 
395 #define DISPR(...) std::cout << "proc" << ceps::getRank() << " " << CEPS_DISPLAY_VAL(__VA_ARGS__) << std::endl
396 
402 #define SEQDISP(...) \
403 ceps::beginSequential();\
404 DISPR(__VA_ARGS__); \
405 std::flush(std::cout); \
406 ceps::endSequential();
407 
408 #define CEPS_UNIMPLEMENTED static_assert (true, "unimplemented function")
409 
410 #define CEPS_UNUSED(X) (void) X
411