Cppcheck
xmlreportv2.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 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 XML_REPORTV2_H
20 #define XML_REPORTV2_H
21 
22 #include "erroritem.h"
23 #include "xmlreport.h"
24 
25 #include <QList>
26 #include <QString>
27 
28 class QXmlStreamReader;
29 class QXmlStreamWriter;
30 
31 /// @addtogroup GUI
32 /// @{
33 
34 
35 /**
36  * @brief XML file report version 2.
37  * This report outputs XML-formatted report. The XML format must match command
38  * line version's XML output.
39  */
40 class XmlReportV2 : public XmlReport {
41 public:
42  explicit XmlReportV2(const QString &filename, QString productName);
43  ~XmlReportV2() override;
44 
45  /**
46  * @brief Create the report (file).
47  * @return true if succeeded, false if file could not be created.
48  */
49  bool create() override;
50 
51  /**
52  * @brief Open existing report file.
53  */
54  bool open() override;
55 
56  /**
57  * @brief Write report header.
58  */
59  void writeHeader() override;
60 
61  /**
62  * @brief Write report footer.
63  */
64  void writeFooter() override;
65 
66  /**
67  * @brief Write error to report.
68  * @param error Error data.
69  */
70  void writeError(const ErrorItem &error) override;
71 
72  /**
73  * @brief Read contents of the report file.
74  */
75  QList<ErrorItem> read() override;
76 
77 protected:
78  /**
79  * @brief Read and parse error item from XML stream.
80  * @param reader XML stream reader to use.
81  */
82  ErrorItem readError(const QXmlStreamReader *reader);
83 
84 private:
85  /** Product name read from cppcheck.cfg */
86  const QString mProductName;
87 
88  /**
89  * @brief XML stream reader for reading the report in XML format.
90  */
91  QXmlStreamReader *mXmlReader;
92 
93  /**
94  * @brief XML stream writer for writing the report in XML format.
95  */
96  QXmlStreamWriter *mXmlWriter;
97 };
98 /// @}
99 #endif // XML_REPORTV2_H
A class containing error data for one error.
Definition: erroritem.h:72
XML file report version 2.
Definition: xmlreportv2.h:40
const QString mProductName
Product name read from cppcheck.cfg.
Definition: xmlreportv2.h:86
ErrorItem readError(const QXmlStreamReader *reader)
Read and parse error item from XML stream.
void writeFooter() override
Write report footer.
QXmlStreamReader * mXmlReader
XML stream reader for reading the report in XML format.
Definition: xmlreportv2.h:91
void writeError(const ErrorItem &error) override
Write error to report.
XmlReportV2(const QString &filename, QString productName)
Definition: xmlreportv2.cpp:62
QXmlStreamWriter * mXmlWriter
XML stream writer for writing the report in XML format.
Definition: xmlreportv2.h:96
QList< ErrorItem > read() override
Read contents of the report file.
bool create() override
Create the report (file).
Definition: xmlreportv2.cpp:75
bool open() override
Open existing report file.
Definition: xmlreportv2.cpp:84
void writeHeader() override
Write report header.
Definition: xmlreportv2.cpp:93
~XmlReportV2() override
Definition: xmlreportv2.cpp:69
Base class for XML report classes.
Definition: xmlreport.h:36
@ error
Programming error.