Cppcheck
filelist.h
Go to the documentation of this file.
00001 /*
00002  * Cppcheck - A tool for static C/C++ code analysis
00003  * Copyright (C) 2007-2013 Daniel Marjamäki and Cppcheck team.
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef FILELIST_H
00020 #define FILELIST_H
00021 
00022 #include <QFileInfoList>
00023 #include <QStringList>
00024 
00025 /**
00026  * @brief A class for listing files and directories to check.
00027  * This class creates a list of files to check. If directory name is given then
00028  * all files in the directory matching the filter will be added. The directory
00029  * can be also added recursively when all files in subdirectories are added too.
00030  * The filenames are matched against the filter and only those files whose
00031  * filename extension is included in the filter list are added.
00032  *
00033  * This class also handles filtering of paths against ignore filters given. If
00034  * there is ignore filters then only paths not matching those filters are
00035  * returned.
00036  */
00037 class FileList {
00038 public:
00039 
00040     /**
00041     * @brief Add filename to the list.
00042     * @param filepath Full path to the file.
00043     */
00044     void AddFile(const QString &filepath);
00045 
00046     /**
00047     * @brief Add files in the directory to the list.
00048     * @param directory Full pathname to directory to add.
00049     * @param recursive If true also files in subdirectories are added.
00050     */
00051     void AddDirectory(const QString &directory, bool recursive = false);
00052 
00053     /**
00054     * @brief Add list of filenames and directories to the list.
00055     * @param paths List of paths to add.
00056     */
00057     void AddPathList(const QStringList &paths);
00058 
00059     /**
00060     * @brief Return list of filenames (to check).
00061     * @return list of filenames to check.
00062     */
00063     QStringList GetFileList() const;
00064 
00065     /**
00066     * @brief Add list of paths to exclusion list.
00067     * @param paths Paths to exclude.
00068     */
00069     void AddExcludeList(const QStringList &paths);
00070 
00071 protected:
00072 
00073     /**
00074     * @brief Return list of default filename extensions included.
00075     * @return list of default filename extensions included.
00076     */
00077     static QStringList GetDefaultFilters();
00078 
00079     /**
00080     * @brief Test if filename matches the filename extensions filtering.
00081     * @return true if filename matches filtering.
00082     */
00083     static bool FilterMatches(const QFileInfo &inf);
00084 
00085     /**
00086     * @brief Get filtered list of paths.
00087     * This method takes the list of paths and applies the exclude lists to
00088     * it. And then returns the list of paths that did not match the
00089     * exclude filters.
00090     * @return Filtered list of paths.
00091     */
00092     QStringList ApplyExcludeList() const;
00093 
00094     /**
00095     * @brief Test if path matches any of the exclude filters.
00096     * @param path Path to test against exclude filters.
00097     * @return true if any of the filters matches, false otherwise.
00098     */
00099     bool Match(const QString &path) const;
00100 
00101 private:
00102     QFileInfoList mFileList;
00103     QStringList mExcludedPaths;
00104 };
00105 
00106 #endif // FILELIST_H