1// Copyright (C) 2016 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 CACHEKEYS_H
5#define CACHEKEYS_H
6
7#include "option.h"
8#include "project.h"
9#include <qstring.h>
10#include <qstringlist.h>
11#include <qfile.h>
12#include <qfileinfo.h>
13#include <qhash.h>
14
15QT_BEGIN_NAMESPACE
16
17// -------------------------------------------------------------------------------------------------
18struct FixStringCacheKey
19{
20 mutable size_t hash;
21 QString string, pwd;
22 uchar flags;
23 FixStringCacheKey(const QString &s, uchar f)
24 {
25 hash = 0;
26 pwd = qmake_getpwd();
27 string = s;
28 flags = f;
29 }
30 bool operator==(const FixStringCacheKey &f) const
31 {
32 return (hashCode() == f.hashCode() &&
33 f.flags == flags &&
34 f.string == string &&
35 f.pwd == pwd);
36 }
37 inline size_t hashCode() const {
38 if(!hash)
39 hash = qHash(key: string) ^ qHash(key: flags) /*^ qHash(pwd)*/;
40 return hash;
41 }
42};
43inline size_t qHash(const FixStringCacheKey &f) { return f.hashCode(); }
44
45// -------------------------------------------------------------------------------------------------
46struct FileInfoCacheKey
47{
48 mutable size_t hash;
49 QString file, pwd;
50 FileInfoCacheKey(const QString &f)
51 {
52 hash = 0;
53 if(isRelativePath(file: f))
54 pwd = qmake_getpwd();
55 file = f;
56 }
57 bool operator==(const FileInfoCacheKey &f) const
58 {
59 return (hashCode() == f.hashCode() && f.file == file &&
60 f.pwd == pwd);
61 }
62 inline size_t hashCode() const {
63 if(!hash)
64 hash = qHash(key: file) /*^ qHash(pwd)*/;
65 return hash;
66 }
67 inline bool isRelativePath(const QString &file) {
68 int length = file.size();
69 if (!length)
70 return true;
71
72 const QChar c0 = file.at(i: 0);
73 const QChar c1 = length >= 2 ? file.at(i: 1) : QChar::Null;
74 return !(c0 == QLatin1Char('/')
75 || c0 == QLatin1Char('\\')
76 || (c0.isLetter() && c1 == QLatin1Char(':'))
77 || (c0 == QLatin1Char('/') && c1 == QLatin1Char('/'))
78 || (c0 == QLatin1Char('\\') && c1 == QLatin1Char('\\')));
79 }
80};
81inline size_t qHash(const FileInfoCacheKey &f) { return f.hashCode(); }
82
83// -------------------------------------------------------------------------------------------------
84template <typename T>
85inline void qmakeDeleteCacheClear(void *i) { delete reinterpret_cast<T*>(i); }
86
87inline void qmakeFreeCacheClear(void *i) { free(ptr: i); }
88
89typedef void (*qmakeCacheClearFunc)(void *);
90void qmakeAddCacheClear(qmakeCacheClearFunc func, void **);
91void qmakeClearCaches();
92
93QT_END_NAMESPACE
94
95#endif // CACHEKEYS_H
96

source code of qtbase/qmake/cachekeys.h