Skip to content

Commit 11ef2c0

Browse files
author
Daniel Marjamäki
committed
Refactoring: Cppcheck::reportProgress needs to call _errorLogger::reportProgress. Ticket: cppcheck-opensource#1625
1 parent 1555901 commit 11ef2c0

4 files changed

Lines changed: 42 additions & 31 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
CppCheckExecutor::CppCheckExecutor()
2727
{
28-
28+
time1 = std::time(0);
2929
}
3030

3131
CppCheckExecutor::~CppCheckExecutor()
@@ -87,6 +87,32 @@ void CppCheckExecutor::reportOut(const std::string &outmsg)
8787
std::cout << outmsg << std::endl;
8888
}
8989

90+
void CppCheckExecutor::reportProgress(const std::string &filename, const char stage[], const unsigned int value)
91+
{
92+
(void)filename;
93+
94+
// Report progress messages every 10 seconds
95+
const std::time_t time2 = std::time(NULL);
96+
if (time2 >= (time1 + 1))
97+
{
98+
time1 = time2;
99+
100+
// current time in the format "Www Mmm dd hh:mm:ss yyyy"
101+
const std::string str(std::ctime(&time2));
102+
103+
// format a progress message
104+
std::ostringstream ostr;
105+
ostr << "progress: "
106+
<< stage
107+
<< " " << int(value) << "%";
108+
if (_settings._verbose)
109+
ostr << " time=" << str.substr(11, 8);
110+
111+
// Report progress message
112+
reportOut(ostr.str());
113+
}
114+
}
115+
90116
void CppCheckExecutor::reportStatus(unsigned int index, unsigned int max)
91117
{
92118
if (max > 1 && !_settings._errorsOnly)

cli/cppcheckexecutor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "errorlogger.h"
2323
#include "settings.h"
24+
#include <ctime>
2425

2526
/**
2627
* This class works as an example of how CppCheck can be used in external
@@ -66,6 +67,8 @@ class CppCheckExecutor : public ErrorLogger
6667
/** xml output of errors */
6768
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
6869

70+
void reportProgress(const std::string &filename, const char stage[], const unsigned int value);
71+
6972
virtual void reportStatus(unsigned int index, unsigned int max);
7073

7174
protected:
@@ -80,6 +83,13 @@ class CppCheckExecutor : public ErrorLogger
8083
* check() will setup this in the beginning of check().
8184
*/
8285
Settings _settings;
86+
87+
private:
88+
89+
/**
90+
* Report progress time
91+
*/
92+
std::time_t time1;
8393
};
8494

8595
#endif // CPPCHECKEXECUTOR_H

lib/cppcheck.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ CppCheck::CppCheck(ErrorLogger &errorLogger)
171171
: _errorLogger(errorLogger)
172172
{
173173
exitcode = 0;
174-
time1 = std::time(0);
175174
}
176175

177176
CppCheck::~CppCheck()
@@ -928,35 +927,14 @@ const std::vector<std::string> &CppCheck::filenames() const
928927
return _filenames;
929928
}
930929

931-
void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
930+
void CppCheck::reportProgress(const std::string &filename, const char stage[], const unsigned int value)
932931
{
933-
932+
_errorLogger.reportProgress(filename, stage, value);
934933
}
935934

936-
void CppCheck::reportProgress(const std::string &filename, const char stage[], const unsigned int value)
935+
void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
937936
{
938-
(void)filename;
939937

940-
// Report progress messages every 10 seconds
941-
const std::time_t time2 = std::time(NULL);
942-
if (time2 >= (time1 + 10))
943-
{
944-
time1 = time2;
945-
946-
// current time in the format "Www Mmm dd hh:mm:ss yyyy"
947-
const std::string str(std::ctime(&time2));
948-
949-
// format a progress message
950-
std::ostringstream ostr;
951-
ostr << "progress: "
952-
<< stage
953-
<< " " << int(value) << "%";
954-
if (_settings._verbose)
955-
ostr << " time=" << str.substr(11, 8);
956-
957-
// Report progress message
958-
reportOut(ostr.str());
959-
}
960938
}
961939

962940
void CppCheck::getErrorMessages()

lib/cppcheck.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <sstream>
2929
#include <vector>
3030
#include <map>
31-
#include <ctime>
3231

3332
/// @addtogroup Core
3433
/// @{
@@ -157,14 +156,14 @@ class CppCheck : public ErrorLogger
157156
*/
158157
virtual void reportOut(const std::string &outmsg);
159158

160-
void reportProgress(const std::string &filename, const char stage[], const unsigned int value);
161-
162159
unsigned int exitcode;
163160
std::list<std::string> _errorList;
164161
std::ostringstream _errout;
165162
Settings _settings;
166163
std::vector<std::string> _filenames;
167164

165+
void reportProgress(const std::string &filename, const char stage[], const unsigned int value);
166+
168167
/** @brief Key is file name, and value is the content of the file */
169168
std::map<std::string, std::string> _fileContents;
170169

@@ -173,8 +172,6 @@ class CppCheck : public ErrorLogger
173172

174173
/** @brief Current preprocessor configuration */
175174
std::string cfg;
176-
177-
std::time_t time1;
178175
};
179176

180177
/// @}

0 commit comments

Comments
 (0)