1 | // Copyright (C) 2022 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef FILESIGNIFICANCECHECK_H |
5 | #define FILESIGNIFICANCECHECK_H |
6 | |
7 | #include <QtCore/qdir.h> |
8 | #include <QtCore/qregularexpression.h> |
9 | #include <QtCore/qstringlist.h> |
10 | |
11 | #include <shared_mutex> |
12 | #include <string> |
13 | #include <unordered_map> |
14 | #include <vector> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class FileSignificanceCheck |
19 | { |
20 | public: |
21 | FileSignificanceCheck() = default; |
22 | |
23 | static void create() |
24 | { |
25 | m_instance = new FileSignificanceCheck; |
26 | } |
27 | |
28 | static void destroy() |
29 | { |
30 | delete m_instance; |
31 | m_instance = nullptr; |
32 | } |
33 | |
34 | static FileSignificanceCheck *the() |
35 | { |
36 | return m_instance; |
37 | } |
38 | |
39 | void setRootDirectories(const QStringList &paths); |
40 | void setExclusionPatterns(const QStringList &patterns); |
41 | |
42 | bool isFileSignificant(const std::string &filePath) const; |
43 | |
44 | private: |
45 | static FileSignificanceCheck *m_instance; |
46 | std::vector<QDir> m_rootDirs; |
47 | std::vector<QRegularExpression> m_exclusionRegExes; |
48 | mutable std::unordered_map<std::string, bool> m_cache; |
49 | mutable std::shared_mutex m_cacheMutex; |
50 | }; |
51 | |
52 | namespace LupdatePrivate { |
53 | |
54 | inline bool isFileSignificant(const std::string &filePath) |
55 | { |
56 | return FileSignificanceCheck::the()->isFileSignificant(filePath); |
57 | } |
58 | |
59 | } // namespace LupdatePrivate |
60 | |
61 | QT_END_NAMESPACE |
62 | |
63 | #endif // header guard |
64 |