hpp-util  4.9.0
Debugging tools for the HPP project.
assertion.hh
Go to the documentation of this file.
1 // Copyright (C) 2010 by Thomas Moulard, CNRS.
2 //
3 // This file is part of the hpp-util.
4 //
5 // This software is provided "as is" without warranty of any kind,
6 // either expressed or implied, including but not limited to the
7 // implied warranties of fitness for a particular purpose.
8 //
9 // See the COPYING file for more information.
10 
11 #ifndef HPP_UTIL_ASSERTION_HH
12 # define HPP_UTIL_ASSERTION_HH
13 # include <boost/scope_exit.hpp>
14 
15 # include <hpp/util/config.hh>
16 # include <hpp/util/exception.hh>
17 
18 // If debug mode is disabled and assertions are not already
19 // disabled, disable them automatically.
20 # if (defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS)
21 # define HPP_ENABLE_ASSERTIONS
22 # endif // (!defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS)
23 
24 namespace hpp
25 {
26  HPP_MAKE_EXCEPTION (HPP_UTIL_DLLAPI, AssertionError);
27 } // end of namespace hpp.
28 
33 # ifdef HPP_ENABLE_ASSERTIONS
34 # define HPP_ASSERT(CONDITION) \
35  do { \
36  bool _x = static_cast<bool>(CONDITION); \
37  if (!_x) \
38  HPP_THROW_EXCEPTION \
39  (::hpp::AssertionError, \
40  #CONDITION " evaluates to false"); \
41  } while (0)
42 # else
43 # define HPP_ASSERT(CONDITION)
44 # endif // HPP_ENABLE_ASSERTIONS
45 
47 # define HPP_PRECONDITION(CONDITION) HPP_ASSERT (CONDITION)
48 
49 #endif
Definition: assertion.hh:24
HPP_MAKE_EXCEPTION(HPP_UTIL_DLLAPI, AssertionError)