// clang-format off // SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company // clang-format on // SPDX-FileContributor: Andrew Hayzen // // SPDX-License-Identifier: MIT OR Apache-2.0 #pragma once #include #include #include #include #include #include "rust/cxx.h" // Define namespace otherwise we hit a GCC bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480 namespace rust { // This has static asserts in the cpp file to ensure this is valid. template struct IsRelocatable> : ::std::true_type {}; } // namespace rust namespace rust { namespace cxxqtlib1 { namespace qhash { template ::rust::isize qhashLen(const QHash& h) noexcept; template V qhashGetOrDefault(const QHash& h, const K& key) noexcept { // Qt 6 returns a T and Qt 5 returns an const T // so we need to define our own method here for CXX return h.value(key); } template const K& qhashGetUncheckedKey(const QHash& h, ::rust::isize pos) noexcept { Q_ASSERT(pos < qhashLen(h)); Q_ASSERT(pos >= 0); auto it = h.cbegin(); ::std::advance(it, pos); return it.key(); } template const V& qhashGetUncheckedValue(const QHash& h, ::rust::isize pos) noexcept { Q_ASSERT(pos < qhashLen(h)); Q_ASSERT(pos >= 0); auto it = h.cbegin(); ::std::advance(it, pos); return it.value(); } template void qhashInsert(QHash& h, const K& key, const V& value) noexcept { h.insert(key, value); } template ::rust::isize qhashLen(const QHash& h) noexcept { // Qt 6 returns a qsizetype and Qt 5 returns an int return static_cast<::rust::isize>(h.size()); } template bool qhashRemove(QHash& h, const K& key) noexcept { // Qt 6 returns a bool and Qt 5 returns an int #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) return h.remove(key); #else return h.remove(key) >= 1; #endif } } } } using QHash_i32_QByteArray = QHash<::std::int32_t, QByteArray>; using QHash_QString_QVariant = QHash;