|
CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
A log stream that does not output successively the same message. More...
#include <log_stream_uniq.hpp>
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_stream * | m_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. | |
A log stream that does not output successively the same message.
Definition at line 58 of file log_stream_uniq.hpp.
| claw::log_stream_uniq::log_stream_uniq | ( | log_stream * | s | ) | [explicit] |
Constructor.
| s | The 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()
| 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.
| str | The 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()
std::string claw::log_stream_uniq::m_current_line [private] |
The current line to send into the stream.
Definition at line 77 of file log_stream_uniq.hpp.
std::string claw::log_stream_uniq::m_previous_line [private] |
The previous line sent into the stream.
Definition at line 80 of file log_stream_uniq.hpp.
std::size_t claw::log_stream_uniq::m_repetition_count [private] |
How many times the previous line has been repeated.
Definition at line 83 of file log_stream_uniq.hpp.
log_stream* claw::log_stream_uniq::m_stream [private] |
The stream in which the messages are finally written.
Definition at line 74 of file log_stream_uniq.hpp.
1.7.3