catch_context.hpp
1 2 // Copyright Catch2 Authors 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE.txt or copy at 5 // https://www.boost.org/LICENSE_1_0.txt) 6 7 // SPDX-License-Identifier: BSL-1.0 8 #ifndef CATCH_CONTEXT_HPP_INCLUDED 9 #define CATCH_CONTEXT_HPP_INCLUDED 10 11 #include <catch2/internal/catch_compiler_capabilities.hpp> 12 13 namespace Catch { 14 15 class IResultCapture; 16 class IConfig; 17 18 class Context { 19 IConfig const* m_config = nullptr; 20 IResultCapture* m_resultCapture = nullptr; 21 22 CATCH_EXPORT static Context* currentContext; 23 friend Context& getCurrentMutableContext(); 24 friend Context const& getCurrentContext(); 25 static void createContext(); 26 friend void cleanUpContext(); 27 28 public: 29 IResultCapture* getResultCapture() const { return m_resultCapture; } 30 IConfig const* getConfig() const { return m_config; } 31 void setResultCapture( IResultCapture* resultCapture ); 32 void setConfig( IConfig const* config ); 33 }; 34 35 Context& getCurrentMutableContext(); 36 37 inline Context const& getCurrentContext() { 38 // We duplicate the logic from `getCurrentMutableContext` here, 39 // to avoid paying the call overhead in debug mode. 40 if ( !Context::currentContext ) { Context::createContext(); } 41 // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) 42 return *Context::currentContext; 43 } 44 45 void cleanUpContext(); 46 47 class SimplePcg32; 48 SimplePcg32& sharedRng(); 49 } 50 51 #endif // CATCH_CONTEXT_HPP_INCLUDED