diff options
| author | Martin Hořeňovský | 2022-04-12 20:59:01 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-04-13 14:59:39 +0200 |
| commit | 4f09f1120ba0a28f218a00821a8347a443042ecb (patch) | |
| tree | af5dc04a3e0c91476e0b03e60d914d5bf2b11693 /src/catch2/internal | |
| parent | 9934b7de13ef303e0d7b1bccf519422be73c6a03 (diff) | |
| download | catch3-4f09f1120ba0a28f218a00821a8347a443042ecb.tar.gz | |
Make IStream::stream non-const
This way it makes much more sense from logically-const point
of view, and also means that concrete implementations don't
have to always have a `mutable` keyword on the stream member.
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_console_colour.cpp | 8 | ||||
| -rw-r--r-- | src/catch2/internal/catch_console_colour.hpp | 6 | ||||
| -rw-r--r-- | src/catch2/internal/catch_stream.cpp | 18 | ||||
| -rw-r--r-- | src/catch2/internal/catch_stream.hpp | 4 |
4 files changed, 18 insertions, 18 deletions
diff --git a/src/catch2/internal/catch_console_colour.cpp b/src/catch2/internal/catch_console_colour.cpp index 67f0d98a..e9fa55f7 100644 --- a/src/catch2/internal/catch_console_colour.cpp +++ b/src/catch2/internal/catch_console_colour.cpp @@ -84,7 +84,7 @@ namespace Catch { //! platforms, and when the user asks to deactivate all colours. class NoColourImpl : public ColourImpl { public: - NoColourImpl( IStream const* stream ): ColourImpl( stream ) {} + NoColourImpl( IStream* stream ): ColourImpl( stream ) {} static bool useColourOnPlatform() { return true; } private: @@ -103,7 +103,7 @@ namespace { class Win32ColourImpl : public ColourImpl { public: - Win32ColourImpl(IStream const* stream): + Win32ColourImpl(IStream* stream): ColourImpl(stream) { CONSOLE_SCREEN_BUFFER_INFO csbiInfo; GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), @@ -169,7 +169,7 @@ namespace { class ANSIColourImpl : public ColourImpl { public: - ANSIColourImpl( IStream const* stream ): ColourImpl( stream ) {} + ANSIColourImpl( IStream* stream ): ColourImpl( stream ) {} static bool useColourOnPlatform(IStream const& stream) { // This is kinda messy due to trying to support a bunch of @@ -229,7 +229,7 @@ namespace { namespace Catch { Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode implSelection, - IStream const* stream ) { + IStream* stream ) { if ( implSelection == ColourMode::None ) { return Detail::make_unique<NoColourImpl>( stream ); } diff --git a/src/catch2/internal/catch_console_colour.hpp b/src/catch2/internal/catch_console_colour.hpp index bf7cb893..661078af 100644 --- a/src/catch2/internal/catch_console_colour.hpp +++ b/src/catch2/internal/catch_console_colour.hpp @@ -60,9 +60,9 @@ namespace Catch { class ColourImpl { protected: //! The associated stream of this ColourImpl instance - IStream const* m_stream; + IStream* m_stream; public: - ColourImpl( IStream const* stream ): m_stream( stream ) {} + ColourImpl( IStream* stream ): m_stream( stream ) {} //! RAII wrapper around writing specific colour of text using specific //! colour impl into a stream. @@ -131,7 +131,7 @@ namespace Catch { //! Provides ColourImpl based on global config and target compilation platform Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection, - IStream const* stream ); + IStream* stream ); //! Checks if specific colour impl has been compiled into the binary bool isColourImplAvailable( ColourMode colourSelection ); diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index dfa322c7..089a7583 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -74,7 +74,7 @@ namespace Detail { /////////////////////////////////////////////////////////////////////////// class FileStream : public IStream { - mutable std::ofstream m_ofs; + std::ofstream m_ofs; public: FileStream( std::string const& filename ) { m_ofs.open( filename.c_str() ); @@ -82,7 +82,7 @@ namespace Detail { } ~FileStream() override = default; public: // IStream - std::ostream& stream() const override { + std::ostream& stream() override { return m_ofs; } }; @@ -90,7 +90,7 @@ namespace Detail { /////////////////////////////////////////////////////////////////////////// class CoutStream : public IStream { - mutable std::ostream m_os; + std::ostream m_os; public: // Store the streambuf from cout up-front because // cout may get redirected when running tests @@ -98,12 +98,12 @@ namespace Detail { ~CoutStream() override = default; public: // IStream - std::ostream& stream() const override { return m_os; } + std::ostream& stream() override { return m_os; } bool isConsole() const override { return true; } }; class CerrStream : public IStream { - mutable std::ostream m_os; + std::ostream m_os; public: // Store the streambuf from cerr up-front because @@ -112,7 +112,7 @@ namespace Detail { ~CerrStream() override = default; public: // IStream - std::ostream& stream() const override { return m_os; } + std::ostream& stream() override { return m_os; } bool isConsole() const override { return true; } }; @@ -120,7 +120,7 @@ namespace Detail { class DebugOutStream : public IStream { Detail::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf; - mutable std::ostream m_os; + std::ostream m_os; public: DebugOutStream() : m_streamBuf( Detail::make_unique<StreamBufImpl<OutputDebugWriter>>() ), @@ -130,7 +130,7 @@ namespace Detail { ~DebugOutStream() override = default; public: // IStream - std::ostream& stream() const override { return m_os; } + std::ostream& stream() override { return m_os; } }; } // unnamed namespace @@ -138,7 +138,7 @@ namespace Detail { /////////////////////////////////////////////////////////////////////////// - auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const> { + auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream> { if ( filename.empty() || filename == "-" ) { return Detail::make_unique<Detail::CoutStream>(); } diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp index 41c1fef0..eab7161c 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_stream.hpp @@ -25,7 +25,7 @@ namespace Catch { class IStream { public: virtual ~IStream(); // = default - virtual std::ostream& stream() const = 0; + virtual std::ostream& stream() = 0; /** * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr) * @@ -51,7 +51,7 @@ namespace Catch { * * \throws if passed an unrecognized %-prefixed stream */ - auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream const>; + auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream>; class ReusableStringStream : Detail::NonCopyable { std::size_t m_index; |