diff --git a/internal/catch_hub.hpp b/internal/catch_hub.hpp index dc708f24..8119e904 100644 --- a/internal/catch_hub.hpp +++ b/internal/catch_hub.hpp @@ -22,12 +22,17 @@ namespace Catch class Hub { - public: Hub(); + static Hub& me() + { + static Hub hub; + return hub; + } + public: - static IResultListener* getListener(); - static IReporterRegistry* getReporterRegistry(); - static ITestCaseRegistry* getTestCaseRegistry(); + static IResultListener& getListener(); + static IReporterRegistry& getReporterRegistry(); + static ITestCaseRegistry& getTestCaseRegistry(); private: std::auto_ptr m_reporterRegistry; @@ -44,6 +49,11 @@ namespace Catch : m_reporterRegistry( new ReporterRegistry ) { } + + inline IReporterRegistry& Hub::getReporterRegistry() + { + return *me().m_reporterRegistry.get(); + } } #endif // TWOBLUECUBES_CATCH_HUB_HPP_INCLUDED \ No newline at end of file diff --git a/internal/catch_ireporterregistry.h b/internal/catch_ireporterregistry.h index eade407a..e4f303a5 100644 --- a/internal/catch_ireporterregistry.h +++ b/internal/catch_ireporterregistry.h @@ -17,6 +17,7 @@ #include #include +#include namespace Catch { @@ -100,6 +101,8 @@ namespace Catch /////////////////////////////////////////////////////////////////////////// struct IReporterRegistry { + typedef std::map FactoryMap; + virtual ~IReporterRegistry (){} @@ -111,7 +114,11 @@ namespace Catch virtual void registerReporter ( const std::string& name, IReporterFactory* factory - ) = 0; + ) = 0; + + virtual const FactoryMap& getFactories + () const = 0; + }; /////////////////////////////////////////////////////////////////////////// diff --git a/internal/catch_list.hpp b/internal/catch_list.hpp index 476f45fe..4b07cf9f 100644 --- a/internal/catch_list.hpp +++ b/internal/catch_list.hpp @@ -23,8 +23,8 @@ namespace Catch if( config.listWhat() & RunnerConfig::listReports ) { std::cout << "Available reports:\n"; - ReporterRegistry::FactoryMap::const_iterator it = ReporterRegistry::instance().getFactories().begin(); - ReporterRegistry::FactoryMap::const_iterator itEnd = ReporterRegistry::instance().getFactories().end(); + ReporterRegistry::FactoryMap::const_iterator it = Hub::getReporterRegistry().getFactories().begin(); + ReporterRegistry::FactoryMap::const_iterator itEnd = Hub::getReporterRegistry().getFactories().end(); for(; it != itEnd; ++it ) { // !TBD: consider listAs() diff --git a/internal/catch_reporter_registry.hpp b/internal/catch_reporter_registry.hpp index 07e1cc77..5b193550 100644 --- a/internal/catch_reporter_registry.hpp +++ b/internal/catch_reporter_registry.hpp @@ -23,12 +23,6 @@ namespace Catch { public: - static ReporterRegistry& instance() - { - static ReporterRegistry instance; - return instance; - } - ~ReporterRegistry() { FactoryMap::const_iterator it = m_factories.begin(); @@ -50,9 +44,7 @@ namespace Catch void registerReporter( const std::string& name, IReporterFactory* factory ) { m_factories.insert( std::make_pair( name, factory ) ); - } - - typedef std::map FactoryMap; + } const FactoryMap& getFactories() const { @@ -81,7 +73,7 @@ namespace Catch { ReporterRegistrar( const std::string& name ) { - ReporterRegistry::instance().registerReporter( name, new ReporterFactory() ); + Hub::getReporterRegistry().registerReporter( name, new ReporterFactory() ); } }; } diff --git a/internal/catch_runnerconfig.hpp b/internal/catch_runnerconfig.hpp index 6e11a451..cce92901 100644 --- a/internal/catch_runnerconfig.hpp +++ b/internal/catch_runnerconfig.hpp @@ -106,7 +106,7 @@ namespace Catch { if( m_reporter.get() ) return setError( "Only one reporter may be specified" ); - setReporter( ReporterRegistry::instance().create( reporterName, m_reporterConfig ) ); + setReporter( Hub::getReporterRegistry().create( reporterName, m_reporterConfig ) ); } void addTestSpec( const std::string& testSpec ) @@ -141,7 +141,7 @@ namespace Catch IReporter* getReporter() { if( !m_reporter.get() ) - setReporter( ReporterRegistry::instance().create( "basic", m_reporterConfig ) ); + setReporter( Hub::getReporterRegistry().create( "basic", m_reporterConfig ) ); return m_reporter.get(); }