24 using callback_type =
typename notifier_type::callback_type;
25 using callback_ptr_type =
typename notifier_type::callback_ptr_type;
31 pimpl_callback = pimpl->subscribe([
this]() {
38 pimpl->unsubscribe(pimpl_callback);
40 pimpl_callback = pimpl->subscribe([
this]() {
68 observable &operator=(value_type
const &value)
noexcept
74 observable &operator+=(value_type
const &value)
noexcept
76 store(load() + value);
80 [[nodiscard]] value_type previous_value()
const noexcept
83 return pimpl->previous_value();
91 return pimpl->time_when_last_modified();
99 return pimpl->duration_since_last_modified();
111 return pimpl->animation_progress(animation_duration);
114 [[nodiscard]]
bool animating(duration animation_duration)
const noexcept
117 return pimpl->animation_progress(animation_duration) < 1.0f;
120 [[nodiscard]] value_type load() const noexcept
123 return pimpl->load();
126 [[nodiscard]] value_type operator*() const noexcept
129 return pimpl->load();
132 [[nodiscard]] value_type load(duration animation_duration)
const noexcept
135 return pimpl->load(animation_duration);
138 bool store(value_type
const &new_value)
noexcept
141 return pimpl->store(new_value);
144 template<
typename Callback>
145 [[nodiscard]] callback_ptr_type subscribe(Callback &&callback)
noexcept
147 return notifier.subscribe(std::forward<Callback>(callback));
150 void subscribe_ptr(callback_ptr_type
const &callback)
noexcept
152 return notifier.subscribe_ptr(callback);
155 void unsubscribe(callback_ptr_type
const &callback_ptr)
noexcept
157 return notifier.unsubscribe(callback_ptr);
160 [[nodiscard]]
friend observable<bool> operator!(observable
const &rhs)
noexcept
162 return std::static_pointer_cast<detail::observable_base<bool>>(std::make_shared<detail::observable_not<bool>>(rhs.pimpl));
165 [[nodiscard]]
friend bool operator==(observable
const &lhs, observable
const &rhs)
noexcept
170 [[nodiscard]]
friend bool operator==(observable
const &lhs, value_type
const &rhs)
noexcept
175 [[nodiscard]]
friend bool operator==(value_type
const &lhs, observable
const &rhs)
noexcept
180 [[nodiscard]]
friend bool operator!=(observable
const &lhs, observable
const &rhs)
noexcept
185 [[nodiscard]]
friend bool operator!=(observable
const &lhs, value_type
const &rhs)
noexcept
190 [[nodiscard]]
friend bool operator!=(value_type
const &lhs, observable
const &rhs)
noexcept
195 [[nodiscard]]
friend float to_float(observable
const &rhs)
noexcept
197 return narrow_cast<float>(rhs.load());
200 [[nodiscard]]
friend float to_float(observable
const &rhs, duration animation_duration)
noexcept
202 ttlet previous_value = narrow_cast<float>(rhs.previous_value());
203 ttlet current_value = narrow_cast<float>(rhs.load());
208 [[nodiscard]]
friend std::string to_string(observable
const &rhs)
noexcept
210 return to_string(rhs.load());
215 return lhs << rhs.load();
219 using pimpl_type = detail::observable_base<value_type>;
221 notifier_type notifier;
223 typename pimpl_type::callback_ptr_type pimpl_callback;
225 observable(
std::shared_ptr<detail::observable_base<value_type>>
const &other) noexcept : pimpl(other)
227 pimpl_callback = pimpl->subscribe([
this]() {
234 pimpl_callback = pimpl->subscribe([
this]() {
239 observable &operator=(
std::shared_ptr<detail::observable_base<value_type>>
const &other)
noexcept
241 pimpl->unsubscribe(pimpl_callback);
243 pimpl_callback = pimpl->subscribe([
this]() {
247 this->notifier(this->load());
float animation_progress(duration animation_duration) const noexcept
The relative time since the start of the animation.
Definition observable.hpp:108