Cppcheck
checkstatistics.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "checkstatistics.h"
20 
21 #include <QDebug>
22 #include <QList>
23 #include <QSet>
24 
26  : QObject(parent)
27 {
28  clear();
29 }
30 
31 static void addItem(QMap<QString,unsigned> &m, const QString &key)
32 {
33  if (m.contains(key))
34  m[key]++;
35  else
36  m[key] = 0;
37 }
38 
39 void CheckStatistics::addItem(const QString &tool, ShowTypes::ShowType type)
40 {
41  const QString lower = tool.toLower();
42  switch (type) {
44  ::addItem(mStyle, lower);
45  break;
47  ::addItem(mWarning, lower);
48  break;
50  ::addItem(mPerformance, lower);
51  break;
53  ::addItem(mPortability, lower);
54  break;
56  ::addItem(mError, lower);
57  break;
59  ::addItem(mInformation, lower);
60  break;
62  default:
63  qDebug() << "Unknown error type - not added to statistics.";
64  break;
65  }
66 }
67 
68 void CheckStatistics::addChecker(const QString &checker)
69 {
70  mActiveCheckers.insert(checker.toStdString());
71 }
72 
74 {
75  mStyle.clear();
76  mWarning.clear();
77  mPerformance.clear();
78  mPortability.clear();
79  mInformation.clear();
80  mError.clear();
81  mActiveCheckers.clear();
82  mCheckersReport.clear();
83 }
84 
85 unsigned CheckStatistics::getCount(const QString &tool, ShowTypes::ShowType type) const
86 {
87  const QString lower = tool.toLower();
88  switch (type) {
90  return mStyle.value(lower,0);
92  return mWarning.value(lower,0);
94  return mPerformance.value(lower,0);
96  return mPortability.value(lower,0);
98  return mError.value(lower,0);
100  return mInformation.value(lower,0);
101  case ShowTypes::ShowNone:
102  default:
103  qDebug() << "Unknown error type - returning zero statistics.";
104  return 0;
105  }
106 }
107 
108 QStringList CheckStatistics::getTools() const
109 {
110  QSet<QString> ret;
111  for (const QString& tool: mStyle.keys()) ret.insert(tool);
112  for (const QString& tool: mWarning.keys()) ret.insert(tool);
113  for (const QString& tool: mPerformance.keys()) ret.insert(tool);
114  for (const QString& tool: mPortability.keys()) ret.insert(tool);
115  for (const QString& tool: mError.keys()) ret.insert(tool);
116  return QStringList(ret.values());
117 }
static void addItem(QMap< QString, unsigned > &m, const QString &key)
QStringList getTools() const
Get tools with results.
void clear()
Clear the statistics.
std::set< std::string > mActiveCheckers
CheckStatistics(QObject *parent=nullptr)
unsigned getCount(const QString &tool, ShowTypes::ShowType type) const
Return statistics for given type.
QMap< QString, unsigned > mError
QMap< QString, unsigned > mPortability
QMap< QString, unsigned > mWarning
void addItem(const QString &tool, ShowTypes::ShowType type)
Add new checked item to statistics.
QMap< QString, unsigned > mInformation
void addChecker(const QString &checker)
Add checker to statistics.
QString mCheckersReport
QMap< QString, unsigned > mPerformance
QMap< QString, unsigned > mStyle
ShowType
Show types we have (i.e.
Definition: showtypes.h:44
@ ShowPerformance
Definition: showtypes.h:47
@ ShowInformation
Definition: showtypes.h:49
@ ShowPortability
Definition: showtypes.h:48
@ ShowErrors
Definition: showtypes.h:50
@ ShowWarnings
Definition: showtypes.h:46
@ ShowStyle
Definition: showtypes.h:45
@ ShowNone
Definition: showtypes.h:51