Cppcheck
filelister.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 filelisterH
20 #define filelisterH
21 
22 #include <cstddef>
23 #include <list>
24 #include <set>
25 #include <string>
26 #include <utility>
27 
28 class PathMatch;
29 class FileWithDetails;
30 
31 /// @addtogroup CLI
32 /// @{
33 
34 /** @brief Cross-platform FileLister */
35 class FileLister {
36 public:
37  /**
38  * @brief Recursively add source files to a map.
39  * Add source files from given directory and all subdirectries to the
40  * given map. Only files with accepted extensions
41  * (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
42  * @param files output list that associates the size of each file with its name
43  * @param path root path
44  * @param ignored ignored paths
45  * @return On success, an empty string is returned. On error, a error message is returned.
46  */
47  static std::string recursiveAddFiles(std::list<FileWithDetails> &files, const std::string &path, const PathMatch& ignored) {
48  const std::set<std::string> extra;
49  return recursiveAddFiles(files, path, extra, ignored);
50  }
51 
52  /**
53  * @brief Recursively add source files to a map.
54  * Add source files from given directory and all subdirectries to the
55  * given map. Only files with accepted extensions
56  * (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
57  * @param files output list that associates the size of each file with its name
58  * @param path root path
59  * @param extra Extra file extensions
60  * @param ignored ignored paths
61  * @return On success, an empty string is returned. On error, a error message is returned.
62  */
63  static std::string recursiveAddFiles(std::list<FileWithDetails> &files, const std::string &path, const std::set<std::string> &extra, const PathMatch& ignored);
64 
65  /**
66  * @brief (Recursively) add source files to a map.
67  * Add source files from given directory and all subdirectries to the
68  * given map. Only files with accepted extensions
69  * (*.c;*.cpp;*.cxx;*.c++;*.cc;*.txx) are added.
70  * @param files output list that associates the size of each file with its name
71  * @param path root path
72  * @param extra Extra file extensions
73  * @param recursive Enable recursion
74  * @param ignored ignored paths
75  * @return On success, an empty string is returned. On error, a error message is returned.
76  */
77  static std::string addFiles(std::list<FileWithDetails> &files, const std::string &path, const std::set<std::string> &extra, bool recursive, const PathMatch& ignored);
78 };
79 
80 /// @}
81 
82 #endif // #ifndef filelisterH
Cross-platform FileLister.
Definition: filelister.h:35
static std::string recursiveAddFiles(std::list< FileWithDetails > &files, const std::string &path, const PathMatch &ignored)
Recursively add source files to a map.
Definition: filelister.h:47
static std::string addFiles(std::list< FileWithDetails > &files, const std::string &path, const std::set< std::string > &extra, bool recursive, const PathMatch &ignored)
(Recursively) add source files to a map.
Definition: filelister.cpp:246
Simple path matching for ignoring paths in CLI.
Definition: pathmatch.h:33