From 11ef2c0a06570605161a3fd171210c0ebaeeebef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 Aug 2010 08:45:37 +0200 Subject: [PATCH] Refactoring: Cppcheck::reportProgress needs to call _errorLogger::reportProgress. Ticket: #1625 --- cli/cppcheckexecutor.cpp | 28 +++++++++++++++++++++++++++- cli/cppcheckexecutor.h | 10 ++++++++++ lib/cppcheck.cpp | 32 +++++--------------------------- lib/cppcheck.h | 7 ++----- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 193ed1c68..0b4505bac 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -25,7 +25,7 @@ CppCheckExecutor::CppCheckExecutor() { - + time1 = std::time(0); } CppCheckExecutor::~CppCheckExecutor() @@ -87,6 +87,32 @@ void CppCheckExecutor::reportOut(const std::string &outmsg) std::cout << outmsg << std::endl; } +void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const unsigned int value) +{ + (void)filename; + + // Report progress messages every 10 seconds + const std::time_t time2 = std::time(NULL); + if (time2 >= (time1 + 1)) + { + time1 = time2; + + // current time in the format "Www Mmm dd hh:mm:ss yyyy" + const std::string str(std::ctime(&time2)); + + // format a progress message + std::ostringstream ostr; + ostr << "progress: " + << stage + << " " << int(value) << "%"; + if (_settings._verbose) + ostr << " time=" << str.substr(11, 8); + + // Report progress message + reportOut(ostr.str()); + } +} + void CppCheckExecutor::reportStatus(unsigned int index, unsigned int max) { if (max > 1 && !_settings._errorsOnly) diff --git a/cli/cppcheckexecutor.h b/cli/cppcheckexecutor.h index 1841dfce0..813a2f196 100644 --- a/cli/cppcheckexecutor.h +++ b/cli/cppcheckexecutor.h @@ -21,6 +21,7 @@ #include "errorlogger.h" #include "settings.h" +#include /** * This class works as an example of how CppCheck can be used in external @@ -66,6 +67,8 @@ public: /** xml output of errors */ virtual void reportErr(const ErrorLogger::ErrorMessage &msg); + void reportProgress(const std::string &filename, const char stage[], const unsigned int value); + virtual void reportStatus(unsigned int index, unsigned int max); protected: @@ -80,6 +83,13 @@ protected: * check() will setup this in the beginning of check(). */ Settings _settings; + +private: + + /** + * Report progress time + */ + std::time_t time1; }; #endif // CPPCHECKEXECUTOR_H diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index da817c29e..bcf0395d5 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -171,7 +171,6 @@ CppCheck::CppCheck(ErrorLogger &errorLogger) : _errorLogger(errorLogger) { exitcode = 0; - time1 = std::time(0); } CppCheck::~CppCheck() @@ -928,37 +927,16 @@ const std::vector &CppCheck::filenames() const return _filenames; } +void CppCheck::reportProgress(const std::string &filename, const char stage[], const unsigned int value) +{ + _errorLogger.reportProgress(filename, stage, value); +} + void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/) { } -void CppCheck::reportProgress(const std::string &filename, const char stage[], const unsigned int value) -{ - (void)filename; - - // Report progress messages every 10 seconds - const std::time_t time2 = std::time(NULL); - if (time2 >= (time1 + 10)) - { - time1 = time2; - - // current time in the format "Www Mmm dd hh:mm:ss yyyy" - const std::string str(std::ctime(&time2)); - - // format a progress message - std::ostringstream ostr; - ostr << "progress: " - << stage - << " " << int(value) << "%"; - if (_settings._verbose) - ostr << " time=" << str.substr(11, 8); - - // Report progress message - reportOut(ostr.str()); - } -} - void CppCheck::getErrorMessages() { // call all "getErrorMessages" in all registered Check classes diff --git a/lib/cppcheck.h b/lib/cppcheck.h index a7bcea169..4c48081cd 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -28,7 +28,6 @@ #include #include #include -#include /// @addtogroup Core /// @{ @@ -157,14 +156,14 @@ private: */ virtual void reportOut(const std::string &outmsg); - void reportProgress(const std::string &filename, const char stage[], const unsigned int value); - unsigned int exitcode; std::list _errorList; std::ostringstream _errout; Settings _settings; std::vector _filenames; + void reportProgress(const std::string &filename, const char stage[], const unsigned int value); + /** @brief Key is file name, and value is the content of the file */ std::map _fileContents; @@ -173,8 +172,6 @@ private: /** @brief Current preprocessor configuration */ std::string cfg; - - std::time_t time1; }; /// @}