claw
1.9.0
Toggle main menu visibility
Loading...
Searching...
No Matches
log_stream_concise.cpp
Go to the documentation of this file.
1
/*
2
CLAW - a C++ Library Absolutely Wonderful
3
4
CLAW is a free library without any particular aim but being useful to
5
anyone.
6
7
Copyright (C) 2005-2011 Julien Jorge
8
9
This library is free software; you can redistribute it and/or
10
modify it under the terms of the GNU Lesser General Public
11
License as published by the Free Software Foundation; either
12
version 2.1 of the License, or (at your option) any later version.
13
14
This library is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public
20
License along with this library; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23
contact: julien.jorge@stuff-o-matic.com
24
*/
30
#include <
claw/logger/log_stream_concise.hpp
>
31
32
#include <algorithm>
33
40
claw::log_stream_concise::log_stream_concise
(
log_stream
* s,
41
std::size_t max_history_size)
42
: m_stream(s)
43
, m_max_history_size(max_history_size)
44
{}
45
49
claw::log_stream_concise::~log_stream_concise
()
50
{
51
delete
m_stream;
52
}
53
58
void
claw::log_stream_concise::write
(
const
std::string& str)
59
{
60
std::string::size_type p = str.find_first_of(
'\n'
);
61
62
if
(p == std::string::npos)
63
m_current_line += str;
64
else
65
{
66
++p;
// includes the '\n'
67
m_current_line += str.substr(0, p);
68
69
output_current_line();
70
71
if
(p != str.length())
72
write
(str.substr(p));
73
}
74
}
75
79
void
claw::log_stream_concise::flush
()
80
{
81
m_stream->flush();
82
}
83
87
void
claw::log_stream_concise::output_current_line()
88
{
89
if
(std::find(m_previous_lines.begin(), m_previous_lines.end(),
90
m_current_line)
91
== m_previous_lines.end())
92
{
93
m_previous_lines.push_back(m_current_line);
94
m_stream->write(m_current_line);
95
96
if
(m_previous_lines.size() > m_max_history_size)
97
m_previous_lines.pop_front();
98
}
99
100
m_current_line.clear();
101
}
claw::log_stream_concise::log_stream_concise
log_stream_concise(log_stream *s, std::size_t max_history_size=25)
Constructor.
Definition
log_stream_concise.cpp:40
claw::log_stream_concise::~log_stream_concise
virtual ~log_stream_concise()
Destructor.
Definition
log_stream_concise.cpp:49
claw::log_stream_concise::write
virtual void write(const std::string &str)
Write a string in the stream.
Definition
log_stream_concise.cpp:58
claw::log_stream_concise::flush
virtual void flush()
Flush the stream.
Definition
log_stream_concise.cpp:79
claw::log_stream
Base class for streams accepting log output.
Definition
log_stream.hpp:61
log_stream_concise.hpp
A log stream that does not output a message that have been recently output.
lib
logger
src
claw
logger
log_stream_concise.cpp
Generated by
1.17.0