Replace owning naked IStream pointers with unique_ptrs

This commit is contained in:
Martin Hořeňovský 2021-08-10 00:14:18 +02:00
parent 7d0770adf2
commit 3ec63324a8
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
4 changed files with 7 additions and 12 deletions

View File

@ -18,7 +18,7 @@ namespace Catch {
Config::Config( ConfigData const& data )
: m_data( data ),
m_stream( openStream() )
m_stream( Catch::makeStream(m_data.outputFilename) )
{
// We need to trim filter specs to avoid trouble with superfluous
// whitespace (esp. important for bdd macros, as those are manually
@ -86,8 +86,4 @@ namespace Catch {
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
IStream const* Config::openStream() {
return Catch::makeStream(m_data.outputFilename);
}
} // end namespace Catch

View File

@ -110,8 +110,6 @@ namespace Catch {
std::chrono::milliseconds benchmarkWarmupTime() const override;
private:
IStream const* openStream();
ConfigData m_data;
Detail::unique_ptr<IStream const> m_stream;

View File

@ -123,17 +123,17 @@ namespace Detail {
///////////////////////////////////////////////////////////////////////////
auto makeStream( std::string const& filename ) -> IStream const* {
auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const> {
if( filename.empty() )
return new Detail::CoutStream();
return Detail::make_unique<Detail::CoutStream>();
else if( filename[0] == '%' ) {
if( filename == "%debug" )
return new Detail::DebugOutStream();
return Detail::make_unique<Detail::DebugOutStream>();
else
CATCH_ERROR( "Unrecognised stream: '" << filename << "'" );
}
else
return new Detail::FileStream( filename );
return Detail::make_unique<Detail::FileStream>( filename );
}

View File

@ -9,6 +9,7 @@
#define CATCH_STREAM_HPP_INCLUDED
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <iosfwd>
#include <cstddef>
@ -26,7 +27,7 @@ namespace Catch {
virtual std::ostream& stream() const = 0;
};
auto makeStream( std::string const& filename ) -> IStream const*;
auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const>;
class ReusableStringStream : Detail::NonCopyable {
std::size_t m_index;