diff --git a/include/catch_session.hpp b/include/catch_session.hpp index 8d200aa6..91aff563 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -21,8 +21,8 @@ namespace Catch { - Ptr createReporter( std::string const& reporterName, Ptr const& config ) { - Ptr reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() ); + Ptr createReporter( std::string const& reporterName, IConfigPtr const& config ) { + Ptr reporter = getRegistryHub().getReporterRegistry().create( reporterName, config ); if( !reporter ) { std::ostringstream oss; oss << "No reporter registered with name: '" << reporterName << "'"; @@ -31,7 +31,7 @@ namespace Catch { return reporter; } - Ptr makeReporter( Ptr const& config ) { + Ptr makeReporter( std::shared_ptr const& config ) { std::vector reporters = config->getReporterNames(); if( reporters.empty() ) reporters.push_back( "console" ); @@ -41,7 +41,7 @@ namespace Catch { reporter = addReporter( reporter, createReporter( name, config ) ); return reporter; } - Ptr addListeners( Ptr const& config, Ptr reporters ) { + Ptr addListeners( IConfigPtr const& config, Ptr reporters ) { IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners(); for( auto const& listener : listeners ) reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) ); @@ -49,9 +49,9 @@ namespace Catch { } - Totals runTests( Ptr const& config ) { + Totals runTests( std::shared_ptr const& config ) { - Ptr iconfig = config.get(); + IConfigPtr iconfig = config; Ptr reporter = makeReporter( config ); reporter = addListeners( iconfig, reporter ); @@ -195,14 +195,14 @@ namespace Catch { } Config& config() { if( !m_config ) - m_config = new Config( m_configData ); + m_config = std::make_shared( m_configData ); return *m_config; } private: Clara::CommandLine m_cli; std::vector m_unusedTokens; ConfigData m_configData; - Ptr m_config; + std::shared_ptr m_config; }; bool Session::alreadyInstantiated = false; diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 24afda6e..8be68a81 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -56,10 +56,7 @@ namespace Catch { }; - class Config : public SharedImpl { - private: - Config( Config const& other ); - Config& operator = ( Config const& other ); + class Config : public IConfig { virtual void dummy(); public: diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp index 426bba29..f15494ab 100644 --- a/include/internal/catch_console_colour_impl.hpp +++ b/include/internal/catch_console_colour_impl.hpp @@ -89,7 +89,7 @@ namespace { IColourImpl* platformColourInstance() { static Win32ColourImpl s_instance; - Ptr config = getCurrentContext().getConfig(); + IConfigPtr config = getCurrentContext().getConfig(); UseColour::YesOrNo colourMode = config ? config->useColour() : UseColour::Auto; @@ -150,7 +150,7 @@ namespace { IColourImpl* platformColourInstance() { ErrnoGuard guard; - Ptr config = getCurrentContext().getConfig(); + IConfigPtr config = getCurrentContext().getConfig(); UseColour::YesOrNo colourMode = config ? config->useColour() : UseColour::Auto; diff --git a/include/internal/catch_context.h b/include/internal/catch_context.h index 8b683864..77a7d3ac 100644 --- a/include/internal/catch_context.h +++ b/include/internal/catch_context.h @@ -21,6 +21,8 @@ namespace Catch { struct IGeneratorsForTest; struct IConfig; + using IConfigPtr = std::shared_ptr; + struct IContext { virtual ~IContext(); @@ -29,7 +31,7 @@ namespace Catch { virtual IRunner* getRunner() = 0; virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; virtual bool advanceGeneratorsForCurrentTest() = 0; - virtual Ptr getConfig() const = 0; + virtual IConfigPtr getConfig() const = 0; }; struct IMutableContext : IContext @@ -37,7 +39,7 @@ namespace Catch { virtual ~IMutableContext(); virtual void setResultCapture( IResultCapture* resultCapture ) = 0; virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( Ptr const& config ) = 0; + virtual void setConfig( IConfigPtr const& config ) = 0; }; IContext& getCurrentContext(); diff --git a/include/internal/catch_context_impl.hpp b/include/internal/catch_context_impl.hpp index b9488c6e..43210693 100644 --- a/include/internal/catch_context_impl.hpp +++ b/include/internal/catch_context_impl.hpp @@ -40,7 +40,7 @@ namespace Catch { return generators && generators->moveNext(); } - virtual Ptr getConfig() const { + virtual IConfigPtr getConfig() const { return m_config; } @@ -51,7 +51,7 @@ namespace Catch { virtual void setRunner( IRunner* runner ) { m_runner = runner; } - virtual void setConfig( Ptr const& config ) { + virtual void setConfig( IConfigPtr const& config ) { m_config = config; } @@ -79,7 +79,7 @@ namespace Catch { } private: - Ptr m_config; + IConfigPtr m_config; IRunner* m_runner = nullptr; IResultCapture* m_resultCapture = nullptr; std::map m_generatorsByTestName; diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h index 5730a8cd..d9479e07 100644 --- a/include/internal/catch_interfaces_config.h +++ b/include/internal/catch_interfaces_config.h @@ -45,7 +45,7 @@ namespace Catch { class TestSpec; - struct IConfig : IShared { + struct IConfig : NonCopyable { virtual ~IConfig(); @@ -63,8 +63,9 @@ namespace Catch { virtual unsigned int rngSeed() const = 0; virtual UseColour::YesOrNo useColour() const = 0; virtual std::vector const& getSectionsToRun() const = 0; - }; + + using IConfigPtr = std::shared_ptr; } #endif // TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index a1c5aa57..07524b93 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -25,18 +25,18 @@ namespace Catch { struct ReporterConfig { - explicit ReporterConfig( Ptr const& _fullConfig ) + explicit ReporterConfig( IConfigPtr const& _fullConfig ) : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} - ReporterConfig( Ptr const& _fullConfig, std::ostream& _stream ) + ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream ) : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} std::ostream& stream() const { return *m_stream; } - Ptr fullConfig() const { return m_fullConfig; } + IConfigPtr fullConfig() const { return m_fullConfig; } private: std::ostream* m_stream; - Ptr m_fullConfig; + IConfigPtr m_fullConfig; }; struct ReporterPreferences { @@ -247,7 +247,7 @@ namespace Catch typedef std::vector > Listeners; virtual ~IReporterRegistry(); - virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const = 0; + virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const = 0; virtual FactoryMap const& getFactories() const = 0; virtual Listeners const& getListeners() const = 0; }; diff --git a/include/internal/catch_reporter_registry.hpp b/include/internal/catch_reporter_registry.hpp index 7a0c783a..ad212437 100644 --- a/include/internal/catch_reporter_registry.hpp +++ b/include/internal/catch_reporter_registry.hpp @@ -20,7 +20,7 @@ namespace Catch { virtual ~ReporterRegistry() override {} - virtual IStreamingReporter* create( std::string const& name, Ptr const& config ) const override { + virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const override { FactoryMap::const_iterator it = m_factories.find( name ); if( it == m_factories.end() ) return nullptr; diff --git a/include/internal/catch_run_context.hpp b/include/internal/catch_run_context.hpp index 23c4654a..78051d21 100644 --- a/include/internal/catch_run_context.hpp +++ b/include/internal/catch_run_context.hpp @@ -59,7 +59,7 @@ namespace Catch { public: - explicit RunContext( Ptr const& _config, Ptr const& reporter ) + explicit RunContext( IConfigPtr const& _config, Ptr const& reporter ) : m_runInfo( _config->name() ), m_context( getCurrentMutableContext() ), m_config( _config ), @@ -128,7 +128,7 @@ namespace Catch { return deltaTotals; } - Ptr config() const { + IConfigPtr config() const { return m_config; } @@ -353,7 +353,7 @@ namespace Catch { ITracker* m_currentSectionTracker; AssertionResult m_lastResult; - Ptr m_config; + IConfigPtr m_config; Totals m_totals; Ptr m_reporter; std::vector m_messages; diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index d94c15b4..6c8e4541 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -92,7 +92,7 @@ namespace Catch { // It can optionally be overridden in the derived class. } - Ptr m_config; + IConfigPtr m_config; std::ostream& stream; LazyStat currentTestRunInfo; @@ -244,7 +244,7 @@ namespace Catch { result.expandDecomposedExpression(); } - Ptr m_config; + IConfigPtr m_config; std::ostream& stream; std::vector m_assertions; std::vector > > m_sections;