From 02e24f0f533fe904c3a5275c4060c10c38d7c17a Mon Sep 17 00:00:00 2001 From: Ján Sučan Date: Wed, 10 May 2017 15:13:29 +0200 Subject: Uvodny commit, subory su rovnake ako na CD prilozenom k vytlacenemu texu bakalarskej prace, naviac je pridany len subor LICENCIA --- Logger.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 Logger.cpp (limited to 'Logger.cpp') diff --git a/Logger.cpp b/Logger.cpp new file mode 100755 index 0000000..142442e --- /dev/null +++ b/Logger.cpp @@ -0,0 +1,73 @@ +#include "Logger.hpp" +#include "ExitException.hpp" +#include + +using std::endl; +using std::cout; +using std::cerr; +using std::flush; +using std::hex; +using std::uppercase; +using std::ostringstream; + +bool CLogger::mLogInfo = false; +int CLogger::mProgressLastPercent = -1; + +void +CLogger::error(const string & msg, int returnValue) +{ + cerr << "ERROR: " << msg << endl; + throw CExitException(msg, returnValue); +} + +void +CLogger::warning(const string & msg) +{ + cerr << "WARNING: " << msg << endl; +} + +void +CLogger::info(const string & msg) +{ + if (!CLogger::mLogInfo) + return; + cout << "INFO: " << msg << endl; +} + +void +CLogger::progress(uint32_t b, uint32_t n) +{ + if (b > n) + b = n; + + double d = n; + int p = (int) (b / (d / 100.0)); + if ((p == 100) && (b != n)) + p = 99; + else if (p > 100) + p = 100; + + if (((p == 0) && (p != mProgressLastPercent)) + || ((p == 100) && (p != mProgressLastPercent)) + || ((p - mProgressLastPercent) >= LOGGER_PROGRESS_UNIT)) { + cout << p << "% (" << b << " B / " << n << " B)" << endl; + mProgressLastPercent = p; + } + + if (p == 100) + mProgressLastPercent = -1; +} + +void +CLogger::setLogInfo(bool b) +{ + mLogInfo = b; +} + +string +CLogger::decToHex(int dec) +{ + ostringstream os; + os << "0x" << hex << uppercase << dec; + return os.str(); +} -- cgit v1.2.3