8#include "../cpu_utc_clock.hpp"
9#include "../unfair_mutex.hpp"
10#include "../notifier.hpp"
11#include "../required.hpp"
34 using callback_type =
typename notifier_type::callback_type;
35 using callback_ptr_type =
typename notifier_type::callback_ptr_type;
53 ttlet lock = std::scoped_lock(_mutex);
54 return _previous_value;
61 ttlet lock = std::scoped_lock(_mutex);
62 return _last_modified;
79 tt_axiom(animation_duration.count() != 0);
91 [[nodiscard]]
virtual value_type
load() const noexcept = 0;
95 [[nodiscard]] value_type
load(duration animation_duration) const noexcept
108 virtual bool store(value_type
const &new_value)
noexcept = 0;
114 template<
typename Callback>
115 [[nodiscard]] callback_ptr_type
subscribe(Callback &&callback)
noexcept
117 return _notifier.subscribe(std::forward<Callback>(callback));
125 _notifier.unsubscribe(callback_ptr);
135 void notify(value_type
const &old_value, value_type
const &new_value)
noexcept
138 ttlet lock = std::scoped_lock(_mutex);
139 _previous_value = old_value;
140 _last_modified = cpu_utc_clock::now();
146 value_type _previous_value;
147 time_point _last_modified;
148 notifier_type _notifier;
Observable abstract base class.
Definition observable_base.hpp:30
void unsubscribe(callback_ptr_type callback_ptr) noexcept
Remove a callback.
Definition observable_base.hpp:123
virtual bool store(value_type const &new_value) noexcept=0
Set the value.
float animation_progress(duration animation_duration) const noexcept
The relative time since the start of the animation.
Definition observable_base.hpp:77
value_type previous_value() const noexcept
Get the previous value.
Definition observable_base.hpp:51
callback_ptr_type subscribe(Callback &&callback) noexcept
Add a callback as a listener.
Definition observable_base.hpp:115
virtual value_type load() const noexcept=0
Get the current value.
duration duration_since_last_modified() const noexcept
Duration since the value was last modified.
Definition observable_base.hpp:67
observable_base() noexcept
Constructor.
Definition observable_base.hpp:47
time_point time_when_last_modified() const noexcept
Time when the value was modified last.
Definition observable_base.hpp:59
An unfair mutex This is a fast implementation of a mutex which does not fairly arbitrate between mult...
Definition unfair_mutex.hpp:32