From 4b10c84adfc11fef30d80f4b41c086e8c9fefc9c Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 29 Jan 2021 00:45:26 +0100 Subject: [PATCH] Add tostring converter using the LogStream system --- inferno/src/inferno/io/log.cpp | 16 ++++++++++++++++ inferno/src/inferno/io/log.h | 32 ++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/inferno/src/inferno/io/log.cpp b/inferno/src/inferno/io/log.cpp index 9c3079d..c496d4c 100644 --- a/inferno/src/inferno/io/log.cpp +++ b/inferno/src/inferno/io/log.cpp @@ -92,6 +92,15 @@ namespace Inferno { write(color, strlen(color)); } +// ----------------------------------------- + + StringLogStream::~StringLogStream() + { + char terminator = '\0'; + write(&terminator, 1); + *m_fill = std::string(reinterpret_cast(buffer())); + } + // ----------------------------------------- const LogStream& operator<<(const LogStream& stream, const char* value) @@ -305,4 +314,11 @@ namespace Inferno { dbg(type, newline) << format; } +// ----------------------------------------- + + StringLogStream str(std::string* fill) + { + return StringLogStream(fill); + } + } diff --git a/inferno/src/inferno/io/log.h b/inferno/src/inferno/io/log.h index 9ce2c8a..4fe92e2 100644 --- a/inferno/src/inferno/io/log.h +++ b/inferno/src/inferno/io/log.h @@ -85,14 +85,14 @@ namespace Inferno { class DebugLogStream final : public BufferedLogStream { public: - DebugLogStream(): - m_newline(true), m_type(Log::None) {} - DebugLogStream(bool newline): - m_newline(newline), m_type(Log::None) {} - DebugLogStream(Log type): - m_newline(true), m_type(type) { color(); } - DebugLogStream(Log type, bool newline): - m_newline(newline), m_type(type) { color(); } + DebugLogStream() + : m_newline(true), m_type(Log::None) {} + DebugLogStream(bool newline) + : m_newline(newline), m_type(Log::None) {} + DebugLogStream(Log type) + : m_newline(true), m_type(type) { color(); } + DebugLogStream(Log type, bool newline) + : m_newline(newline), m_type(type) { color(); } virtual ~DebugLogStream() override; void color() const; @@ -102,6 +102,18 @@ namespace Inferno { Log m_type; }; +// ----------------------------------------- + + class StringLogStream final : public BufferedLogStream { + public: + StringLogStream(std::string* fill) + : m_fill(fill) {} + virtual ~StringLogStream() override; + + private: + std::string* m_fill; + }; + // ----------------------------------------- const LogStream& operator<<(const LogStream& stream, const char* value); @@ -209,6 +221,10 @@ namespace Inferno { dbgln(type, newline, format.data(), value, std::forward

(parameters)...); } +// ----------------------------------------- + + StringLogStream str(std::string* fill); + } #endif // LOG_H