12#include <rpp/disposables/fwd.hpp>
13#include <rpp/observers/fwd.hpp>
15#include <rpp/observers/observer.hpp>
20namespace rpp::details::observers
22 template<
typename Type>
26 void set_upstream(
const disposable_wrapper& d)
noexcept { m_vtable.set_upstream_ptr(
this, d); }
27 bool is_disposed()
const noexcept {
return m_vtable.is_disposed_ptr(
this); }
29 void on_next(
const Type& v)
const noexcept { m_vtable.on_next_lvalue_ptr(
this, v); }
30 void on_next(Type&& v)
const noexcept { m_vtable.on_next_rvalue_ptr(
this, std::move(v)); }
31 void on_error(
const std::exception_ptr& err)
const noexcept { m_vtable.on_error_ptr(
this, err); }
32 void on_completed()
const noexcept { m_vtable.on_completed_ptr(
this); }
37 void (*
const on_next_lvalue_ptr)(
const observer_vtable*,
const Type&){};
39 void (*
const on_error_ptr)(
const observer_vtable*,
const std::exception_ptr&){};
47 : m_vtable{std::move(vtable)}
51 const vtable_t m_vtable{};
54 template<rpp::constra
int::observer TObs>
57 using Type = rpp::utils::extract_observer_type_t<TObs>;
61 static constexpr const TObs& cast(
const Base* ptr)
66 static constexpr TObs& cast(
Base* ptr)
74 .on_next_lvalue_ptr = +[](
const Base* b,
const Type& v) { cast(b).on_next(v); },
75 .on_next_rvalue_ptr = +[](
const Base* b, Type&& v) { cast(b).on_next(std::move(v)); },
76 .on_error_ptr = +[](
const Base* b,
const std::exception_ptr& err) { cast(b).on_error(err); },
77 .on_completed_ptr = +[](
const Base* b) { cast(b).on_completed(); },
79 .is_disposed_ptr = +[](
const Base* b) {
80 return cast(b).is_disposed();
87 RPP_NO_UNIQUE_ADDRESS TObs m_observer;
90 template<rpp::constra
int::decayed_type Type>
94 static constexpr auto preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
96 template<rpp::constra
int::observer_strategy<Type> Strategy>
99 : m_observer{std::make_shared<type_erased_observer<observer<Type, Strategy>>>(std::move(obs))}
103 void set_upstream(
const disposable_wrapper& d)
noexcept { m_observer->set_upstream(d); }
104 bool is_disposed() const noexcept {
return m_observer->is_disposed(); }
106 void on_next(
const Type& v)
const noexcept { m_observer->on_next(v); }
107 void on_next(Type&& v)
const noexcept { m_observer->on_next(std::move(v)); }
108 void on_error(
const std::exception_ptr& err)
const noexcept { m_observer->on_error(err); }
109 void on_completed() const noexcept { m_observer->on_completed(); }
112 std::shared_ptr<observer_vtable<Type>> m_observer;
127 template<constra
int::decayed_type Type>
128 class dynamic_observer final :
public observer<Type, details::observers::dynamic_strategy<Type>>
130 using base = observer<Type, details::observers::dynamic_strategy<Type>>;
135 dynamic_observer(base&& b)
140 dynamic_observer(
const base& b)
Definition dynamic_observer.hpp:24
Definition dynamic_observer.hpp:56
Base class for any observer used in RPP. It handles core callbacks of observers. Objects of this clas...
Definition observer.hpp:172
Definition constraints.hpp:19
Definition dynamic_observer.hpp:36