File indexing completed on 2025-01-30 10:02:49
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
0009 #define CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
0010
0011 #include <catch2/internal/catch_platform.hpp>
0012 #include <catch2/internal/catch_compiler_capabilities.hpp>
0013
0014 #include <cassert>
0015
0016 namespace Catch {
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 class FatalConditionHandler {
0029 bool m_started = false;
0030
0031
0032
0033
0034 void engage_platform();
0035 void disengage_platform() noexcept;
0036 public:
0037
0038 FatalConditionHandler();
0039 ~FatalConditionHandler();
0040
0041 void engage() {
0042 assert(!m_started && "Handler cannot be installed twice.");
0043 m_started = true;
0044 engage_platform();
0045 }
0046
0047 void disengage() noexcept {
0048 assert(m_started && "Handler cannot be uninstalled without being installed first");
0049 m_started = false;
0050 disengage_platform();
0051 }
0052 };
0053
0054
0055 class FatalConditionHandlerGuard {
0056 FatalConditionHandler* m_handler;
0057 public:
0058 FatalConditionHandlerGuard(FatalConditionHandler* handler):
0059 m_handler(handler) {
0060 m_handler->engage();
0061 }
0062 ~FatalConditionHandlerGuard() {
0063 m_handler->disengage();
0064 }
0065 };
0066
0067 }
0068
0069 #endif