libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
assert.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2016 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QI_ASSERT_HPP_
8 #define _QI_ASSERT_HPP_
9 
10 
11 #include <boost/predef/compiler.h>
12 
13 /* TODO:
14  - add assertion variants (assert_if);
15  - add a way to force assert activation whatever the build mode;
16  - add a way to chose assertion behaviour at compile time (not necessarilly abort);
17  - add a way to force assertion behaviour whatever the platform;
18 */
19 # if defined(NDEBUG)
20 # define QI_ASSERT(expr__)
21 # else
22 # if BOOST_COMP_MSVC
23 # include <cstdlib>
24 # define QI_ASSERT( expr__ ) { if( !( expr__ ) ){ __debugbreak(); ::std::abort(); } }
25 # else
26 # include <cassert>
27 # define QI_ASSERT( expr__ ) assert( expr__ )
28 # endif
29 # endif
30 
31 # define QI_ASSERT_TRUE( expr__ ) QI_ASSERT( expr__ )
32 # define QI_ASSERT_FALSE( expr__ ) QI_ASSERT( !(expr__) )
33 # define QI_ASSERT_UNREACHABLE() QI_ASSERT( false )
34 # define QI_ASSERT_NULL( expr__ ) QI_ASSERT_TRUE( expr__ == nullptr )
35 # define QI_ASSERT_NOT_NULL( expr__ ) QI_ASSERT_TRUE( expr__ != nullptr )
36 
41 # define QI_TRUE_OR_RETURN_FALSE( expr__ ) if (!(expr__)) return false
42 
43 #endif // _QI_ASSERT_HPP_