diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 93f4ac0a57a..8fb7fcd47a7 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -191,7 +191,7 @@ FilePath FilePath::currentWorkingPath() bool FilePath::isRootPath() const { // FIXME: Make host-independent - return operator==(FilePath::fromString(QDir::rootPath())); + return *this == FilePath::fromString(QDir::rootPath()); } QString FilePath::encodedHost() const @@ -1003,43 +1003,6 @@ QVariant FilePath::toVariant() const return toString(); } -bool FilePath::operator==(const FilePath &other) const -{ - return pathView().compare(other.pathView(), caseSensitivity()) == 0 - && host() == other.host() - && scheme() == other.scheme(); -} - -bool FilePath::operator!=(const FilePath &other) const -{ - return !(*this == other); -} - -bool FilePath::operator<(const FilePath &other) const -{ - const int cmp = pathView().compare(other.pathView(), caseSensitivity()); - if (cmp != 0) - return cmp < 0; - if (host() != other.host()) - return host() < other.host(); - return scheme() < other.scheme(); -} - -bool FilePath::operator<=(const FilePath &other) const -{ - return !(other < *this); -} - -bool FilePath::operator>(const FilePath &other) const -{ - return other < *this; -} - -bool FilePath::operator>=(const FilePath &other) const -{ - return !(*this < other); -} - /*! \returns whether FilePath is a child of \a s */ @@ -1363,13 +1326,6 @@ FilePath FilePath::stringAppended(const QString &str) const return FilePath::fromString(toString() + str); } -size_t FilePath::hash(uint seed) const -{ - if (caseSensitivity() == Qt::CaseInsensitive) - return qHash(path().toCaseFolded(), seed); - return qHash(path(), seed); -} - QDateTime FilePath::lastModified() const { return fileAccess()->lastModified(*this); @@ -1984,20 +1940,53 @@ DeviceFileHooks &DeviceFileHooks::instance() return s_deviceHooks; } -} // namespace Utils - -std::hash::result_type - std::hash::operator()(const std::hash::argument_type &fn) const +QTCREATOR_UTILS_EXPORT bool operator==(const FilePath &first, const FilePath &second) { - if (fn.caseSensitivity() == Qt::CaseInsensitive) - return hash()(fn.toString().toCaseFolded().toStdString()); - return hash()(fn.toString().toStdString()); + return first.pathView().compare(second.pathView(), first.caseSensitivity()) == 0 + && first.host() == second.host() + && first.scheme() == second.scheme(); } -QT_BEGIN_NAMESPACE -QDebug operator<<(QDebug dbg, const Utils::FilePath &c) +QTCREATOR_UTILS_EXPORT bool operator!=(const FilePath &first, const FilePath &second) +{ + return !(first == second); +} + +QTCREATOR_UTILS_EXPORT bool operator<(const FilePath &first, const FilePath &second) +{ + const int cmp = first.pathView().compare(second.pathView(), first.caseSensitivity()); + if (cmp != 0) + return cmp < 0; + if (first.host() != second.host()) + return first.host() < second.host(); + return first.scheme() < second.scheme(); +} + +QTCREATOR_UTILS_EXPORT bool operator<=(const FilePath &first, const FilePath &second) +{ + return !(second < first); +} + +QTCREATOR_UTILS_EXPORT bool operator>(const FilePath &first, const FilePath &second) +{ + return second < first; +} + +QTCREATOR_UTILS_EXPORT bool operator>=(const FilePath &first, const FilePath &second) +{ + return !(first < second); +} + +QTCREATOR_UTILS_EXPORT size_t qHash(const FilePath &filePath, uint seed) +{ + if (filePath.caseSensitivity() == Qt::CaseInsensitive) + return qHash(filePath.path().toCaseFolded(), seed); + return qHash(filePath.path(), seed); +} + +QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const FilePath &c) { return dbg << c.toString(); } -QT_END_NAMESPACE +} // Utils diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index 3da33a00688..a3da61ce47a 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -132,12 +132,6 @@ public: expected_str writeFileContents(const QByteArray &data, qint64 offset = 0) const; FilePathInfo filePathInfo() const; - bool operator==(const FilePath &other) const; - bool operator!=(const FilePath &other) const; - bool operator<(const FilePath &other) const; - bool operator<=(const FilePath &other) const; - bool operator>(const FilePath &other) const; - bool operator>=(const FilePath &other) const; [[nodiscard]] FilePath operator/(const QString &str) const; Qt::CaseSensitivity caseSensitivity() const; @@ -147,8 +141,6 @@ public: void clear(); bool isEmpty() const; - size_t hash(uint seed) const; - [[nodiscard]] FilePath absoluteFilePath() const; [[nodiscard]] FilePath absolutePath() const; [[nodiscard]] FilePath resolvePath(const FilePath &tail) const; @@ -245,6 +237,20 @@ public: expected_str localSource() const; private: + // These are needed. + QTCREATOR_UTILS_EXPORT friend bool operator==(const FilePath &first, const FilePath &second); + QTCREATOR_UTILS_EXPORT friend bool operator!=(const FilePath &first, const FilePath &second); + QTCREATOR_UTILS_EXPORT friend bool operator<(const FilePath &first, const FilePath &second); + QTCREATOR_UTILS_EXPORT friend bool operator<=(const FilePath &first, const FilePath &second); + QTCREATOR_UTILS_EXPORT friend bool operator>(const FilePath &first, const FilePath &second); + QTCREATOR_UTILS_EXPORT friend bool operator>=(const FilePath &first, const FilePath &second); + + QTCREATOR_UTILS_EXPORT friend size_t qHash(const FilePath &a, uint seed); + QTCREATOR_UTILS_EXPORT friend size_t qHash(const FilePath &a) { return qHash(a, 0); } + + QTCREATOR_UTILS_EXPORT friend QDebug operator<<(QDebug dbg, const FilePath &c); + + // Implementation details. May change. friend class ::tst_fileutils; void setPath(QStringView path); void setFromString(QStringView filepath); @@ -258,11 +264,6 @@ private: unsigned short m_hostLen = 0; }; -inline size_t qHash(const Utils::FilePath &a, uint seed = 0) -{ - return a.hash(seed); -} - class QTCREATOR_UTILS_EXPORT DeviceFileHooks { public: @@ -276,21 +277,15 @@ public: std::function(const FilePath &)> localSource; }; -} // namespace Utils - -QT_BEGIN_NAMESPACE -QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Utils::FilePath &c); -QT_END_NAMESPACE +} // Utils Q_DECLARE_METATYPE(Utils::FilePath) namespace std { -template<> -struct QTCREATOR_UTILS_EXPORT hash + +template<> struct hash { - using argument_type = Utils::FilePath; - using result_type = size_t; - result_type operator()(const argument_type &fn) const; + size_t operator()(const Utils::FilePath &fn) const { return qHash(fn); } }; -} // namespace std +} // std diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.h b/src/plugins/cmakeprojectmanager/fileapidataextractor.h index 86adb15b01b..04f4ecea43f 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.h +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.h @@ -25,7 +25,7 @@ class CMakeFileInfo { public: bool operator==(const CMakeFileInfo& other) const { return path == other.path; } - friend auto qHash(const CMakeFileInfo &info, uint seed = 0) { return info.path.hash(seed); } + friend size_t qHash(const CMakeFileInfo &info, uint seed = 0) { return qHash(info.path, seed); } Utils::FilePath path; bool isCMake = false;