forked from khuldraeseth/eecs281-lab07-verifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProbeListener.hpp
35 lines (25 loc) · 932 Bytes
/
ProbeListener.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <functional>
#include <unordered_set>
template <typename K>
class NotifyingKey;
template <typename K>
class ProbeListener {
public:
virtual auto notify(NotifyingKey<K> const& key) -> void = 0;
virtual auto finalize() const -> void = 0;
auto addSubscriber(NotifyingKey<K>& key) -> void { subscribers.insert(&key); }
auto removeSubscriber(NotifyingKey<K>& key) -> void { subscribers.erase(&key); }
ProbeListener() = default;
ProbeListener(ProbeListener const&) = default;
ProbeListener(ProbeListener&&) noexcept = default;
auto operator=(ProbeListener const&) -> ProbeListener& = default;
auto operator=(ProbeListener&&) noexcept -> ProbeListener& = default;
virtual ~ProbeListener() {
for (auto subscriber : subscribers) {
subscriber->unsafeUnsubscribe();
}
}
private:
std::unordered_set<NotifyingKey<K>*> subscribers {};
};