4#ifndef QRHIVALUEMAPPER_P_H
5#define QRHIVALUEMAPPER_P_H
18#include <QtMultimedia/qtmultimediaglobal.h>
19#include <QtMultimedia/private/qmultimedia_ranges_p.h>
21#include <qreadwritelock.h>
31
32
33
34
35
36class Q_MULTIMEDIA_EXPORT
QRhiCallback :
public std::enable_shared_from_this<QRhiCallback>
42 virtual ~QRhiCallback();
44 void registerCallback(QRhi &rhi);
47 virtual void onRhiCleanup(QRhi &rhi) = 0;
50 std::shared_ptr<Manager> m_manager;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68template <
typename Value>
71 struct Data : QRhiCallback
76 std::map<QRhi *, Value> storage;
78 void onRhiCleanup(QRhi &rhi) override
80 QWriteLocker locker(&lock);
99 std::pair<Value *,
bool>
tryMap(QRhi &rhi, V &&value)
101 QWriteLocker locker(&m_data->lock);
103 auto [rhiIt, rhiAdded] = m_data->storage.try_emplace(&rhi,
std::forward<V>(value));
106 m_data->registerCallback(rhi);
108 return { &rhiIt->second, rhiAdded };
111 Value *
get(QRhi *rhi)
const
113 QReadLocker locker(&m_data->lock);
114 auto rhiIt = m_data->storage.find(rhi);
115 return rhiIt == m_data->storage.end() ?
nullptr : &rhiIt->second;
132 QWriteLocker locker(&m_data->lock);
133 m_data->storage.clear();
136 template <
typename Predicate>
139 QReadLocker locker(&m_data->lock);
140 auto &storage = m_data->storage;
141 namespace ranges = QtMultimediaPrivate::ranges;
143 auto it = ranges::find_if(storage, [&](
auto &rhiItem) {
144 return p(*rhiItem.first);
146 return it == storage.end() ?
nullptr : it->first;
150 std::shared_ptr<Data> m_data;
void registerCallback(QRhi &rhi, const std::weak_ptr< QRhiCallback > &cb)
The QRhiCallback class implements a thread-safe wrapper around QRhi cleanup callbacks....
The class associates values of the specified type with different QRhi. One instance of QRhiValueMappe...
QRhiValueMapper & operator=(QRhiValueMapper &&) noexcept=default
QRhiValueMapper(QRhiValueMapper &&) noexcept=default
QRhi * findRhi(Predicate &&p) const
std::pair< Value *, bool > tryMap(QRhi &rhi, V &&value)
Value * get(QRhi *rhi) const
Combined button and popup list for selecting options.
Q_GLOBAL_STATIC(const QTzTimeZoneHash, tzZones, loadTzTimeZones())