Refactor some Journal::Sink members

This commit is contained in:
Vinnie Falco
2013-11-30 11:00:21 -08:00
parent 1dfd9e3c10
commit f7aa4f9593
4 changed files with 49 additions and 34 deletions

View File

@@ -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. */

View File

@@ -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())

View File

@@ -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);

View File

@@ -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: