Migrated IReporterFactory to std::shared_ptr

This commit is contained in:
Phil Nash 2017-04-25 20:28:53 +01:00
parent 338ba6b9ba
commit dd78824697
5 changed files with 16 additions and 13 deletions

View File

@ -22,6 +22,8 @@ namespace Catch {
struct IReporterFactory;
struct ITagAliasRegistry;
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
struct IRegistryHub {
virtual ~IRegistryHub();
@ -34,8 +36,8 @@ namespace Catch {
struct IMutableRegistryHub {
virtual ~IMutableRegistryHub();
virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
virtual void registerListener( IReporterFactoryPtr const& factory ) = 0;
virtual void registerTest( TestCase const& testInfo ) = 0;
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;

View File

@ -236,15 +236,16 @@ namespace Catch
};
struct IReporterFactory : IShared {
struct IReporterFactory {
virtual ~IReporterFactory();
virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
virtual std::string getDescription() const = 0;
};
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
struct IReporterRegistry {
typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
typedef std::vector<Ptr<IReporterFactory> > Listeners;
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
using Listeners = std::vector<IReporterFactoryPtr>;
virtual ~IReporterRegistry();
virtual IStreamingReporter* create( std::string const& name, IConfigPtr const& config ) const = 0;

View File

@ -42,10 +42,10 @@ namespace Catch {
public: // IMutableRegistryHub
virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) override {
virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
m_reporterRegistry.registerReporter( name, factory );
}
virtual void registerListener( Ptr<IReporterFactory> const& factory ) override {
virtual void registerListener( IReporterFactoryPtr const& factory ) override {
m_reporterRegistry.registerListener( factory );
}
virtual void registerTest( TestCase const& testInfo ) override {

View File

@ -15,7 +15,7 @@ namespace Catch {
template<typename T>
class ReporterRegistrar {
class ReporterFactory : public SharedImpl<IReporterFactory> {
class ReporterFactory : public IReporterFactory {
virtual IStreamingReporter* create( ReporterConfig const& config ) const {
return new T( config );
@ -29,14 +29,14 @@ namespace Catch {
public:
ReporterRegistrar( std::string const& name ) {
getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
}
};
template<typename T>
class ListenerRegistrar {
class ListenerFactory : public SharedImpl<IReporterFactory> {
class ListenerFactory : public IReporterFactory {
virtual IStreamingReporter* create( ReporterConfig const& config ) const {
return new T( config );
@ -49,7 +49,7 @@ namespace Catch {
public:
ListenerRegistrar() {
getMutableRegistryHub().registerListener( new ListenerFactory() );
getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
}
};
}

View File

@ -27,10 +27,10 @@ namespace Catch {
return it->second->create( ReporterConfig( config ) );
}
void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) {
m_factories.insert( std::make_pair( name, factory ) );
}
void registerListener( Ptr<IReporterFactory> const& factory ) {
void registerListener( IReporterFactoryPtr const& factory ) {
m_listeners.push_back( factory );
}