Cppcheck
executor.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 EXECUTOR_H
20 #define EXECUTOR_H
21 
22 #include <cstddef>
23 #include <list>
24 #include <mutex>
25 #include <string>
26 #include <unordered_set>
27 #include <utility>
28 
29 class Settings;
30 class ErrorLogger;
31 class ErrorMessage;
32 class SuppressionList;
33 struct FileSettings;
34 class FileWithDetails;
35 
36 /// @addtogroup CLI
37 /// @{
38 
39 /**
40  * This class will take a list of filenames and settings and check then
41  * all files using threads.
42  */
43 class Executor {
44 public:
45  Executor(const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger);
46  virtual ~Executor() = default;
47 
48  Executor(const Executor &) = delete;
49  Executor& operator=(const Executor &) = delete;
50 
51  virtual unsigned int check() = 0;
52 
53  /**
54  * Information about how many files have been checked
55  *
56  * @param fileindex This many files have been checked.
57  * @param filecount This many files there are in total.
58  * @param sizedone The sum of sizes of the files checked.
59  * @param sizetotal The total sizes of the files.
60  */
61  void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal);
62 
63 protected:
64  /**
65  * @brief Check if message is being suppressed and unique.
66  * @param msg the message to check
67  * @return true if message is not suppressed and unique
68  */
69  bool hasToLog(const ErrorMessage &msg);
70 
71  const std::list<FileWithDetails> &mFiles;
72  const std::list<FileSettings>& mFileSettings;
76 
77 private:
78  std::mutex mErrorListSync;
79  // TODO: store hashes instead of the full messages
80  std::unordered_set<std::string> mErrorList;
81 };
82 
83 /// @}
84 
85 #endif // EXECUTOR_H
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
Wrapper for error messages, provided by reportErr()
Definition: errorlogger.h:48
This class will take a list of filenames and settings and check then all files using threads.
Definition: executor.h:43
bool hasToLog(const ErrorMessage &msg)
Check if message is being suppressed and unique.
Definition: executor.cpp:41
std::unordered_set< std::string > mErrorList
Definition: executor.h:80
Executor(const std::list< FileWithDetails > &files, const std::list< FileSettings > &fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
Definition: executor.cpp:33
const std::list< FileSettings > & mFileSettings
Definition: executor.h:72
Executor & operator=(const Executor &)=delete
virtual ~Executor()=default
SuppressionList & mSuppressions
Definition: executor.h:74
const std::list< FileWithDetails > & mFiles
Definition: executor.h:71
std::mutex mErrorListSync
Definition: executor.h:78
Executor(const Executor &)=delete
void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal)
Information about how many files have been checked.
Definition: executor.cpp:61
ErrorLogger & mErrorLogger
Definition: executor.h:75
virtual unsigned int check()=0
const Settings & mSettings
Definition: executor.h:73
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
class for handling suppressions
Definition: suppressions.h:42
File settings.
Definition: filesettings.h:57