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/qreadwritelock.h> |
9 | #include <QtCore/qregularexpression.h> |
10 | #include <QtCore/qstringlist.h> |
11 | #include <QtCore/qvector.h> |
12 | |
13 | #include <string> |
14 | #include <unordered_map> |
15 | #include <vector> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class FileSignificanceCheck |
20 | { |
21 | public: |
22 | FileSignificanceCheck() = default; |
23 | |
24 | static void create() |
25 | { |
26 | m_instance = new FileSignificanceCheck; |
27 | } |
28 | |
29 | static void destroy() |
30 | { |
31 | delete m_instance; |
32 | m_instance = nullptr; |
33 | } |
34 | |
35 | static FileSignificanceCheck *the() |
36 | { |
37 | return m_instance; |
38 | } |
39 | |
40 | void setRootDirectories(const QStringList &paths); |
41 | void setExclusionRegExes(const QVector<QRegularExpression> &expressions); |
42 | |
43 | bool isFileSignificant(const std::string &filePath) const; |
44 | |
45 | private: |
46 | static FileSignificanceCheck *m_instance; |
47 | std::vector<QDir> m_rootDirs; |
48 | QVector<QRegularExpression> m_exclusionRegExes; |
49 | mutable std::unordered_map<std::string, bool> m_cache; |
50 | mutable QReadWriteLock m_cacheLock; |
51 | }; |
52 | |
53 | namespace LupdatePrivate { |
54 | |
55 | inline bool isFileSignificant(const std::string &filePath) |
56 | { |
57 | return FileSignificanceCheck::the()->isFileSignificant(filePath); |
58 | } |
59 | |
60 | } // namespace LupdatePrivate |
61 | |
62 | QT_END_NAMESPACE |
63 | |
64 | #endif // header guard |
65 |