summaryrefslogtreecommitdiffhomepage
path: root/log.h
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-04 11:28:20 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-04 11:28:20 +0100
commitb2c35cdf69a9084806ac7930cf4475980d596cf6 (patch)
treeb74b8f2ee2c66c59f7385407cfc34c2a0a16961f /log.h
parentaaafcea7e26791acbf5b9612e3fb396edcdfcc8f (diff)
Separate out implementation from headers
Diffstat (limited to 'log.h')
-rw-r--r--log.h50
1 files changed, 7 insertions, 43 deletions
diff --git a/log.h b/log.h
index cfc4d4c..9aea958 100644
--- a/log.h
+++ b/log.h
@@ -8,27 +8,17 @@
class log_stream
{
public:
- log_stream(): m_active(false), m_buffer(), m_log_lines() {}
+ log_stream();
- void log_lines(int n) {
- m_log_lines = n;
- }
+ void log_lines(int n);
- std::string get_log() {
- return m_buffer.str();
- }
+ std::string get_log();
// log to buffer
- void activate()
- {
- m_active = true;
- }
+ void activate();
// log to plain console
- void deactivate()
- {
- m_active = false;
- }
+ void deactivate();
template<typename T>
log_stream& operator<<(const T& arg) {
@@ -45,36 +35,10 @@ public:
log_stream& operator<<(
std::basic_ostream<char>& (*func)
- (std::basic_ostream<char>&) ) {
- if (m_active) {
- m_buffer << *func;
- trim_buffer();
- }
- else
- {
- std::cout << *func;
- }
- return *this;
- }
+ (std::basic_ostream<char>&) );
private:
- void trim_buffer()
- {
- std::string s = m_buffer.str();
- size_t pos = s.npos;
- for (int i = 0; i <= m_log_lines; ++i) {
- pos = s.rfind("\n", pos);
- if (pos == s.npos) {
- // too few lines
- return;
- }
- if (pos > 0) {
- --pos;
- }
- }
-
- m_buffer.str(s.substr((pos <= (s.size() - 2)) ? pos + 2 : pos));
- }
+ void trim_buffer();
bool m_active;
std::stringstream m_buffer;