HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
observable_unary.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "observable_base.hpp"
8
9namespace tt::detail {
10
11template<typename T, typename OT>
13public:
15
16 observable_unary(std::shared_ptr<operand_type> const &operand) noexcept :
18 _operand(operand),
19 _operand_cache(operand->load())
20 {
21 _operand_callback = _operand->subscribe([this]() {
22 ttlet old_value = this->load();
23 {
24 ttlet lock = std::scoped_lock(observable_base<T>::_mutex);
25 _operand_cache = _operand->load();
26 }
27 ttlet new_value = this->load();
28 observable_base<T>::notify(old_value, new_value);
29 });
30 }
31
32protected:
34 OT _operand_cache;
35 typename operand_type::callback_ptr_type _operand_callback;
36};
37
38}
Observable abstract base class.
Definition observable_base.hpp:30
virtual value_type load() const noexcept=0
Get the current value.
Definition observable_unary.hpp:12