src/utilities/core/Assert.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_CORE_ASSERT_HPP | ||
| 7 | #define UTILITIES_CORE_ASSERT_HPP | ||
| 8 | |||
| 9 | /**************************************************************************** | ||
| 10 | !!! THIS FILE MUST BE INCLUDED BY ANY SOURCE FILE THAT USES OPENSTUDIO_ASSERT!!! | ||
| 11 | !!! THIS FILE MUST BE INCLUDED BY ANY SOURCE FILE THAT USES BOOST_ASSERT!!! | ||
| 12 | *****************************************************************************/ | ||
| 13 | |||
| 14 | #include "../UtilitiesAPI.hpp" | ||
| 15 | #include "Logger.hpp" | ||
| 16 | |||
| 17 | #include <sstream> | ||
| 18 | |||
| 19 | #define OS_ASSERT(expr) BOOST_ASSERT(expr) | ||
| 20 | |||
| 21 | #ifdef NDEBUG | ||
| 22 | //#define BOOST_DISABLE_ASSERTS | ||
| 23 | # define BOOST_ENABLE_ASSERT_HANDLER | ||
| 24 | #else | ||
| 25 | # define BOOST_ENABLE_ASSERT_HANDLER | ||
| 26 | #endif | ||
| 27 | |||
| 28 | // include after definitions | ||
| 29 | #include <boost/assert.hpp> | ||
| 30 | |||
| 31 | namespace boost { | ||
| 32 | 1 | inline void assertion_failed(char const* expr, char const* function, char const* file, long line) { | |
| 33 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::stringstream ss; |
| 34 |
9/9✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
✓ Branch 25 taken 1 time.
|
1 | ss << "Assertion " << expr << " failed on line " << line << " of " << function << " in file " << file << "."; |
| 35 |
3/3✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
1 | openstudio::Logger::instance().standardErrLogger().enable(); |
| 36 |
6/6✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 11 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 17 taken 1 time.
|
3 | LOG_FREE(Fatal, "BOOST_ASSERT", ss.str()); |
| 37 | assert(false); | ||
| 38 | 1 | } | |
| 39 | |||
| 40 | inline void assertion_failed_msg(char const* expr, char const* msg, char const* function, char const* file, long line) { | ||
| 41 | std::stringstream ss; | ||
| 42 | ss << "Assertion " << expr << " failed on line " << line << " of " << function << " in file " << file << "." << '\n' << msg; | ||
| 43 | openstudio::Logger::instance().standardErrLogger().enable(); | ||
| 44 | LOG_FREE(Fatal, "BOOST_ASSERT", ss.str()); | ||
| 45 | assert(false); | ||
| 46 | } | ||
| 47 | } // namespace boost | ||
| 48 | |||
| 49 | #endif // UTILITIES_CORE_ASSERT_HPP | ||
| 50 |