Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
checks.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef CHECK_INCLUDED
33 #define CHECK_INCLUDED
34 
35 #include <vlCore/link_config.hpp>
36 
37 // Required for IsDebuggerPresent()
38 #if defined(VL_PLATFORM_WINDOWS)
39  #ifndef WIN32_LEAN_AND_MEAN
40  #define WIN32_LEAN_AND_MEAN 1
41  #endif
42  #ifndef NOMINMAX
43  #define NOMINMAX
44  #endif
45  #include <windows.h>
46 #endif
47 
48 #if defined(__GNUG__) || defined(__MINGW32__)
49  #include <cstdio>
50 #endif
51 
52 namespace vl
53 {
54  VLCORE_EXPORT void log_failed_check(const char*, const char*, int);
55 
56  VLCORE_EXPORT void abort_vl();
57 
58  // Compile-time check
59  #define VL_COMPILE_TIME_CHECK( expr ) typedef char compile_time_assert[ (expr) ? 1 : -1 ];
60 
61  #if defined(_DEBUG) || !defined(NDEBUG) || VL_FORCE_CHECKS == 1
62 
63  // Visual Studio
64  #if defined(_MSC_VER)
65  #define VL_TRAP() { if (IsDebuggerPresent()) { __debugbreak(); } else ::vl::abort_vl(); }
66  // GNU GCC
67  #elif defined(__GNUG__) || defined(__MINGW32__)
68  #define VL_TRAP() { fflush(stdout); fflush(stderr); asm("int $0x3"); }
69  #else
70  #define VL_TRAP() { ::vl::abort_vl(); }
71  #endif
72 
73  #define VL_CHECK(expr) { if(!(expr)) { ::vl::log_failed_check(#expr,__FILE__,__LINE__); VL_TRAP() } }
74  #define VL_WARN(expr) { if(!(expr)) { ::vl::log_failed_check(#expr,__FILE__,__LINE__); } }
75 
76  // MSDN checked iterators
77  // #define _SECURE_SCL 1
78  #else
79  #define VL_WARN(expr) {}
80  #define VL_CHECK(expr) {}
81  #define VL_TRAP() {}
82 
83  // MSDN checked iterators
84  // #define _SECURE_SCL 0
85  #endif
86 }
87 
88 #endif
VLCORE_EXPORT void abort_vl()
Definition: pimpl.cpp:121
VLCORE_EXPORT void log_failed_check(const char *, const char *, int)
Definition: Log.cpp:185
Visualization Library main namespace.