mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Replace owning naked IStream pointers with unique_ptrs
This commit is contained in:
parent
7d0770adf2
commit
3ec63324a8
@ -18,7 +18,7 @@ namespace Catch {
|
|||||||
|
|
||||||
Config::Config( ConfigData const& data )
|
Config::Config( ConfigData const& data )
|
||||||
: m_data( 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
|
// We need to trim filter specs to avoid trouble with superfluous
|
||||||
// whitespace (esp. important for bdd macros, as those are manually
|
// 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; }
|
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
|
||||||
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
|
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
|
} // end namespace Catch
|
||||||
|
@ -110,8 +110,6 @@ namespace Catch {
|
|||||||
std::chrono::milliseconds benchmarkWarmupTime() const override;
|
std::chrono::milliseconds benchmarkWarmupTime() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
IStream const* openStream();
|
|
||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
|
|
||||||
Detail::unique_ptr<IStream const> m_stream;
|
Detail::unique_ptr<IStream const> m_stream;
|
||||||
|
@ -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() )
|
if( filename.empty() )
|
||||||
return new Detail::CoutStream();
|
return Detail::make_unique<Detail::CoutStream>();
|
||||||
else if( filename[0] == '%' ) {
|
else if( filename[0] == '%' ) {
|
||||||
if( filename == "%debug" )
|
if( filename == "%debug" )
|
||||||
return new Detail::DebugOutStream();
|
return Detail::make_unique<Detail::DebugOutStream>();
|
||||||
else
|
else
|
||||||
CATCH_ERROR( "Unrecognised stream: '" << filename << "'" );
|
CATCH_ERROR( "Unrecognised stream: '" << filename << "'" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return new Detail::FileStream( filename );
|
return Detail::make_unique<Detail::FileStream>( filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define CATCH_STREAM_HPP_INCLUDED
|
#define CATCH_STREAM_HPP_INCLUDED
|
||||||
|
|
||||||
#include <catch2/internal/catch_noncopyable.hpp>
|
#include <catch2/internal/catch_noncopyable.hpp>
|
||||||
|
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -26,7 +27,7 @@ namespace Catch {
|
|||||||
virtual std::ostream& stream() const = 0;
|
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 {
|
class ReusableStringStream : Detail::NonCopyable {
|
||||||
std::size_t m_index;
|
std::size_t m_index;
|
||||||
|
Loading…
Reference in New Issue
Block a user