HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
observable_unary.hpp
1// Copyright 2020 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "observable_base.hpp"
7
8namespace tt::detail {
9
10template<typename T, typename OT>
12protected:
14 OT operand_cache;
15 size_t operand_cb_id;
16
17public:
18 observable_unary(std::shared_ptr<observable_base<OT>> const &operand) noexcept :
20 operand(operand),
21 operand_cache(operand->load())
22 {
23 operand_cb_id = this->operand->add_callback([this](OT const &value) {
24 ttlet old_value = this->load();
25 {
26 ttlet lock = std::scoped_lock(observable_base<T>::mutex);
27 operand_cache = value;
28 }
29 ttlet new_value = this->load();
30 observable_base<T>::notify(old_value, new_value);
31 });
32 }
33
35 operand->remove_callback(operand_cb_id);
36 }
37};
38
39}
Observable abstract base class.
Definition observable_base.hpp:29
virtual T load() const noexcept=0
Get the current value.
Definition observable_unary.hpp:11