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&){};
38 void (*
const on_next_rvalue_ptr)(
const observer_vtable*, Type&&){};
39 void (*
const on_error_ptr)(
const observer_vtable*,
const std::exception_ptr&){};
40 void (*
const on_completed_ptr)(
const observer_vtable*){};
43 bool (*
const is_disposed_ptr)(
const observer_vtable*){};
47 : m_vtable{std::move(vtable)}
51 const vtable_t m_vtable{};
55 class type_erased_observer :
public observer_vtable<rpp::utils::extract_observer_type_t<TObs>>
57 using Type = rpp::utils::extract_observer_type_t<TObs>;
58 using Base = observer_vtable<Type>;
61 static constexpr const TObs& cast(
const Base* ptr)
63 return static_cast<const type_erased_observer*
>(ptr)->m_observer;
66 static constexpr TObs& cast(Base* ptr)
68 return static_cast<type_erased_observer*
>(ptr)->m_observer;
72 type_erased_observer(TObs&&
observer)
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;
91 class dynamic_strategy final
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;