Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2012-05-22 08:55:19 +0100
committerPhil Nash2012-05-22 08:55:19 +0100
commit9fa9d4279c070cdab4ebfea973c73e5c75bed429 (patch)
tree5e90e6892c9dc40d968ea7af9da365787b47e7c5 /include
parent61319a9bc102a9ba3ebe6a22941c48b9e01b182d (diff)
downloadcatch3-9fa9d4279c070cdab4ebfea973c73e5c75bed429.tar.gz
Removed "singleton" method from context
There is now a global "currentContext" - but Context itself is not aware of it
Diffstat (limited to 'include')
-rw-r--r--include/internal/catch_context.h8
-rw-r--r--include/internal/catch_context_impl.hpp33
2 files changed, 17 insertions, 24 deletions
diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h
index 6d0052f9..8611064e 100644
--- a/include/internal/catch_context.h
+++ b/include/internal/catch_context.h
@@ -51,10 +51,6 @@ namespace Catch {
Context( const Context& );
void operator=( const Context& );
- public: // friends
- friend IContext& getCurrentContext() { return Context::getCurrent(); }
- friend IMutableContext& getCurrentMutableContext() { return Context::getCurrent(); }
-
public: // IContext
virtual IResultCapture& getResultCapture();
virtual IRunner& getRunner();
@@ -72,9 +68,9 @@ namespace Catch {
static std::streambuf* createStreamBuf( const std::string& streamName );
static void cleanUp();
+ friend IMutableContext& getCurrentMutableContext();
+
private:
- static Context& getCurrent();
- static Context*& singleInstance();
GeneratorsForTest* findGeneratorsForCurrentTest();
GeneratorsForTest& getGeneratorsForCurrentTest();
diff --git a/include/internal/catch_context_impl.hpp b/include/internal/catch_context_impl.hpp
index 83b52869..3c992016 100644
--- a/include/internal/catch_context_impl.hpp
+++ b/include/internal/catch_context_impl.hpp
@@ -17,7 +17,17 @@
namespace Catch {
-
+ namespace {
+ Context* currentHub = NULL;
+ }
+ IMutableContext& getCurrentMutableContext() {
+ if( !currentHub )
+ currentHub = new Context();
+ return *currentHub;
+ }
+ IContext& getCurrentContext() {
+ return getCurrentMutableContext();
+ }
Context::Context()
: m_reporterRegistry( new ReporterRegistry ),
@@ -25,22 +35,9 @@ namespace Catch {
m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry )
{}
- Context*& Context::singleInstance() {
- static Context* hub = NULL;
- return hub;
- }
-
- Context& Context::getCurrent() {
- Context*& hub = singleInstance();
- if( !hub )
- hub = new Context();
- return *hub;
- }
-
void Context::cleanUp() {
- Context*& hub = singleInstance();
- delete hub;
- hub = NULL;
+ delete currentHub;
+ currentHub = NULL;
}
void Context::setRunner( IRunner* runner ) {
@@ -80,7 +77,7 @@ namespace Catch {
}
GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
- std::string testName = getCurrentContext().getResultCapture().getCurrentTestName();
+ std::string testName = getResultCapture().getCurrentTestName();
std::map<std::string, GeneratorsForTest*>::const_iterator it =
m_generatorsByTestName.find( testName );
@@ -92,7 +89,7 @@ namespace Catch {
GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
GeneratorsForTest* generators = findGeneratorsForCurrentTest();
if( !generators ) {
- std::string testName = getCurrentContext().getResultCapture().getCurrentTestName();
+ std::string testName = getResultCapture().getCurrentTestName();
generators = new GeneratorsForTest();
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
}