HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
TTauri
Foundation
detail
observable_unary.hpp
1
// Copyright 2020 Pokitec
2
// All rights reserved.
3
4
#pragma once
5
6
#include "observable_base.hpp"
7
8
namespace
tt::detail {
9
10
template
<
typename
T,
typename
OT>
11
class
observable_unary
:
public
observable_base
<T> {
12
protected
:
13
std::shared_ptr<observable_base<OT>
> operand;
14
OT operand_cache;
15
size_t
operand_cb_id;
16
17
public
:
18
observable_unary
(
std::shared_ptr
<
observable_base<OT>
>
const
&operand) noexcept :
19
observable_base<T>
(),
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
34
~observable_unary
() {
35
operand->remove_callback(operand_cb_id);
36
}
37
};
38
39
}
tt::detail::observable_base
Observable abstract base class.
Definition
observable_base.hpp:29
tt::detail::observable_base::load
virtual T load() const noexcept=0
Get the current value.
tt::detail::observable_unary
Definition
observable_unary.hpp:11
std::shared_ptr
Generated on Mon Apr 22 2024 12:53:56 for HikoGUI by
1.10.0