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

A log stream that does not output a message that have been recently output. More...

#include <log_stream_concise.hpp>

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

List of all members.

Public Member Functions

 log_stream_concise (log_stream *s, std::size_t max_history_size=25)
 Constructor.
virtual ~log_stream_concise ()
 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::list< std::string > m_previous_lines
 Recent lines sent to the stream.
std::size_t m_max_history_size
 Maximum number of lines in the history.

Detailed Description

A log stream that does not output a message that have been recently output.

Author:
Julien Jorge

Definition at line 61 of file log_stream_concise.hpp.


Constructor & Destructor Documentation

claw::log_stream_concise::log_stream_concise ( log_stream s,
std::size_t  max_history_size = 25 
) [explicit]

Constructor.

Parameters:
sThe stream in which the messages are finally written. It will be deleted in the destructor.
max_history_sizeThe maximum number of lines in the history.

Definition at line 42 of file log_stream_concise.cpp.

  : m_stream(s), m_max_history_size(max_history_size)
{

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

Destructor.

Definition at line 52 of file log_stream_concise.cpp.

References m_stream.

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

Member Function Documentation

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

Flush the stream.

Reimplemented from claw::log_stream.

Definition at line 84 of file log_stream_concise.cpp.

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

Output the current line, if not in the history.

Definition at line 93 of file log_stream_concise.cpp.

{
  if ( std::find
       (m_previous_lines.begin(), m_previous_lines.end(), m_current_line)
       == m_previous_lines.end() )
    {
      m_previous_lines.push_back( m_current_line );
      m_stream->write( m_current_line );

      if (m_previous_lines.size() > m_max_history_size)
  m_previous_lines.pop_front();
    }

  m_current_line.clear();
} // log_stream_concise::output_current_line()
void claw::log_stream_concise::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_concise.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_concise::write()

Member Data Documentation

The current line to send into the stream.

Definition at line 81 of file log_stream_concise.hpp.

Maximum number of lines in the history.

Definition at line 87 of file log_stream_concise.hpp.

std::list<std::string> claw::log_stream_concise::m_previous_lines [private]

Recent lines sent to the stream.

Definition at line 84 of file log_stream_concise.hpp.

The stream in which the messages are finally written.

Definition at line 78 of file log_stream_concise.hpp.

Referenced by ~log_stream_concise().


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