From 17455f2084f905bcc1e4fb152bee7fb696a9d421 Mon Sep 17 00:00:00 2001 From: denes Date: Mon, 11 Nov 2019 14:44:52 +0100 Subject: [PATCH] enable multiple << in one line --- Logger.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Logger.hpp b/Logger.hpp index 34d7da0..feafe17 100644 --- a/Logger.hpp +++ b/Logger.hpp @@ -1,9 +1,11 @@ #ifndef LOGGER_HPP #define LOGGER_HPP -#include #include +#include +#include + #include "Singleton_DCLP.hpp" class Logger : public Singleton_DCLP @@ -11,22 +13,23 @@ class Logger : public Singleton_DCLP public: class Endl {}; - Logger() : m_os(nullptr), m_print_time_stamp(false) {} + Logger() : m_os(nullptr), m_buffer(), m_print_time_stamp(false) {} void setStream(std::ostream* os) { m_os = os; } - std::ostream* getStream() { return m_os; } void setPrintTimeStamp(bool b = true) { m_print_time_stamp = b; } template Logger &operator<<(const T &x) { - decorate(); - *m_os << x; + m_buffer << x; return *this; } Logger& operator<<(const Logger::Endl& e) { + decorate(); + *m_os << m_buffer.str(); *m_os << std::endl; + m_buffer.str(""); return *this; } @@ -43,6 +46,7 @@ private: // ostreams are not copyable, hence storing a pointer only std::ostream* m_os; + std::ostringstream m_buffer; bool m_print_time_stamp; };