G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsDebug.h
Go to the documentation of this file.
1
15// Start DEBUG_GROUP of Doxygen
18#pragma once
19
20#include <iostream>
21#include <sstream>
22#include <iomanip>
23#include <stdexcept>
24#include <typeinfo>
25
26// See also about memory leak detection:
27// http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.90%29.aspx
28#if _MSC_VER //>= 1400
29#include <crtdbg.h>
30//#include <errno.h>
31#endif
32
33//#ifdef GISMO_WITH_XDEBUG
34// #include <misc/gsStackWalker.h>
35//#endif
36
37namespace gismo {
38
43#define gsInfo std::cout
44
50#define gsWarn std::cout<<"Warning: "
51//#define gsWarn std::cerr
52
59#ifndef NDEBUG
60
61 #define gsDebug std::cout<<"GISMO_DEBUG: "
62
63 #define gsDebugVar(variable) gsDebug << (strrchr(__FILE__, '/') ? \
64 strrchr(__FILE__, '/') + 1 : __FILE__) <<":"<< \
65 __LINE__<< ", "#variable": \n"<<(variable)<<std::endl
66#define gsDebugIf(cond,variable) if (cond) gsDebug <<"[ "#cond" ] -- "<< \
67 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) \
68 <<":"<<__LINE__<< ", "#variable": \n"<<(variable)<<std::endl
69#else
70 #define gsDebug if (0) std::cout
71 #define gsDebugVar(variable)
72 #define gsDebugIf(cond,variable)
73#endif
74
82#define GISMO_HPP_HEADER(x) #x
83
88#ifndef NDEBUG
89# define GISMO_ASSERT(cond, message) do if(!(cond)) {std::cerr \
90 <<"Assert `"<<#cond<<"` "<<message<<"\n"<<__FILE__<<", line "\
91 <<__LINE__<<" ("<<__FUNCTION__<<")"<<std::endl; \
92 throw std::logic_error("GISMO_ASSERT"); } while(false)
93#else
94# define GISMO_ASSERT(condition, message)
95#endif
96
102#define GISMO_ENSURE(cond, message) do if(!(cond)) {std::cerr \
103 <<"Ensure `"<<#cond<<"` "<<message<<"\n"<<__FILE__<<", line " \
104 <<__LINE__<<" ("<< __FUNCTION__<< ")"<<std::endl; \
105 throw std::runtime_error("GISMO_ENSURE");} while(false)
106
112#define GISMO_UNUSED(x) static_cast<void>(x)
113
118#define GISMO_ERROR(message) do {std::cerr <<"Error " <<message<<"\n"\
119 <<__FILE__<<", line " <<__LINE__<<" ("<<__FUNCTION__<<")"<<std::endl; \
120 throw std::runtime_error("GISMO_ERROR");} while(false)
121
128// TO DO: for GCC __PRETTY_FUNC__ is better
129#define GISMO_NO_IMPLEMENTATION {std::cerr \
130 <<"Virtual member function `"<<__FUNCTION__<<"` has not been implemented\n" \
131 <<__FILE__<<", line "<<__LINE__<<"\n"<<typeid(*this).name()<<std::endl; \
132 throw std::runtime_error("GISMO_NO_IMPLEMENTATION");}
133
134/*
135#ifdef _MSC_VER
136#include <float.h>
137template <typename T> int isnan (T a) {return _isnan(a); }
138template <typename T> int isfinite(T a){return _finite(a);}
139template <typename T> bool isinf(T a) {return (_FPCLASS_PINF|_FPCLASS_NINF) & _fpclass(a);}
140 #else
141#ifdef _INTEL_COMPILER
142#include <mathimf.h>
143#else
144using std::isnan;
145using std::isfinite;
146using std::isinf;
147#endif
148*/
155template <typename T> bool gsIsnumber(T a) {return a == a;}
156template <typename T> bool gsIsnan (T a) {return a != a;}
162template <typename T> bool gsIsfinite(T a) {return (a - a) == (a - a);}
163
164}//namespace gismo
165
166/*
167 Disable debug/abort popup windows on MS Windows
168
169 See http://msdn.microsoft.com/en-us/library/1y71x448.aspx
170
171 You might also need to disable "error reporting" on your windows
172 system for popup-free runs.
173*/
174#if _MSC_VER //>= 1400
175static const int gismo_CrtSetReportMode = _CrtSetReportMode(
176 _CRT_ASSERT, _CRTDBG_MODE_FILE );
177static const _HFILE gismo_CrtSetReportFile = _CrtSetReportFile(
178 _CRT_ASSERT, _CRTDBG_FILE_STDERR );
179static const int gismo_set_abort_behavior = _set_abort_behavior(
180 0x0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
181#endif
182
183/*
184 Disable some Warnings
185*/
186
187#ifdef _MSC_VER
188// 4100 - unreferenced formal parameter
189// 4101 - unreferenced local variable
190// 4127 - conditional expression is constant (triggered by assertion macros)
191// 4146 - unary minus operator applied to unsigned type, result still unsigned
192// 4181 - qualifier applied to reference type ignored
193// 4211 - nonstandard extension used : redefined extern to static
194// 4231 - nonstandard extension used: extern before template explicit instantiation
195// 4244 - 'argument' : conversion from 'type1' to 'type2', possible loss of data
196// 4251 - needs to have dll-interface to be used by clients of class
197// 4273 - QtAlignedMalloc, inconsistent DLL linkage
198// 4275 - non dll-interface base
199// 4324 - structure was padded due to declspec(align())
200// 4428 - universal-character-name encountered in source
201// 4503 - decorated name length exceeded
202// 4505 - unreferenced local function has been removed
203// 4512 - assignment operator could not be generated
204// 4522 - 'class' : multiple assignment operators specified
205// 4566 - character represented by universal-character-name cannot be represented in the current code page
206// 4661 - no definition available
207// 4700 - uninitialized local variable 'xyz' used
208// 4702 - unreachable code
209// 4714 - function marked as __forceinline not inlined
210// 4717 - 'function' : recursive on all control paths, function will cause runtime stack overflow
211// 4789 - destination of memory copy is too small (for Eigen)
212// 4996 - 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead.
213// 4510 - default constructor could not be generated
214// 4610 - user defined constructor required
215// 4752 - found Intel(R) Advanced Vector Extensions; consider using /arch:AVX
216 #pragma warning( push )
217 #pragma warning( disable : 4100 4127 4146 4231 4251 4428 4275 4503 4505 4512 4566 4661 4714 4789 4996 4510 4610 4752)
218
219#elif defined __INTEL_COMPILER
220// 2196 - routine is both "inline" and "noinline" ("noinline" assumed)
221// ICC 12 generates this warning even without any inline keyword, when defining class methods 'inline' i.e. inside of class body
222// typedef that may be a reference type.
223// 279 - controlling expression is constant
224// ICC 12 generates this warning on assert(constant_expression_depending_on_template_params) and frankly this is a legitimate use case.
225// 161 - unrecognized pragma
226// 175 - subscript out of range
227// to avoid warnings on #pragma GCC diagnostic
228 #pragma warning push
229 #pragma warning disable 2196 279 161 175
230
231#elif defined __clang__
232// -Wconstant-logical-operand - warning: use of logical && with constant operand; switch to bitwise & or remove constant
233// -Wbind-to-temporary-copy - warning: Warn about an unusable copy constructor when binding a reference to a temporary
234 #pragma clang diagnostic push
235 #pragma clang diagnostic ignored "-Wconstant-logical-operand"
236 #pragma clang diagnostic ignored "-Wbind-to-temporary-copy"
237
238#elif defined __GNUC__ // major version >=4
239// typedef locally defined but not used [-Wunused-local-typedefs]
240#if ( __GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>7) )
241#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
242#endif
243
244#if (__cplusplus < 201703L && __GNUC__>6)
245// mangled name will change in C++17 because the exception
246// specification is part of a function type [-Wnoexcept-type]
247#pragma GCC diagnostic ignored "-Wnoexcept-type"
248#endif
249
250#endif
251
252
253/*
254 Compile-time assertions:
255
256 - in GISMO_STATIC_ASSERT(CONDITION,MSG) the parameter CONDITION
257 must be a compile time boolean expression, and MSG an error
258 message (string)
259
260 - define GISMO_NO_STATIC_ASSERT to disable them (and save
261 compilation time) in that case, the static assertion is
262 converted to a runtime assertion.
263
264 - GISMO_STATIC_ASSERT can only be used in function scope
265 */
266#ifndef GISMO_NO_STATIC_ASSERT
267
268 #if defined(__GXX_EXPERIMENTAL_CXX0X__) || _MSC_VER >= 1600
269
270 // Native static_assert is available
271 #define GISMO_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);
272
273 #else // not C++11
274
275 namespace gismo {
276 namespace internal {
277
278 template<bool condition> struct static_assertion {};
279 template<> struct static_assertion<true> { enum { STATIC_ASSERTION_FAILED }; };
280
281 } // end namespace internal
282 } // end namespace gismo
283
284 // Specialized implementation for MSVC to avoid "conditional
285 // expression is constant" warnings. This implementation doesn't
286 // appear to work under GCC, hence the multiple implementations.
287 #ifdef _MSC_VER
288
289 #define GISMO_STATIC_ASSERT(CONDITION,MSG) \
290 {gismo::internal::static_assertion<bool(CONDITION)>::STATIC_ASSERTION_FAILED;}
291
292 #else
293
294 #define GISMO_STATIC_ASSERT(CONDITION,MSG) \
295 if (gismo::internal::static_assertion<bool(CONDITION)>::STATIC_ASSERTION_FAILED) {}
296
297 #endif
298
299 #endif // not C++11
300
301#else // GISMO_NO_STATIC_ASSERT
302
303#define GISMO_STATIC_ASSERT(CONDITION,MSG) GISMO_ASSERT(CONDITION, #MSG);
304
305#endif // GISMO_NO_STATIC_ASSERT
306
307
308
309#ifdef GISMO_WITH_WARNINGS
310 //#pragma message("G+Smo Warnings ON")
311 #ifdef __GNUC__
312 #define GISMO_DEPRECATED __attribute__((deprecated))
313 #elif defined(_MSC_VER)
314 #define GISMO_DEPRECATED __declspec(deprecated)
315 #else
316 #define GISMO_DEPRECATED
317 #endif
318#else
319 #define GISMO_DEPRECATED
320#endif
321
322
323// Next line closes the DEBUG_GROUP of Doxygen
The G+Smo namespace, containing all definitions for the library.
bool gsIsfinite(T a)
Definition gsDebug.h:162
bool gsIsnumber(T a)
Definition gsDebug.h:155