Loading...
Searching...
No Matches
ReferenceIndex.hpp
1#pragma once
2#include <State/Address.hpp>
3
4#include <LocalTree/ScriptableReference.hpp>
5
6#include <ossia/detail/hash_map.hpp>
7
8#include <QObject>
9#include <QPointer>
10#include <QTimer>
11
12#include <score_plugin_engine_export.h>
13
14#include <verdigris>
15
16#include <functional>
17#include <optional>
18#include <vector>
19
20namespace score
21{
22struct DocumentContext;
23}
24namespace LocalTree
25{
26class DocumentPlugin;
27
31class SCORE_PLUGIN_ENGINE_EXPORT ReferenceIndex final : public QObject
32{
33 W_OBJECT(ReferenceIndex)
34public:
35 explicit ReferenceIndex(DocumentPlugin& tree);
37
39 void add(QObject& referrer);
40
41 std::vector<QObject*> referrers(const QObject& target) const;
42 std::vector<QObject*> targets(const QObject& referrer) const;
43 struct Broken
44 {
45 ::State::Address address;
46 QObject* referrer{};
47 AddressStatus status{};
48 };
50 std::vector<Broken> broken() const;
52 void watchExplorer();
53
54 void refresh(const QObject& target);
56 void recover(const ::State::Address& published);
57 void unpublished(const QObject* target);
58
59 void changed() E_SIGNAL(SCORE_PLUGIN_ENGINE_EXPORT, changed)
60
61public:
62 using Mapping = std::function<std::optional<::State::AddressAccessor>(
63 const ::State::AddressAccessor&)>;
65 void rewrite(QObject& referrer, const Mapping& map);
66
67private:
68 void update(QObject& referrer);
69 void remove(QObject* referrer);
71 void notify(QObject* referrer);
73 void schedule();
74 void unlink(const QObject* target, QObject* referrer);
75 void unlinkAddress(const ::State::Address& address, QObject* referrer);
76 void unlinkDevice(const QString& device, QObject* referrer);
78 void explorerChanged(const QString& device);
80 void explorerDevicesChanged();
82 bool namesOther(const ::State::Address& a, const QObject* target) const;
83
84 struct Ref
85 {
86 ::State::Address address;
87 QPointer<QObject> target;
89 const QObject* key{};
90 bool anchored{};
91 bool local{};
93 bool misanchored{};
94 bool dangling() const noexcept { return local && !target; }
95 };
96 struct Entry
97 {
98 std::vector<Ref> refs;
99 };
100
101 DocumentPlugin& m_tree;
102 ossia::hash_map<QObject*, Entry> m_entries;
103 ossia::hash_map<const QObject*, std::vector<QObject*>> m_byTarget;
104 ossia::hash_set<const QObject*> m_watched;
106 ossia::hash_map<::State::Address, ossia::hash_set<QObject*>, std::hash<::State::Address>>
107 m_byAddress;
108 ossia::hash_map<QString, ossia::hash_set<QObject*>> m_byDevice;
109 ossia::hash_set<QString> m_changedDevices;
110 bool m_allDevicesChanged{};
111 bool m_missingDevicesChanged{};
112 QTimer m_explorerChanges;
113 ossia::hash_set<QObject*> m_pending;
114 bool m_pendingAll{};
115 bool m_scheduled{};
116};
117}
Definition LocalTreeDocumentPlugin.hpp:67
Definition ReferenceIndex.hpp:32
Local tree provides a way to extend the tree given through the Engine::Network::LocalDevice.
Definition BaseCallbackWrapper.hpp:9
AddressStatus
Definition ScriptableReference.hpp:151
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:35
Base toolkit upon which the software is built.
Definition Application.cpp:108
STL namespace.
Definition ReferenceIndex.hpp:44
The Address struct.
Definition Address.hpp:81