Browse Source

Add tostring converter using the LogStream system

master
Riyyi 4 years ago
parent
commit
4b10c84adf
  1. 16
      inferno/src/inferno/io/log.cpp
  2. 32
      inferno/src/inferno/io/log.h

16
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<char*>(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);
}
}

32
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<P>(parameters)...);
}
// -----------------------------------------
StringLogStream str(std::string* fill);
}
#endif // LOG_H

Loading…
Cancel
Save