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) {
const std::string showtimeMode = argv[i] + 11;
if (showtimeMode == "file")
mSettings->showtime = SHOWTIME_FILE;
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_FILE;
else if (showtimeMode == "summary")
mSettings->showtime = SHOWTIME_SUMMARY;
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY;
else if (showtimeMode == "top5")
mSettings->showtime = SHOWTIME_TOP5;
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_TOP5;
else if (showtimeMode.empty())
mSettings->showtime = SHOWTIME_NONE;
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_NONE;
else {
std::string message("cppcheck: error: unrecognized showtime mode: \"");
message += showtimeMode;

View File

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

View File

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

View File

@ -41,7 +41,7 @@ namespace {
void TimerResults::ShowResults(SHOWTIME_MODES mode) const
{
if (mode == SHOWTIME_NONE)
if (mode == SHOWTIME_MODES::SHOWTIME_NONE)
return;
std::cout << std::endl;
@ -55,7 +55,7 @@ void TimerResults::ShowResults(SHOWTIME_MODES mode) const
const double sec = iter->second.seconds();
const double secAverage = sec / (double)(iter->second.mNumberOfResults);
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;
}
++ordinal;
@ -71,14 +71,14 @@ void TimerResults::AddResults(const std::string& str, std::clock_t clocks)
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)
, mTimerResults(timerResults)
, mStart(0)
, mShowTimeMode(showtimeMode)
, mStopped(false)
{
if (showtimeMode != SHOWTIME_NONE)
if (showtimeMode != SHOWTIME_MODES::SHOWTIME_NONE)
mStart = std::clock();
}
@ -89,11 +89,11 @@ Timer::~Timer()
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 diff = end - mStart;
if (mShowTimeMode == SHOWTIME_FILE) {
if (mShowTimeMode == SHOWTIME_MODES::SHOWTIME_FILE) {
const double sec = (double)diff / CLOCKS_PER_SEC;
std::cout << mStr << ": " << sec << "s" << std::endl;
} else {

View File

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

View File

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