File indexing completed on 2024-05-12 15:59:51
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KisResourcesInterface_P_H 0007 #define KisResourcesInterface_P_H 0008 0009 #include "kritaresources_export.h" 0010 #include "KisResourcesInterface.h" 0011 #include <unordered_map> 0012 #include <memory> 0013 0014 #include <QReadWriteLock> 0015 #include <QReadLocker> 0016 #include <QWriteLocker> 0017 0018 #include "kis_assert.h" 0019 0020 /// added to Qt in 5.14.0 0021 /// https://codereview.qt-project.org/c/qt/qtbase/+/261819 0022 0023 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) 0024 namespace std 0025 { 0026 template<> struct hash<QString> 0027 { 0028 std::size_t operator()(const QString &s) const noexcept { 0029 return qHash(s); 0030 } 0031 }; 0032 } 0033 #endif 0034 0035 class KRITARESOURCES_EXPORT KisResourcesInterfacePrivate 0036 { 0037 public: 0038 mutable std::unordered_map<QString, 0039 std::unique_ptr< 0040 KisResourcesInterface::ResourceSourceAdapter>> sourceAdapters; 0041 mutable QReadWriteLock lock; 0042 0043 KisResourcesInterface::ResourceSourceAdapter* findExistingSource(const QString &type) const { 0044 auto it = this->sourceAdapters.find(type); 0045 if (it != this->sourceAdapters.end()) { 0046 KIS_ASSERT(bool(it->second)); 0047 0048 return it->second.get(); 0049 } 0050 0051 return nullptr; 0052 } 0053 0054 virtual ~KisResourcesInterfacePrivate() {} 0055 }; 0056 0057 #endif // KisResourcesInterface_P_H