Refactoring: Cppcheck::reportProgress needs to call _errorLogger::reportProgress. Ticket: #1625

This commit is contained in:
Daniel Marjamäki 2010-08-08 08:45:37 +02:00
parent 1555901077
commit 11ef2c0a06
4 changed files with 44 additions and 33 deletions

View File

@ -25,7 +25,7 @@
CppCheckExecutor::CppCheckExecutor() CppCheckExecutor::CppCheckExecutor()
{ {
time1 = std::time(0);
} }
CppCheckExecutor::~CppCheckExecutor() CppCheckExecutor::~CppCheckExecutor()
@ -87,6 +87,32 @@ void CppCheckExecutor::reportOut(const std::string &outmsg)
std::cout << outmsg << std::endl; 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) void CppCheckExecutor::reportStatus(unsigned int index, unsigned int max)
{ {
if (max > 1 && !_settings._errorsOnly) if (max > 1 && !_settings._errorsOnly)

View File

@ -21,6 +21,7 @@
#include "errorlogger.h" #include "errorlogger.h"
#include "settings.h" #include "settings.h"
#include <ctime>
/** /**
* This class works as an example of how CppCheck can be used in external * This class works as an example of how CppCheck can be used in external
@ -66,6 +67,8 @@ public:
/** xml output of errors */ /** xml output of errors */
virtual void reportErr(const ErrorLogger::ErrorMessage &msg); 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); virtual void reportStatus(unsigned int index, unsigned int max);
protected: protected:
@ -80,6 +83,13 @@ protected:
* check() will setup this in the beginning of check(). * check() will setup this in the beginning of check().
*/ */
Settings _settings; Settings _settings;
private:
/**
* Report progress time
*/
std::time_t time1;
}; };
#endif // CPPCHECKEXECUTOR_H #endif // CPPCHECKEXECUTOR_H

View File

@ -171,7 +171,6 @@ CppCheck::CppCheck(ErrorLogger &errorLogger)
: _errorLogger(errorLogger) : _errorLogger(errorLogger)
{ {
exitcode = 0; exitcode = 0;
time1 = std::time(0);
} }
CppCheck::~CppCheck() CppCheck::~CppCheck()
@ -928,37 +927,16 @@ const std::vector<std::string> &CppCheck::filenames() const
return _filenames; 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::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() void CppCheck::getErrorMessages()
{ {
// call all "getErrorMessages" in all registered Check classes // call all "getErrorMessages" in all registered Check classes

View File

@ -28,7 +28,6 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <map> #include <map>
#include <ctime>
/// @addtogroup Core /// @addtogroup Core
/// @{ /// @{
@ -157,14 +156,14 @@ private:
*/ */
virtual void reportOut(const std::string &outmsg); virtual void reportOut(const std::string &outmsg);
void reportProgress(const std::string &filename, const char stage[], const unsigned int value);
unsigned int exitcode; unsigned int exitcode;
std::list<std::string> _errorList; std::list<std::string> _errorList;
std::ostringstream _errout; std::ostringstream _errout;
Settings _settings; Settings _settings;
std::vector<std::string> _filenames; std::vector<std::string> _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 */ /** @brief Key is file name, and value is the content of the file */
std::map<std::string, std::string> _fileContents; std::map<std::string, std::string> _fileContents;
@ -173,8 +172,6 @@ private:
/** @brief Current preprocessor configuration */ /** @brief Current preprocessor configuration */
std::string cfg; std::string cfg;
std::time_t time1;
}; };
/// @} /// @}