diff --git a/include/plasp/utils/Formatting.h b/include/plasp/utils/Formatting.h index ee64388..652ce7c 100644 --- a/include/plasp/utils/Formatting.h +++ b/include/plasp/utils/Formatting.h @@ -52,8 +52,7 @@ struct Format //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &operator<<(LogStream &stream, const Format &format) +LogStream &operator<<(LogStream &stream, const Format &format) { if (!stream.supportsColor()) return stream; @@ -72,8 +71,7 @@ class ResetFormat //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &operator<<(LogStream &stream, const ResetFormat &) +LogStream &operator<<(LogStream &stream, const ResetFormat &) { if (!stream.supportsColor()) return stream; diff --git a/include/plasp/utils/LogStream.h b/include/plasp/utils/LogStream.h index cd7d1c1..8e8c8a5 100644 --- a/include/plasp/utils/LogStream.h +++ b/include/plasp/utils/LogStream.h @@ -23,7 +23,6 @@ enum class StandardStream //////////////////////////////////////////////////////////////////////////////////////////////////// -template class LogStream { private: @@ -31,10 +30,37 @@ class LogStream using TraitsType = std::ostream::traits_type; public: + LogStream(StandardStream standardStream) + : m_standardStream{standardStream} + { + } + + LogStream(const LogStream &other) + : m_standardStream{other.m_standardStream} + { + } + + LogStream &operator=(const LogStream &other) + { + m_standardStream = other.m_standardStream; + return *this; + } + + LogStream(LogStream &&other) + : m_standardStream{other.m_standardStream} + { + } + + LogStream &operator=(LogStream &&other) + { + m_standardStream = other.m_standardStream; + return *this; + } + bool supportsColor() const { const auto fileDescriptor = - (StandardStream == utils::StandardStream::Out) + (m_standardStream == utils::StandardStream::Out) ? STDOUT_FILENO : STDERR_FILENO; @@ -43,35 +69,37 @@ class LogStream std::ostream &ostream() { - return (StandardStream == utils::StandardStream::Out) + return (m_standardStream == utils::StandardStream::Out) ? std::cout : std::cerr; } - LogStream &operator<<(short value); - LogStream &operator<<(unsigned short value); - LogStream &operator<<(int value); - LogStream &operator<<(unsigned int value); - LogStream &operator<<(long value); - LogStream &operator<<(unsigned long value); - LogStream &operator<<(long long value); - LogStream &operator<<(unsigned long long value); - LogStream &operator<<(float value); - LogStream &operator<<(double value); - LogStream &operator<<(long double value); - LogStream &operator<<(bool value); - LogStream &operator<<(const void *value); - LogStream &operator<<(const char *value); - LogStream &operator<<(std::basic_streambuf *sb); - LogStream &operator<<(std::ios_base &(*func)(std::ios_base &)); - LogStream &operator<<(std::basic_ios &(*func)(std::basic_ios &)); - LogStream &operator<<(std::basic_ostream &(*func)(std::basic_ostream &)); + inline LogStream &operator<<(short value); + inline LogStream &operator<<(unsigned short value); + inline LogStream &operator<<(int value); + inline LogStream &operator<<(unsigned int value); + inline LogStream &operator<<(long value); + inline LogStream &operator<<(unsigned long value); + inline LogStream &operator<<(long long value); + inline LogStream &operator<<(unsigned long long value); + inline LogStream &operator<<(float value); + inline LogStream &operator<<(double value); + inline LogStream &operator<<(long double value); + inline LogStream &operator<<(bool value); + inline LogStream &operator<<(const void *value); + inline LogStream &operator<<(const char *value); + inline LogStream &operator<<(std::basic_streambuf *sb); + inline LogStream &operator<<(std::ios_base &(*func)(std::ios_base &)); + inline LogStream &operator<<(std::basic_ios &(*func)(std::basic_ios &)); + inline LogStream &operator<<(std::basic_ostream &(*func)(std::basic_ostream &)); + + private: + StandardStream m_standardStream; }; //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(short value) +LogStream &LogStream::operator<<(short value) { ostream() << value; return *this; @@ -79,8 +107,7 @@ LogStream &LogStream::operator<<(short value) //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(unsigned short value) +LogStream &LogStream::operator<<(unsigned short value) { ostream() << value; return *this; @@ -88,8 +115,7 @@ LogStream &LogStream::operator<<(unsigned short //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(int value) +LogStream &LogStream::operator<<(int value) { ostream() << value; return *this; @@ -97,8 +123,7 @@ LogStream &LogStream::operator<<(int value) //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(unsigned int value) +LogStream &LogStream::operator<<(unsigned int value) { ostream() << value; return *this; @@ -106,8 +131,7 @@ LogStream &LogStream::operator<<(unsigned int va //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(long value) +LogStream &LogStream::operator<<(long value) { ostream() << value; return *this; @@ -115,8 +139,7 @@ LogStream &LogStream::operator<<(long value) //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(unsigned long value) +LogStream &LogStream::operator<<(unsigned long value) { ostream() << value; return *this; @@ -124,8 +147,7 @@ LogStream &LogStream::operator<<(unsigned long v //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(long long value) +LogStream &LogStream::operator<<(long long value) { ostream() << value; return *this; @@ -133,8 +155,7 @@ LogStream &LogStream::operator<<(long long value //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(unsigned long long value) +LogStream &LogStream::operator<<(unsigned long long value) { ostream() << value; return *this; @@ -142,8 +163,7 @@ LogStream &LogStream::operator<<(unsigned long l //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(float value) +LogStream &LogStream::operator<<(float value) { ostream() << value; return *this; @@ -151,8 +171,7 @@ LogStream &LogStream::operator<<(float value) //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(double value) +LogStream &LogStream::operator<<(double value) { ostream() << value; return *this; @@ -160,8 +179,7 @@ LogStream &LogStream::operator<<(double value) //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(long double value) +LogStream &LogStream::operator<<(long double value) { ostream() << value; return *this; @@ -169,8 +187,7 @@ LogStream &LogStream::operator<<(long double val //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(bool value) +LogStream &LogStream::operator<<(bool value) { ostream() << value; return *this; @@ -178,8 +195,7 @@ LogStream &LogStream::operator<<(bool value) //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(const void *value) +LogStream &LogStream::operator<<(const void *value) { ostream() << value; return *this; @@ -187,8 +203,7 @@ LogStream &LogStream::operator<<(const void *val //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(const char *value) +LogStream &LogStream::operator<<(const char *value) { ostream() << value; return *this; @@ -196,8 +211,7 @@ LogStream &LogStream::operator<<(const char *val //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(std::basic_streambuf* sb) +LogStream &LogStream::operator<<(std::basic_streambuf* sb) { ostream() << sb; return *this; @@ -205,8 +219,7 @@ LogStream &LogStream::operator<<(std::basic_stre //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(std::ios_base &(*func)(std::ios_base &)) +LogStream &LogStream::operator<<(std::ios_base &(*func)(std::ios_base &)) { ostream() << func; return *this; @@ -214,8 +227,7 @@ LogStream &LogStream::operator<<(std::ios_base & //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(std::basic_ios &(*func)(std::basic_ios &)) +LogStream &LogStream::operator<<(std::basic_ios &(*func)(std::basic_ios &)) { ostream() << func; return *this; @@ -223,8 +235,7 @@ LogStream &LogStream::operator<<(std::basic_ios< //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &LogStream::operator<<(std::basic_ostream &(*func)(std::basic_ostream &)) +LogStream &LogStream::operator<<(std::basic_ostream &(*func)(std::basic_ostream &)) { ostream() << func; return *this; @@ -232,8 +243,8 @@ LogStream &LogStream::operator<<(std::basic_ostr //////////////////////////////////////////////////////////////////////////////////////////////////// -template -LogStream &operator<<(LogStream &stream, const std::basic_string &string) +template +LogStream &operator<<(LogStream &stream, const std::basic_string &string) { stream.ostream() << string; return stream; diff --git a/include/plasp/utils/Logger.h b/include/plasp/utils/Logger.h index 732a183..ff56ba1 100644 --- a/include/plasp/utils/Logger.h +++ b/include/plasp/utils/Logger.h @@ -37,8 +37,8 @@ class Logger Logger(Logger &&other); Logger &operator=(Logger &&other); - LogStream &outputStream(); - LogStream &errorStream(); + LogStream &outputStream(); + LogStream &errorStream(); void setWarningLevel(WarningLevel warningLevel); @@ -47,8 +47,8 @@ class Logger void logWarning(const Parser &parser, const std::string &message); private: - LogStream m_outputStream; - LogStream m_errorStream; + LogStream m_outputStream; + LogStream m_errorStream; WarningLevel m_warningLevel; }; diff --git a/src/plasp/utils/Logger.cpp b/src/plasp/utils/Logger.cpp index af42817..80cbf9c 100644 --- a/src/plasp/utils/Logger.cpp +++ b/src/plasp/utils/Logger.cpp @@ -14,14 +14,18 @@ namespace utils //////////////////////////////////////////////////////////////////////////////////////////////////// Logger::Logger() -: m_warningLevel{Logger::WarningLevel::Normal} +: m_outputStream(StandardStream::Out), + m_errorStream(StandardStream::Err), + m_warningLevel{Logger::WarningLevel::Normal} { } //////////////////////////////////////////////////////////////////////////////////////////////////// Logger::Logger(const Logger &other) -: m_warningLevel{other.m_warningLevel} +: m_outputStream{other.m_outputStream}, + m_errorStream{other.m_errorStream}, + m_warningLevel{other.m_warningLevel} { } @@ -29,6 +33,8 @@ Logger::Logger(const Logger &other) Logger &Logger::operator=(const Logger &other) { + m_outputStream = other.m_outputStream; + m_errorStream = other.m_errorStream; m_warningLevel = other.m_warningLevel; return *this; @@ -37,7 +43,9 @@ Logger &Logger::operator=(const Logger &other) //////////////////////////////////////////////////////////////////////////////////////////////////// Logger::Logger(Logger &&other) -: m_warningLevel{other.m_warningLevel} +: m_outputStream{other.m_outputStream}, + m_errorStream{other.m_errorStream}, + m_warningLevel{other.m_warningLevel} { other.m_warningLevel = WarningLevel::Normal; } @@ -46,6 +54,8 @@ Logger::Logger(Logger &&other) Logger &Logger::operator=(Logger &&other) { + m_outputStream = other.m_outputStream; + m_errorStream = other.m_errorStream; m_warningLevel = other.m_warningLevel; other.m_warningLevel = WarningLevel::Normal; @@ -54,14 +64,14 @@ Logger &Logger::operator=(Logger &&other) //////////////////////////////////////////////////////////////////////////////////////////////////// -LogStream &Logger::outputStream() +LogStream &Logger::outputStream() { return m_outputStream; } //////////////////////////////////////////////////////////////////////////////////////////////////// -LogStream &Logger::errorStream() +LogStream &Logger::errorStream() { return m_errorStream; }