From 0844d6e8677d400f1c363f2d48dc6cf74075b8d5 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 25 Apr 2017 20:42:01 +0100 Subject: [PATCH] Migrated IStreamingReporter from Ptr to std::shared_ptr --- include/catch_session.hpp | 12 ++++++------ include/internal/catch_interfaces_reporter.h | 10 +++++----- include/internal/catch_reporter_registrars.hpp | 8 ++++---- include/internal/catch_reporter_registry.hpp | 2 +- include/internal/catch_run_context.hpp | 4 ++-- include/reporters/catch_reporter_multi.hpp | 10 +++++----- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/catch_session.hpp b/include/catch_session.hpp index e07b11cf..7c674fba 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -21,8 +21,8 @@ namespace Catch { - Ptr createReporter( std::string const& reporterName, IConfigPtr const& config ) { - Ptr reporter = getRegistryHub().getReporterRegistry().create( reporterName, config ); + IStreamingReporterPtr createReporter( std::string const& reporterName, IConfigPtr const& config ) { + IStreamingReporterPtr reporter = getRegistryHub().getReporterRegistry().create( reporterName, config ); if( !reporter ) { std::ostringstream oss; oss << "No reporter registered with name: '" << reporterName << "'"; @@ -31,17 +31,17 @@ namespace Catch { return reporter; } - Ptr makeReporter( std::shared_ptr const& config ) { + IStreamingReporterPtr makeReporter( std::shared_ptr const& config ) { std::vector reporters = config->getReporterNames(); if( reporters.empty() ) reporters.push_back( "console" ); - Ptr reporter; + IStreamingReporterPtr reporter; for( auto const& name : reporters ) reporter = addReporter( reporter, createReporter( name, config ) ); return reporter; } - Ptr addListeners( IConfigPtr const& config, Ptr reporters ) { + IStreamingReporterPtr addListeners( IConfigPtr const& config, IStreamingReporterPtr reporters ) { auto const& listeners = getRegistryHub().getReporterRegistry().getListeners(); for( auto const& listener : listeners ) reporters = addReporter(reporters, listener->create( ReporterConfig( config ) ) ); @@ -53,7 +53,7 @@ namespace Catch { IConfigPtr iconfig = config; - Ptr reporter = makeReporter( config ); + IStreamingReporterPtr reporter = makeReporter( config ); reporter = addListeners( iconfig, reporter ); RunContext context( iconfig, reporter ); diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h index 6a38528b..b0af150f 100644 --- a/include/internal/catch_interfaces_reporter.h +++ b/include/internal/catch_interfaces_reporter.h @@ -204,7 +204,7 @@ namespace Catch class MultipleReporters; - struct IStreamingReporter : IShared { + struct IStreamingReporter { virtual ~IStreamingReporter(); // Implementing class must also provide the following static method: @@ -234,11 +234,11 @@ namespace Catch virtual MultipleReporters* tryAsMulti() { return nullptr; } }; - + using IStreamingReporterPtr = std::shared_ptr; struct IReporterFactory { virtual ~IReporterFactory(); - virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0; + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; virtual std::string getDescription() const = 0; }; using IReporterFactoryPtr = std::shared_ptr; @@ -248,12 +248,12 @@ namespace Catch using Listeners = std::vector; virtual ~IReporterRegistry(); - virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const = 0; + virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; virtual FactoryMap const& getFactories() const = 0; virtual Listeners const& getListeners() const = 0; }; - Ptr addReporter( Ptr const& existingReporter, Ptr const& additionalReporter ); + IStreamingReporterPtr addReporter( IStreamingReporterPtr const& existingReporter, IStreamingReporterPtr const& additionalReporter ); } diff --git a/include/internal/catch_reporter_registrars.hpp b/include/internal/catch_reporter_registrars.hpp index 086c5df2..759b0edb 100644 --- a/include/internal/catch_reporter_registrars.hpp +++ b/include/internal/catch_reporter_registrars.hpp @@ -17,8 +17,8 @@ namespace Catch { class ReporterFactory : public IReporterFactory { - virtual IStreamingReporter* create( ReporterConfig const& config ) const { - return new T( config ); + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const { + return std::make_shared( config ); } virtual std::string getDescription() const { @@ -38,8 +38,8 @@ namespace Catch { class ListenerFactory : public IReporterFactory { - virtual IStreamingReporter* create( ReporterConfig const& config ) const { - return new T( config ); + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const { + return std::make_shared( config ); } virtual std::string getDescription() const { return std::string(); diff --git a/include/internal/catch_reporter_registry.hpp b/include/internal/catch_reporter_registry.hpp index e316ee4e..9556fb31 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, IConfigPtr const& config ) const override { + virtual IStreamingReporterPtr 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 78051d21..7f38eb4a 100644 --- a/include/internal/catch_run_context.hpp +++ b/include/internal/catch_run_context.hpp @@ -59,7 +59,7 @@ namespace Catch { public: - explicit RunContext( IConfigPtr const& _config, Ptr const& reporter ) + explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr const& reporter ) : m_runInfo( _config->name() ), m_context( getCurrentMutableContext() ), m_config( _config ), @@ -355,7 +355,7 @@ namespace Catch { IConfigPtr m_config; Totals m_totals; - Ptr m_reporter; + IStreamingReporterPtr m_reporter; std::vector m_messages; AssertionInfo m_lastAssertionInfo; std::vector m_unfinishedSections; diff --git a/include/reporters/catch_reporter_multi.hpp b/include/reporters/catch_reporter_multi.hpp index 6b460bf0..0fbba771 100644 --- a/include/reporters/catch_reporter_multi.hpp +++ b/include/reporters/catch_reporter_multi.hpp @@ -13,11 +13,11 @@ namespace Catch { class MultipleReporters : public SharedImpl { - typedef std::vector > Reporters; + typedef std::vector Reporters; Reporters m_reporters; public: - void add( Ptr const& reporter ) { + void add( IStreamingReporterPtr const& reporter ) { m_reporters.push_back( reporter ); } @@ -101,14 +101,14 @@ public: // IStreamingReporter }; -Ptr addReporter( Ptr const& existingReporter, Ptr const& additionalReporter ) { - Ptr resultingReporter; +IStreamingReporterPtr addReporter( IStreamingReporterPtr const& existingReporter, IStreamingReporterPtr const& additionalReporter ) { + IStreamingReporterPtr resultingReporter; if( existingReporter ) { MultipleReporters* multi = existingReporter->tryAsMulti(); if( !multi ) { multi = new MultipleReporters; - resultingReporter = Ptr( multi ); + resultingReporter = IStreamingReporterPtr( multi ); if( existingReporter ) multi->add( existingReporter ); }