Files
Catch2/include/internal/catch_context.cpp
T

63 lines
1.7 KiB
C++
Raw Normal View History

/*
* Created by Phil on 31/12/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
2012-05-10 08:17:06 +01:00
#include "catch_context.h"
2017-01-16 10:30:44 +00:00
#include "catch_common.h"
2012-05-16 08:02:20 +01:00
namespace Catch {
class Context : public IMutableContext, NonCopyable {
public: // IContext
2017-07-25 17:16:28 +02:00
virtual IResultCapture* getResultCapture() override {
2014-05-20 18:49:28 +01:00
return m_resultCapture;
}
2017-07-25 17:16:28 +02:00
virtual IRunner* getRunner() override {
2014-05-20 18:49:28 +01:00
return m_runner;
}
2017-07-25 17:16:28 +02:00
virtual IConfigPtr getConfig() const override {
return m_config;
}
public: // IMutableContext
2017-07-25 17:16:28 +02:00
virtual void setResultCapture( IResultCapture* resultCapture ) override {
m_resultCapture = resultCapture;
}
2017-07-25 17:16:28 +02:00
virtual void setRunner( IRunner* runner ) override {
m_runner = runner;
}
2017-07-25 17:16:28 +02:00
virtual void setConfig( IConfigPtr const& config ) override {
m_config = config;
}
2013-07-03 19:14:59 +01:00
friend IMutableContext& getCurrentMutableContext();
private:
IConfigPtr m_config;
IRunner* m_runner = nullptr;
IResultCapture* m_resultCapture = nullptr;
};
2013-07-03 19:14:59 +01:00
2012-05-22 08:55:19 +01:00
namespace {
2017-04-25 12:41:30 +02:00
Context* currentContext = nullptr;
2012-05-22 08:55:19 +01:00
}
IMutableContext& getCurrentMutableContext() {
2012-06-05 10:13:52 +01:00
if( !currentContext )
currentContext = new Context();
return *currentContext;
2012-05-22 08:55:19 +01:00
}
IContext& getCurrentContext() {
return getCurrentMutableContext();
}
2011-01-11 09:13:31 +00:00
void cleanUpContext() {
delete currentContext;
2017-04-25 12:41:30 +02:00
currentContext = nullptr;
2011-01-26 23:23:33 +00:00
}
}