Cppcheck
erroritem.h
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 #ifndef ERRORITEM_H
20 #define ERRORITEM_H
21 
22 #include "errorlogger.h"
23 #include "errortypes.h"
24 
25 #include <QList>
26 #include <QMetaType>
27 #include <QString>
28 
29 /// @addtogroup GUI
30 /// @{
31 
32 
33 /**
34  * @brief GUI versions of severity conversions.
35  * GUI needs wrappers for conversion functions since GUI uses Qt's QString
36  * instead of the std::string used by lib/cli.
37  */
38 class GuiSeverity {
39 public:
40  static QString toString(Severity severity) {
41  return QString::fromStdString(severityToString(severity));
42  }
43 
44  static Severity fromString(const QString &severity) {
45  return severityFromString(severity.toStdString());
46  }
47 };
48 
49 /**
50  * @brief A class containing data for one error path item
51  */
53 public:
54  QErrorPathItem() : line(0), column(-1) {}
55  explicit QErrorPathItem(const ErrorMessage::FileLocation &loc);
56  QString file;
57  int line;
58  int column;
59  QString info;
60 };
61 
62 bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2);
63 
64 /**
65  * @brief A class containing error data for one error.
66  *
67  * The paths are stored with internal ("/") separators. Only when we show the
68  * path or copy if for user (to clipboard) we convert to native separators.
69  * Full path is stored instead of relative path for flexibility. It is easy
70  * to get the relative path from full path when needed.
71  */
72 class ErrorItem {
73 public:
74  ErrorItem();
75  explicit ErrorItem(const ErrorMessage &errmsg);
76 
77  /**
78  * @brief Convert error item to string.
79  * @return Error item as string.
80  */
81  QString toString() const;
82  QString tool() const;
83 
84  QString file0;
85  QString errorId;
88  QString summary;
89  QString message;
90  int cwe;
91  unsigned long long hash;
92  QList<QErrorPathItem> errorPath;
93  QString symbolNames;
94 
95  // Special GUI properties
96  QString sinceDate;
97  QString tags;
98 
99  /**
100  * Compare "CID"
101  */
102  static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
103 };
104 
105 // NOLINTNEXTLINE(performance-no-int-to-ptr)
106 Q_DECLARE_METATYPE(ErrorItem)
107 
108 /**
109  * @brief A class containing error data for one shown error line.
110  */
111 class ErrorLine {
112 public:
113  QString file;
114  int line;
115  QString file0;
116  QString errorId;
117  int cwe;
118  unsigned long long hash;
121  QString summary;
122  QString message;
123  QString sinceDate;
124  QString tags;
125 };
126 
127 /// @}
128 #endif // ERRORITEM_H
A class containing error data for one error.
Definition: erroritem.h:72
QString toString() const
Convert error item to string.
Definition: erroritem.cpp:73
bool inconclusive
Definition: erroritem.h:87
QString file0
Definition: erroritem.h:84
int cwe
Definition: erroritem.h:90
QString tool() const
Definition: erroritem.cpp:62
QString summary
Definition: erroritem.h:88
Severity severity
Definition: erroritem.h:86
QString symbolNames
Definition: erroritem.h:93
static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2)
Compare "CID".
Definition: erroritem.cpp:87
unsigned long long hash
Definition: erroritem.h:91
QString message
Definition: erroritem.h:89
QList< QErrorPathItem > errorPath
Definition: erroritem.h:92
QString sinceDate
Definition: erroritem.h:96
QString tags
Definition: erroritem.h:97
QString errorId
Definition: erroritem.h:85
A class containing error data for one shown error line.
Definition: erroritem.h:111
unsigned long long hash
Definition: erroritem.h:118
bool inconclusive
Definition: erroritem.h:119
int line
Definition: erroritem.h:114
QString file0
Definition: erroritem.h:115
QString errorId
Definition: erroritem.h:116
Severity severity
Definition: erroritem.h:120
QString tags
Definition: erroritem.h:124
QString summary
Definition: erroritem.h:121
QString sinceDate
Definition: erroritem.h:123
QString file
Definition: erroritem.h:113
QString message
Definition: erroritem.h:122
File name and line number.
Definition: errorlogger.h:55
Wrapper for error messages, provided by reportErr()
Definition: errorlogger.h:48
GUI versions of severity conversions.
Definition: erroritem.h:38
static QString toString(Severity severity)
Definition: erroritem.h:40
static Severity fromString(const QString &severity)
Definition: erroritem.h:44
A class containing data for one error path item.
Definition: erroritem.h:52
QString file
Definition: erroritem.h:56
QString info
Definition: erroritem.h:59
Severity
enum class for severity.
Definition: errortypes.h:63
Severity severityFromString(const std::string &severity)
Definition: errortypes.cpp:76
std::string severityToString(Severity severity)
Definition: errortypes.cpp:50
bool operator==(const QErrorPathItem &i1, const QErrorPathItem &i2)
Definition: erroritem.cpp:32