hpp-util  4.12.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 <hpp/util/config.hh>
14 # include <hpp/util/exception.hh>
15 
16 // If debug mode is disabled and assertions are not already
17 // disabled, disable them automatically.
18 # if (defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS)
19 # define HPP_ENABLE_ASSERTIONS
20 # endif // (!defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS)
21 
22 namespace hpp
23 {
24  HPP_MAKE_EXCEPTION (HPP_UTIL_DLLAPI, AssertionError);
25 } // end of namespace hpp.
26 
31 # ifdef HPP_ENABLE_ASSERTIONS
32 # define HPP_ASSERT(CONDITION) \
33  do { \
34  bool _x = static_cast<bool>(CONDITION); \
35  if (!_x) \
36  HPP_THROW_EXCEPTION \
37  (::hpp::AssertionError, \
38  #CONDITION " evaluates to false"); \
39  } while (0)
40 # else
41 # define HPP_ASSERT(CONDITION)
42 # endif // HPP_ENABLE_ASSERTIONS
43 
45 # define HPP_PRECONDITION(CONDITION) HPP_ASSERT (CONDITION)
46 
47 #endif
Definition: assertion.hh:22
HPP_MAKE_EXCEPTION(HPP_UTIL_DLLAPI, AssertionError)
#define HPP_UTIL_DLLAPI
Definition: config.hh:64