diff options
| author | Martin Hořeňovský | 2023-03-16 10:04:03 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-03-20 20:46:41 +0100 |
| commit | 173aa3f1f401ce1165ec9307d249dc506a976c3e (patch) | |
| tree | b8c0e8e4dde24a8e23a599b6325db3f6541f1663 /src/catch2/internal/catch_context.cpp | |
| parent | 28437e1214fec5ffc4d744c75a894f9cddf8d635 (diff) | |
| download | catch3-173aa3f1f401ce1165ec9307d249dc506a976c3e.tar.gz | |
Devirtualize Context
Diffstat (limited to 'src/catch2/internal/catch_context.cpp')
| -rw-r--r-- | src/catch2/internal/catch_context.cpp | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/src/catch2/internal/catch_context.cpp b/src/catch2/internal/catch_context.cpp index 17f28509..3b1cc277 100644 --- a/src/catch2/internal/catch_context.cpp +++ b/src/catch2/internal/catch_context.cpp @@ -11,49 +11,27 @@ namespace Catch { - class Context : public IMutableContext, private Detail::NonCopyable { + Context* Context::currentContext = nullptr; - public: // IContext - IResultCapture* getResultCapture() override { - return m_resultCapture; - } - - IConfig const* getConfig() const override { - return m_config; - } - - ~Context() override; - - public: // IMutableContext - void setResultCapture( IResultCapture* resultCapture ) override { - m_resultCapture = resultCapture; - } - void setConfig( IConfig const* config ) override { - m_config = config; - } - - friend IMutableContext& getCurrentMutableContext(); - - private: - IConfig const* m_config = nullptr; - IResultCapture* m_resultCapture = nullptr; - }; - - IMutableContext *IMutableContext::currentContext = nullptr; - - void IMutableContext::createContext() - { + void cleanUpContext() { + delete Context::currentContext; + Context::currentContext = nullptr; + } + void Context::createContext() { currentContext = new Context(); } - void cleanUpContext() { - delete IMutableContext::currentContext; - IMutableContext::currentContext = nullptr; + Context& getCurrentMutableContext() { + if ( !Context::currentContext ) { Context::createContext(); } + // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) + return *Context::currentContext; + } + + void Context::setResultCapture( IResultCapture* resultCapture ) { + m_resultCapture = resultCapture; } - IContext::~IContext() = default; - IMutableContext::~IMutableContext() = default; - Context::~Context() = default; + void Context::setConfig( IConfig const* config ) { m_config = config; } SimplePcg32& sharedRng() { static SimplePcg32 s_rng; |