From f7aa4f9593bf1ef3f9b3d53de2d42b7e4087c29e Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 30 Nov 2013 11:00:21 -0800 Subject: [PATCH] Refactor some Journal::Sink members --- beast/utility/Journal.h | 18 +++++++---- beast/utility/impl/Journal.cpp | 37 ++++++++++++++++++++++ modules/beast_core/diagnostic/UnitTest.cpp | 23 -------------- modules/beast_core/diagnostic/UnitTest.h | 5 --- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/beast/utility/Journal.h b/beast/utility/Journal.h index 9c85b6d412..3d74a7b7bb 100644 --- a/beast/utility/Journal.h +++ b/beast/utility/Journal.h @@ -56,28 +56,34 @@ public: class Sink { public: - virtual ~Sink () { } + Sink (); + + virtual ~Sink () = 0; /** Returns `true` if text at the passed severity produces output. */ - virtual bool active (Severity severity) const = 0; + virtual bool active (Severity level) const; /** Returns `true` if a message is also written to the Output Window (MSVC). */ - virtual bool console () const = 0; + virtual bool console () const; /** Set whether messages are also written to the Output Window (MSVC). */ - virtual void console (bool output) = 0; + virtual void console (bool output); /** Returns the minimum severity level this sink will report. */ - virtual Severity severity() const = 0; + virtual Severity severity() const; /** Set the minimum severity this sink will report. */ - virtual void severity (Severity level) = 0; + virtual void severity (Severity level); /** Write text to the sink at the specified severity. The caller is responsible for checking the minimum severity level before using this function. */ virtual void write (Severity level, std::string const& text) = 0; + + private: + Severity m_severity; + bool m_console; }; /** Returns a Sink which does nothing. */ diff --git a/beast/utility/impl/Journal.cpp b/beast/utility/impl/Journal.cpp index 6d990ce7a7..09036b0173 100644 --- a/beast/utility/impl/Journal.cpp +++ b/beast/utility/impl/Journal.cpp @@ -65,6 +65,43 @@ Journal::Sink& Journal::getNullSink () //------------------------------------------------------------------------------ +Journal::Sink::Sink () + : m_severity (kLowestSeverity) + , m_console (false) +{ +} + +Journal::Sink::~Sink () +{ +} + +bool Journal::Sink::active (Severity level) const +{ + return level >= m_severity; +} + +bool Journal::Sink::console () const +{ + return m_console; +} + +void Journal::Sink::console (bool output) +{ + m_console = output; +} + +Journal::Severity Journal::Sink::severity () const +{ + return m_severity; +} + +void Journal::Sink::severity (Severity level) +{ + m_severity = level; +} + +//------------------------------------------------------------------------------ + Journal::ScopedStream::ScopedStream (Stream const& stream) : m_sink (stream.sink()) , m_severity (stream.severity()) diff --git a/modules/beast_core/diagnostic/UnitTest.cpp b/modules/beast_core/diagnostic/UnitTest.cpp index 5a566523da..324dd4e37d 100644 --- a/modules/beast_core/diagnostic/UnitTest.cpp +++ b/modules/beast_core/diagnostic/UnitTest.cpp @@ -235,29 +235,6 @@ UnitTests::JournalSink::JournalSink (UnitTests& tests) { } -bool UnitTests::JournalSink::active (Journal::Severity) const -{ - return true; -} - -bool UnitTests::JournalSink::console() const -{ - return false; -} - -void UnitTests::JournalSink::console (bool) -{ -} - -Journal::Severity UnitTests::JournalSink::severity() const -{ - return Journal::kLowestSeverity; -} - -void UnitTests::JournalSink::severity (Journal::Severity) -{ -} - void UnitTests::JournalSink::write (Journal::Severity, std::string const& text) { m_tests.logMessage (text); diff --git a/modules/beast_core/diagnostic/UnitTest.h b/modules/beast_core/diagnostic/UnitTest.h index 8a3a7655b3..02dc832b05 100644 --- a/modules/beast_core/diagnostic/UnitTest.h +++ b/modules/beast_core/diagnostic/UnitTest.h @@ -517,11 +517,6 @@ private: { public: explicit JournalSink (UnitTests& tests); - bool active (Journal::Severity severity) const; - bool console () const; - void console (bool); - Journal::Severity severity() const; - void severity (Journal::Severity severity); void write (Journal::Severity severity, std::string const& text); private: