| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the qmake application of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #ifndef CACHEKEYS_H |
| 30 | #define CACHEKEYS_H |
| 31 | |
| 32 | #include "project.h" |
| 33 | #include <qstring.h> |
| 34 | #include <qstringlist.h> |
| 35 | #include <qfile.h> |
| 36 | #include <qfileinfo.h> |
| 37 | #include <qhash.h> |
| 38 | |
| 39 | QT_BEGIN_NAMESPACE |
| 40 | |
| 41 | // ------------------------------------------------------------------------------------------------- |
| 42 | struct FixStringCacheKey |
| 43 | { |
| 44 | mutable size_t hash; |
| 45 | QString string, pwd; |
| 46 | uchar flags; |
| 47 | FixStringCacheKey(const QString &s, uchar f) |
| 48 | { |
| 49 | hash = 0; |
| 50 | pwd = qmake_getpwd(); |
| 51 | string = s; |
| 52 | flags = f; |
| 53 | } |
| 54 | bool operator==(const FixStringCacheKey &f) const |
| 55 | { |
| 56 | return (hashCode() == f.hashCode() && |
| 57 | f.flags == flags && |
| 58 | f.string == string && |
| 59 | f.pwd == pwd); |
| 60 | } |
| 61 | inline size_t hashCode() const { |
| 62 | if(!hash) |
| 63 | hash = qHash(string) ^ qHash(flags) /*^ qHash(pwd)*/; |
| 64 | return hash; |
| 65 | } |
| 66 | }; |
| 67 | inline size_t qHash(const FixStringCacheKey &f) { return f.hashCode(); } |
| 68 | |
| 69 | // ------------------------------------------------------------------------------------------------- |
| 70 | struct FileInfoCacheKey |
| 71 | { |
| 72 | mutable size_t hash; |
| 73 | QString file, pwd; |
| 74 | FileInfoCacheKey(const QString &f) |
| 75 | { |
| 76 | hash = 0; |
| 77 | if(isRelativePath(f)) |
| 78 | pwd = qmake_getpwd(); |
| 79 | file = f; |
| 80 | } |
| 81 | bool operator==(const FileInfoCacheKey &f) const |
| 82 | { |
| 83 | return (hashCode() == f.hashCode() && f.file == file && |
| 84 | f.pwd == pwd); |
| 85 | } |
| 86 | inline size_t hashCode() const { |
| 87 | if(!hash) |
| 88 | hash = qHash(file) /*^ qHash(pwd)*/; |
| 89 | return hash; |
| 90 | } |
| 91 | inline bool isRelativePath(const QString &file) { |
| 92 | int length = file.length(); |
| 93 | if (!length) |
| 94 | return true; |
| 95 | |
| 96 | const QChar c0 = file.at(0); |
| 97 | const QChar c1 = length >= 2 ? file.at(1) : QChar::Null; |
| 98 | return !(c0 == QLatin1Char('/') |
| 99 | || c0 == QLatin1Char('\\') |
| 100 | || (c0.isLetter() && c1 == QLatin1Char(':')) |
| 101 | || (c0 == QLatin1Char('/') && c1 == QLatin1Char('/')) |
| 102 | || (c0 == QLatin1Char('\\') && c1 == QLatin1Char('\\'))); |
| 103 | } |
| 104 | }; |
| 105 | inline size_t qHash(const FileInfoCacheKey &f) { return f.hashCode(); } |
| 106 | |
| 107 | // ------------------------------------------------------------------------------------------------- |
| 108 | template <typename T> |
| 109 | inline void qmakeDeleteCacheClear(void *i) { delete reinterpret_cast<T*>(i); } |
| 110 | |
| 111 | inline void qmakeFreeCacheClear(void *i) { free(i); } |
| 112 | |
| 113 | typedef void (*qmakeCacheClearFunc)(void *); |
| 114 | void qmakeAddCacheClear(qmakeCacheClearFunc func, void **); |
| 115 | void qmakeClearCaches(); |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #endif // CACHEKEYS_H |
| 120 |