GCC Code Coverage Report


Directory: ./
File: include/hpp/util/assertion.hh
Date: 2025-05-17 13:07:10
Exec Total Coverage
Lines: 1 1 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // Copyright (C) 2010 by Thomas Moulard, CNRS.
2 //
3
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 // DAMAGE.
27 //
28 // This software is provided "as is" without warranty of any kind,
29 // either expressed or implied, including but not limited to the
30 // implied warranties of fitness for a particular purpose.
31 //
32 // See the COPYING file for more information.
33
34 #ifndef HPP_UTIL_ASSERTION_HH
35 #define HPP_UTIL_ASSERTION_HH
36 #include <hpp/util/config.hh>
37 #include <hpp/util/exception.hh>
38
39 // If debug mode is disabled and assertions are not already
40 // disabled, disable them automatically.
41 #if (defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS)
42 #define HPP_ENABLE_ASSERTIONS
43 #endif // (!defined HPP_DEBUG) && (!defined HPP_ENABLE_ASSERTIONS)
44
45 namespace hpp {
46 3 HPP_MAKE_EXCEPTION(HPP_UTIL_DLLAPI, AssertionError);
47 } // end of namespace hpp.
48
49 /// \brief Define HPP_ASSERT.
50 ///
51 /// Throw an ::hpp::AssertionError if macro argument evaluates to
52 /// false.
53 #ifdef HPP_ENABLE_ASSERTIONS
54 #define HPP_ASSERT(CONDITION) \
55 do { \
56 bool _x = static_cast<bool>(CONDITION); \
57 if (!_x) \
58 HPP_THROW_EXCEPTION(::hpp::AssertionError, \
59 #CONDITION " evaluates to false"); \
60 } while (0)
61 #else
62 #define HPP_ASSERT(CONDITION)
63 #endif // HPP_ENABLE_ASSERTIONS
64
65 /// \brief Define macro for precondition checking.
66 #define HPP_PRECONDITION(CONDITION) HPP_ASSERT(CONDITION)
67
68 #endif //! HPP_UTIL_ASSERTION_HH
69