CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
Public Member Functions | Private Member Functions | Private Attributes
claw::log_stream_uniq Class Reference

A log stream that does not output successively the same message. More...

#include <log_stream_uniq.hpp>

Inheritance diagram for claw::log_stream_uniq:
claw::log_stream claw::pattern::non_copyable

List of all members.

Public Member Functions

 log_stream_uniq (log_stream *s)
 Constructor.
virtual ~log_stream_uniq ()
 Destructor.
virtual void write (const std::string &str)
 Write a string in the stream.
virtual void flush ()
 Flush the stream.

Private Member Functions

void output_current_line ()
 Output the current line, if not in the history.

Private Attributes

log_streamm_stream
 The stream in which the messages are finally written.
std::string m_current_line
 The current line to send into the stream.
std::string m_previous_line
 The previous line sent into the stream.
std::size_t m_repetition_count
 How many times the previous line has been repeated.

Detailed Description

A log stream that does not output successively the same message.

Author:
Julien Jorge

Definition at line 58 of file log_stream_uniq.hpp.


Constructor & Destructor Documentation

claw::log_stream_uniq::log_stream_uniq ( log_stream s) [explicit]

Constructor.

Parameters:
sThe stream in which the messages are finally written. It will be deleted in the destructor.

Definition at line 42 of file log_stream_uniq.cpp.

  : m_stream(s), m_repetition_count(0)
{

} // log_stream_uniq::log_stream_uniq()
claw::log_stream_uniq::~log_stream_uniq ( ) [virtual]

Destructor.

Definition at line 52 of file log_stream_uniq.cpp.

{
  delete m_stream;
} // log_stream_uniq::~log_stream_uniq()

Member Function Documentation

void claw::log_stream_uniq::flush ( ) [virtual]

Flush the stream.

Reimplemented from claw::log_stream.

Definition at line 84 of file log_stream_uniq.cpp.

{
  m_stream->flush();
} // log_stream_uniq::flush()
void claw::log_stream_uniq::output_current_line ( ) [private]

Output the current line, if not in the history.

Definition at line 93 of file log_stream_uniq.cpp.

References claw_gettext, and claw_ngettext.

{
  if ( m_current_line == m_previous_line )
    ++m_repetition_count;
  else
    {
      if ( m_repetition_count > 0 )
  {
    std::ostringstream oss;
    oss << claw_gettext("(Previous line repeated ") << m_repetition_count
        << claw_ngettext(" time)", " times)", m_repetition_count) << '\n';

    m_stream->write(oss.str());
  }

      m_repetition_count = 0;

      m_previous_line = m_current_line;
      m_stream->write( m_current_line );
    }

  m_current_line.clear();
} // log_stream_uniq::output_current_line()
void claw::log_stream_uniq::write ( const std::string &  str) [virtual]

Write a string in the stream.

Parameters:
strThe sring to write.

Implements claw::log_stream.

Definition at line 62 of file log_stream_uniq.cpp.

{
  std::string::size_type p = str.find_first_of('\n');

  if ( p == std::string::npos )
    m_current_line += str;
  else
    {
      ++p; // includes the '\n'
      m_current_line += str.substr(0, p);

      output_current_line();

      if ( p != str.length() )
        write( str.substr(p) );
    }
} // log_stream_uniq::write()

Member Data Documentation

The current line to send into the stream.

Definition at line 77 of file log_stream_uniq.hpp.

The previous line sent into the stream.

Definition at line 80 of file log_stream_uniq.hpp.

How many times the previous line has been repeated.

Definition at line 83 of file log_stream_uniq.hpp.

The stream in which the messages are finally written.

Definition at line 74 of file log_stream_uniq.hpp.


The documentation for this class was generated from the following files: