source: trunk/qmake/cachekeys.h@ 362

Last change on this file since 362 was 362, checked in by Dmitry A. Kuminov, 15 years ago

qmake: Don't assume that relative paths in all OSes look like in *nix [vendor bug].

File size: 6.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the qmake application of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef CACHEKEYS_H
43#define CACHEKEYS_H
44
45#include "project.h"
46#include <qstring.h>
47#include <qstringlist.h>
48#include <qfile.h>
49#include <qfileinfo.h>
50#include <qdir.h>
51#include <qhash.h>
52
53QT_BEGIN_NAMESPACE
54
55// -------------------------------------------------------------------------------------------------
56struct FixStringCacheKey
57{
58 mutable uint hash;
59 QString string, pwd;
60 uchar flags;
61 FixStringCacheKey(const QString &s, uchar f)
62 {
63 hash = 0;
64 pwd = qmake_getpwd();
65 string = s;
66 flags = f;
67 }
68 bool operator==(const FixStringCacheKey &f) const
69 {
70 return (hashCode() == f.hashCode() &&
71 f.flags == flags &&
72 f.string == string &&
73 f.pwd == pwd);
74 }
75 inline uint hashCode() const {
76 if(!hash)
77 hash = qHash(string) | qHash(flags) /*| qHash(pwd)*/;
78 return hash;
79 }
80};
81inline uint qHash(const FixStringCacheKey &f) { return f.hashCode(); }
82
83// -------------------------------------------------------------------------------------------------
84struct FileInfoCacheKey
85{
86 mutable uint hash;
87 QString file, pwd;
88 FileInfoCacheKey(const QString &f)
89 {
90 hash = 0;
91 if(isRelativePath(f))
92 pwd = qmake_getpwd();
93 file = f;
94 }
95 bool operator==(const FileInfoCacheKey &f) const
96 {
97 return (hashCode() == f.hashCode() && f.file == file &&
98 f.pwd == pwd);
99 }
100 inline uint hashCode() const {
101 if(!hash)
102 hash = qHash(file) /*| qHash(pwd)*/;
103 return hash;
104 }
105 inline bool isRelativePath(const QString &file) {
106 int length = file.length();
107 if (!length)
108 return true;
109
110#ifdef Q_OS_OS2
111 return QDir::isRelativePath(file);
112#else
113 const QChar c0 = file.at(0);
114 const QChar c1 = length >= 2 ? file.at(1) : QChar(0);
115 return !(c0 == QLatin1Char('/')
116 || c0 == QLatin1Char('\\')
117 || (c0.isLetter() && c1 == QLatin1Char(':'))
118 || (c0 == QLatin1Char('/') && c1 == QLatin1Char('/'))
119 || (c0 == QLatin1Char('\\') && c1 == QLatin1Char('\\')));
120#endif
121 }
122};
123inline uint qHash(const FileInfoCacheKey &f) { return f.hashCode(); }
124
125// -------------------------------------------------------------------------------------------------
126struct FileFixifyCacheKey
127{
128 mutable uint hash;
129 QString in_d, out_d;
130 QString file, pwd;
131 uint fixType;
132 bool canonicalize;
133 FileFixifyCacheKey(const QString &f, const QString &od, const QString &id,
134 uint ft, bool c)
135 {
136 hash = 0;
137 pwd = qmake_getpwd();
138 file = f;
139 if(od.isNull())
140 out_d = Option::output_dir;
141 else
142 out_d = od;
143 if(id.isNull())
144 in_d = qmake_getpwd();
145 else
146 in_d = id;
147 fixType = ft;
148 canonicalize = c;
149 }
150 QString toString() const {
151 return file + "--" + in_d + "--" + out_d + "--" + pwd + "--" +
152 QString::number(fixType) + "--" + QString::number((int)canonicalize);
153 }
154 bool operator==(const FileFixifyCacheKey &f) const
155 {
156 return (f.canonicalize == canonicalize &&
157 f.fixType == fixType &&
158 f.file == file &&
159 f.in_d == in_d &&
160 f.out_d == out_d &&
161 f.pwd == pwd);
162 }
163 inline uint hashCode() const {
164 if(!hash)
165 hash = uint(canonicalize) | uint(fixType) |
166 qHash(file) | qHash(in_d) | qHash(out_d) /*|qHash(pwd)*/;
167 return hash;
168 }
169};
170
171inline uint qHash(const FileFixifyCacheKey &f) { return f.hashCode(); }
172// -------------------------------------------------------------------------------------------------
173
174// As MSVC 6.0 can't handle template functions that well, we need a separate function for each type
175inline void qmakeDeleteCacheClear_QMapStringInt(void *i) { delete reinterpret_cast<QMap<QString,int> *>(i); }
176inline void qmakeDeleteCacheClear_QStringList(void *i) { delete reinterpret_cast<QStringList *>(i); }
177inline void qmakeDeleteCacheClear_QHashFixStringCacheKeyQString(void *i) { delete reinterpret_cast<QHash<FixStringCacheKey, QString> *>(i); }
178inline void qmakeDeleteCacheClear_QHashFileInfoCacheKeyQFileInfo(void *i) { delete reinterpret_cast<QHash<FileInfoCacheKey, QFileInfo> *>(i); }
179inline void qmakeDeleteCacheClear_QHashFileFixifyCacheKeyQString(void *i) { delete reinterpret_cast<QHash<FileFixifyCacheKey, QString> *>(i); }
180inline void qmakeFreeCacheClear(void *i) { free(i); }
181
182typedef void (*qmakeCacheClearFunc)(void *);
183void qmakeAddCacheClear(qmakeCacheClearFunc func, void **);
184void qmakeClearCaches();
185
186QT_END_NAMESPACE
187
188#endif // CACHEKEYS_H
Note: See TracBrowser for help on using the repository browser.