Convert SHOWTIME_MODES to enum class

This commit is contained in:
amai2012 2019-07-31 22:35:51 +02:00
parent 8deb855b41
commit b0fbbb5aa7
6 changed files with 17 additions and 17 deletions

View File

@ -750,13 +750,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
else if (std::strncmp(argv[i], "--showtime=", 11) == 0) { else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
const std::string showtimeMode = argv[i] + 11; const std::string showtimeMode = argv[i] + 11;
if (showtimeMode == "file") if (showtimeMode == "file")
mSettings->showtime = SHOWTIME_FILE; mSettings->showtime = SHOWTIME_MODES::SHOWTIME_FILE;
else if (showtimeMode == "summary") else if (showtimeMode == "summary")
mSettings->showtime = SHOWTIME_SUMMARY; mSettings->showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY;
else if (showtimeMode == "top5") else if (showtimeMode == "top5")
mSettings->showtime = SHOWTIME_TOP5; mSettings->showtime = SHOWTIME_MODES::SHOWTIME_TOP5;
else if (showtimeMode.empty()) else if (showtimeMode.empty())
mSettings->showtime = SHOWTIME_NONE; mSettings->showtime = SHOWTIME_MODES::SHOWTIME_NONE;
else { else {
std::string message("cppcheck: error: unrecognized showtime mode: \""); std::string message("cppcheck: error: unrecognized showtime mode: \"");
message += showtimeMode; message += showtimeMode;

View File

@ -471,7 +471,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
} }
Tokenizer mTokenizer(&mSettings, this); Tokenizer mTokenizer(&mSettings, this);
if (mSettings.showtime != SHOWTIME_NONE) if (mSettings.showtime != SHOWTIME_MODES::SHOWTIME_NONE)
mTokenizer.setTimerResults(&S_timerResults); mTokenizer.setTimerResults(&S_timerResults);
try { try {

View File

@ -55,7 +55,7 @@ Settings::Settings()
quiet(false), quiet(false),
relativePaths(false), relativePaths(false),
reportProgress(false), reportProgress(false),
showtime(SHOWTIME_NONE), showtime(SHOWTIME_MODES::SHOWTIME_NONE),
verbose(false), verbose(false),
xml(false), xml(false),
xml_version(2) xml_version(2)

View File

@ -41,7 +41,7 @@ namespace {
void TimerResults::ShowResults(SHOWTIME_MODES mode) const void TimerResults::ShowResults(SHOWTIME_MODES mode) const
{ {
if (mode == SHOWTIME_NONE) if (mode == SHOWTIME_MODES::SHOWTIME_NONE)
return; return;
std::cout << std::endl; std::cout << std::endl;
@ -55,7 +55,7 @@ void TimerResults::ShowResults(SHOWTIME_MODES mode) const
const double sec = iter->second.seconds(); const double sec = iter->second.seconds();
const double secAverage = sec / (double)(iter->second.mNumberOfResults); const double secAverage = sec / (double)(iter->second.mNumberOfResults);
overallData.mClocks += iter->second.mClocks; overallData.mClocks += iter->second.mClocks;
if ((mode != SHOWTIME_TOP5) || (ordinal<=5)) { if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5) || (ordinal<=5)) {
std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl; std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl;
} }
++ordinal; ++ordinal;
@ -71,14 +71,14 @@ void TimerResults::AddResults(const std::string& str, std::clock_t clocks)
mResults[str].mNumberOfResults++; mResults[str].mNumberOfResults++;
} }
Timer::Timer(const std::string& str, unsigned int showtimeMode, TimerResultsIntf* timerResults) Timer::Timer(const std::string& str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults)
: mStr(str) : mStr(str)
, mTimerResults(timerResults) , mTimerResults(timerResults)
, mStart(0) , mStart(0)
, mShowTimeMode(showtimeMode) , mShowTimeMode(showtimeMode)
, mStopped(false) , mStopped(false)
{ {
if (showtimeMode != SHOWTIME_NONE) if (showtimeMode != SHOWTIME_MODES::SHOWTIME_NONE)
mStart = std::clock(); mStart = std::clock();
} }
@ -89,11 +89,11 @@ Timer::~Timer()
void Timer::Stop() void Timer::Stop()
{ {
if ((mShowTimeMode != SHOWTIME_NONE) && !mStopped) { if ((mShowTimeMode != SHOWTIME_MODES::SHOWTIME_NONE) && !mStopped) {
const std::clock_t end = std::clock(); const std::clock_t end = std::clock();
const std::clock_t diff = end - mStart; const std::clock_t diff = end - mStart;
if (mShowTimeMode == SHOWTIME_FILE) { if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) {
const double sec = (double)diff / CLOCKS_PER_SEC; const double sec = (double)diff / CLOCKS_PER_SEC;
std::cout << mStr << ": " << sec << "s" << std::endl; std::cout << mStr << ": " << sec << "s" << std::endl;
} else { } else {

View File

@ -26,7 +26,7 @@
#include <map> #include <map>
#include <string> #include <string>
enum SHOWTIME_MODES { enum class SHOWTIME_MODES {
SHOWTIME_NONE = 0, SHOWTIME_NONE = 0,
SHOWTIME_FILE, SHOWTIME_FILE,
SHOWTIME_SUMMARY, SHOWTIME_SUMMARY,
@ -69,7 +69,7 @@ private:
class CPPCHECKLIB Timer { class CPPCHECKLIB Timer {
public: public:
Timer(const std::string& str, unsigned int showtimeMode, TimerResultsIntf* timerResults = nullptr); Timer(const std::string& str, SHOWTIME_MODES showtimeMode, TimerResultsIntf* timerResults = nullptr);
~Timer(); ~Timer();
void Stop(); void Stop();
@ -80,7 +80,7 @@ private:
const std::string mStr; const std::string mStr;
TimerResultsIntf* mTimerResults; TimerResultsIntf* mTimerResults;
std::clock_t mStart; std::clock_t mStart;
const unsigned int mShowTimeMode; const SHOWTIME_MODES mShowTimeMode;
bool mStopped; bool mStopped;
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -893,9 +893,9 @@ private:
void showtime() { void showtime() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--showtime=summary"}; const char * const argv[] = {"cppcheck", "--showtime=summary"};
settings.showtime = SHOWTIME_NONE; settings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
ASSERT(defParser.parseFromArgs(2, argv)); ASSERT(defParser.parseFromArgs(2, argv));
ASSERT(settings.showtime == SHOWTIME_SUMMARY); ASSERT(settings.showtime == SHOWTIME_MODES::SHOWTIME_SUMMARY);
} }
void errorlist1() { void errorlist1() {