36 pimpl_cbid = pimpl->add_callback([
this](ttlet &tmp) {
44 pimpl_cbid = pimpl->add_callback([
this](ttlet &tmp) {
50 pimpl->remove_callback(pimpl_cbid);
54 pimpl_cbid = pimpl->add_callback([
this](ttlet &tmp) {
65 pimpl_cbid = pimpl->add_callback([
this](ttlet &tmp) {
72 pimpl->remove_callback(pimpl_cbid);
74 pimpl_cbid = pimpl->add_callback([
this](ttlet &tmp) {
86 pimpl->remove_callback(pimpl_cbid);
99 template<
typename Other>
105 template<
typename Other>
115 observable &operator=(value_type
const &value)
noexcept {
120 template<
typename Other>
122 return *
this = std::static_pointer_cast<detail::observable_base<value_type>>(
123 std::make_shared<detail::observable_cast<value_type,Other>>(other.pimpl)
127 template<
typename Other>
128 observable &operator=(Other
const &other)
noexcept {
129 return *
this = std::static_pointer_cast<detail::observable_base<value_type>>(
130 std::make_shared<detail::observable_cast<value_type,Other>>(
131 std::make_shared<detail::observable_value<Other>>(other)
136 [[nodiscard]] value_type previous_value()
const noexcept {
138 return pimpl->previous_value();
145 return pimpl->time_when_last_modified();
152 return pimpl->duration_since_last_modified();
162 return pimpl->animation_progress(animation_duration);
165 [[nodiscard]]
bool animating(duration animation_duration)
const noexcept {
167 return pimpl->animation_progress(animation_duration) < 1.0f;
170 [[nodiscard]] value_type load() const noexcept {
172 return pimpl->load();
175 [[nodiscard]] value_type operator*() const noexcept {
177 return pimpl->load();
180 [[nodiscard]] value_type load(duration animation_duration)
const noexcept {
182 return pimpl->load(animation_duration);
185 bool store(value_type
const &new_value)
noexcept {
187 return pimpl->store(new_value);
190 [[nodiscard]]
size_t add_callback(callback_type callback)
noexcept {
191 return notifier.
add(callback);
194 void remove_callback(
size_t id)
noexcept {
195 return notifier.
remove(
id);
198 [[nodiscard]]
friend observable<bool> operator!(observable
const &rhs)
noexcept {
199 return std::static_pointer_cast<detail::observable_base<bool>>(
200 std::make_shared<detail::observable_not<bool>>(rhs.pimpl)
204 [[nodiscard]]
friend bool operator==(observable
const &lhs, observable
const &rhs)
noexcept {
208 [[nodiscard]]
friend bool operator==(observable
const &lhs, value_type
const &rhs)
noexcept {
212 [[nodiscard]]
friend bool operator==(value_type
const &lhs, observable
const &rhs)
noexcept {
216 [[nodiscard]]
friend bool operator!=(observable
const &lhs, observable
const &rhs)
noexcept {
220 [[nodiscard]]
friend bool operator!=(observable
const &lhs, value_type
const &rhs)
noexcept {
224 [[nodiscard]]
friend bool operator!=(value_type
const &lhs, observable
const &rhs)
noexcept {
228 [[nodiscard]]
friend float to_float(observable
const &rhs)
noexcept {
229 return numeric_cast<float>(rhs.load());
232 [[nodiscard]]
friend float to_float(observable
const &rhs, duration animation_duration)
noexcept {
233 ttlet previous_value = numeric_cast<float>(rhs.previous_value());
234 ttlet current_value = numeric_cast<float>(rhs.load());
239 [[nodiscard]]
friend std::string to_string(observable
const &rhs)
noexcept {
240 return to_string(rhs.load());
244 return lhs << rhs.load();
size_t add(callback_type callback) noexcept
Add a callback to the notifier.
Definition notifier.hpp:36
float animation_progress(duration animation_duration) const noexcept
The relative time since the start of the animation.
Definition observable.hpp:160