BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Assert.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Utils/Assert.h
6 //! @brief Defines the macro ASSERT.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_BASE_UTILS_ASSERT_H
16 #define BORNAGAIN_BASE_UTILS_ASSERT_H
17 
18 // ASSERT must be declared as a macro, not a function, in order for the error
19 // message to correctly report the source line where the assertion failed.
20 
21 // For an alternative implementation that calls qFatal, see Base/Utils/Assert.h < 29oct20.
22 
23 #include <stdexcept>
24 #include <sstream>
25 
26 #define ASSERT(condition) if (!(condition)) { \
27  std::stringstream msg; \
28  msg << "Assertion " << (#condition) << " failed in " << __FILE__ << ", line " << __LINE__; \
29  throw std::runtime_error(msg.str()); }
30 
31 #endif // BORNAGAIN_BASE_UTILS_ASSERT_H