7#include "TTauri/Foundation/cpu_utc_clock.hpp"
8#include "TTauri/Foundation/fast_mutex.hpp"
9#include "TTauri/Foundation/notifier.hpp"
10#include "TTauri/Foundation/required.hpp"
40 time_point _last_modified;
53 _previous_value(), _last_modified(),
notifier() {}
58 ttlet lock = std::scoped_lock(mutex);
59 return _previous_value;
65 ttlet lock = std::scoped_lock(mutex);
66 return _last_modified;
81 tt_assume(animation_duration.count() != 0);
94 [[nodiscard]]
virtual T
load() const noexcept = 0;
98 [[nodiscard]] T
load(duration animation_duration) const noexcept {
110 virtual bool store(T
const &new_value)
noexcept = 0;
133 void notify(T
const &old_value, T
const &new_value)
noexcept {
135 ttlet lock = std::scoped_lock(mutex);
136 _previous_value = old_value;
137 _last_modified = cpu_utc_clock::now();
Observable abstract base class.
Definition observable_base.hpp:29
virtual T load() const noexcept=0
Get the current value.
float animation_progress(duration animation_duration) const noexcept
The relative time since the start of the animation.
Definition observable_base.hpp:80
virtual bool store(T const &new_value) noexcept=0
Set the value.
size_t add_callback(callback_type callback) noexcept
Add a callback as a listener.
Definition observable_base.hpp:116
void remove_callback(size_t id) noexcept
Remove a callback.
Definition observable_base.hpp:123
T previous_value() const noexcept
Get the previous value.
Definition observable_base.hpp:57
duration duration_since_last_modified() const noexcept
Duration since the value was last modified.
Definition observable_base.hpp:71
observable_base() noexcept
Constructor.
Definition observable_base.hpp:52
time_point time_when_last_modified() const noexcept
Time when the value was modified last.
Definition observable_base.hpp:64
Definition fast_mutex.hpp:14
A notifier which can be used to call a set of registred callbacks.
Definition notifier.hpp:21
void remove(size_t id) noexcept
Remove a callback from the notifier.
Definition notifier.hpp:65
size_t add(callback_type callback) noexcept
Add a callback to the notifier.
Definition notifier.hpp:36