diff options
| author | Martin Hořeňovský | 2022-04-12 21:22:43 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-04-13 15:00:50 +0200 |
| commit | 79d1e8238135427a6780a6db2cdb8b9be0b7f086 (patch) | |
| tree | 13b7a82bbad094af77171b2807b5d9241acc1721 /src/catch2/interfaces | |
| parent | 4f09f1120ba0a28f218a00821a8347a443042ecb (diff) | |
| download | catch3-79d1e8238135427a6780a6db2cdb8b9be0b7f086.tar.gz | |
Store IStream instance owning ptrs in reporter instances
This ended up being a surprisingly large refactoring, motivated
by removing a `const_cast` from `Config`'s handling of reporter
streams, forced by previous commit.
Diffstat (limited to 'src/catch2/interfaces')
4 files changed, 12 insertions, 8 deletions
diff --git a/src/catch2/interfaces/catch_interfaces_reporter.cpp b/src/catch2/interfaces/catch_interfaces_reporter.cpp index 926331e0..9a6cbdc2 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.cpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.cpp @@ -17,21 +17,25 @@ #include <catch2/internal/catch_move_and_forward.hpp> #include <algorithm> +#include <cassert> #include <iomanip> namespace Catch { ReporterConfig::ReporterConfig( IConfig const* _fullConfig, - IStream* _stream, + Detail::unique_ptr<IStream> _stream, ColourMode colourMode, std::map<std::string, std::string> customOptions ): - m_stream( _stream ), + m_stream( CATCH_MOVE(_stream) ), m_fullConfig( _fullConfig ), m_colourMode( colourMode ), m_customOptions( CATCH_MOVE( customOptions ) ) {} - IStream* ReporterConfig::stream() const { return m_stream; } + Detail::unique_ptr<IStream> ReporterConfig::takeStream() && { + assert( m_stream ); + return CATCH_MOVE( m_stream ); + } IConfig const * ReporterConfig::fullConfig() const { return m_fullConfig; } ColourMode ReporterConfig::colourMode() const { return m_colourMode; } diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp index 21a16cde..1e6c2590 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp @@ -36,17 +36,17 @@ namespace Catch { struct ReporterConfig { ReporterConfig( IConfig const* _fullConfig, - IStream* _stream, + Detail::unique_ptr<IStream> _stream, ColourMode colourMode, std::map<std::string, std::string> customOptions ); - IStream* stream() const; + Detail::unique_ptr<IStream> takeStream() &&; IConfig const* fullConfig() const; ColourMode colourMode() const; std::map<std::string, std::string> const& customOptions() const; private: - IStream* m_stream; + Detail::unique_ptr<IStream> m_stream; IConfig const* m_fullConfig; ColourMode m_colourMode; std::map<std::string, std::string> m_customOptions; diff --git a/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp b/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp index 7a71a168..76dce504 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter_factory.hpp @@ -25,7 +25,7 @@ namespace Catch { virtual ~IReporterFactory(); // = default virtual IEventListenerPtr - create( ReporterConfig const& config ) const = 0; + create( ReporterConfig&& config ) const = 0; virtual std::string getDescription() const = 0; }; using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>; diff --git a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp index 5645640a..d2f2a159 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter_registry.hpp @@ -32,7 +32,7 @@ namespace Catch { using Listeners = std::vector<Detail::unique_ptr<EventListenerFactory>>; virtual ~IReporterRegistry(); // = default - virtual IEventListenerPtr create( std::string const& name, ReporterConfig const& config ) const = 0; + virtual IEventListenerPtr create( std::string const& name, ReporterConfig&& config ) const = 0; virtual FactoryMap const& getFactories() const = 0; virtual Listeners const& getListeners() const = 0; }; |