12#include <rpp/observables/fwd.hpp>
13#include <rpp/subjects/fwd.hpp>
15#include <rpp/observables/observable.hpp>
16#include <rpp/observers/dynamic_observer.hpp>
21namespace rpp::details::observables
23 template<
typename T,
typename Observable>
24 void forwarding_subscribe(
const void*
const ptr, dynamic_observer<T>&& obs)
26 static_cast<const Observable*
>(ptr)->
subscribe(std::move(obs));
29 template<rpp::constra
int::decayed_type Type>
30 class dynamic_strategy final
33 using value_type = Type;
36 template<rpp::constra
int::observable_strategy<Type> Strategy>
38 explicit dynamic_strategy(observable<Type, Strategy>&& obs)
39 : m_forwarder{std::make_shared<observable<Type, Strategy>>(std::move(obs))}
40 , m_vtable{vtable::template create<observable<Type, Strategy>>()}
44 template<rpp::constra
int::observable_strategy<Type> Strategy>
46 explicit dynamic_strategy(
const observable<Type, Strategy>& obs)
47 : m_forwarder{std::make_shared<observable<Type, Strategy>>(obs)}
48 , m_vtable{vtable::template create<observable<Type, Strategy>>()}
52 template<rpp::constra
int::observer_strategy<Type> ObserverStrategy>
53 void subscribe(observer<Type, ObserverStrategy>&& observer)
const
55 m_vtable->subscribe(m_forwarder.get(), std::move(observer).as_dynamic());
61 void (*subscribe)(
const void*, dynamic_observer<Type>&&){};
63 template<rpp::constra
int::observable Observable>
64 static const vtable* create() noexcept
67 .subscribe = forwarding_subscribe<Type, Observable>};
73 std::shared_ptr<void> m_forwarder;
74 const vtable* m_vtable;
88 template<constra
int::decayed_type Type>
89 class dynamic_observable :
public observable<Type, details::observables::dynamic_strategy<Type>>
91 using base = observable<Type, details::observables::dynamic_strategy<Type>>;
96 dynamic_observable(base&& b)
101 dynamic_observable(
const base& b)
107 template<
typename Subject>
108 using dynamic_connectable_observable = connectable_observable<rpp::dynamic_observable<rpp::subjects::utils::extract_subject_type_t<Subject>>, Subject>;
Definition constraints.hpp:19
auto subscribe(observer< Type, ObserverStrategy > &&observer)
Subscribes passed observer to emissions from this observable.
Definition subscribe.hpp:226
Definition disposables_strategy.hpp:19