ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
subscribe.hpp
1#pragma once
2
3#include <rpp/observables/details/member_overload.hpp>
4#include <rpp/subscribers/constraints.hpp>
5#include <rpp/subscribers/specific_subscriber.hpp>
6#include <rpp/subscriptions/composite_subscription.hpp>
7
8
9namespace rpp::details
10{
11struct subscribe_tag;
12
13
14template<constraint::decayed_type Type, typename SpecificObservable>
15struct member_overload<Type, SpecificObservable, subscribe_tag>
16{
22 template<constraint::subscriber_of_type<Type> TSub>
23 auto subscribe(TSub&& subscriber) const
24 {
25 return subscribe_impl(std::forward<TSub>(subscriber));
26 }
27
33 template<constraint::observer_of_type<Type> TObserver>
34 auto subscribe(TObserver&& observer) const
35 {
36 return subscribe_impl<std::decay_t<TObserver>>(std::forward<TObserver>(observer));
37 }
38
44 template<constraint::observer_of_type<Type> TObserver>
45 auto subscribe(composite_subscription sub, TObserver&& observer) const
46 {
47 return subscribe_impl(specific_subscriber<Type, std::decay_t<TObserver>>{std::move(sub), std::forward<TObserver>(observer)});
48 }
49
55 template<constraint::on_next_fn<Type> TOnNext = utils::empty_function_t<Type>,
56 constraint::on_error_fn TOnError = utils::rethrow_error_t,
57 constraint::on_completed_fn TOnCompleted = utils::empty_function_t<>>
58 auto subscribe(TOnNext&& on_next = {}, TOnError&& on_error = {}, TOnCompleted&& on_completed = {}) const
59 {
60 return subscribe_impl(make_specific_subscriber<Type>(std::forward<TOnNext>(on_next), std::forward<TOnError>(on_error), std::forward<TOnCompleted>(on_completed)));
61 }
62
68 template<constraint::on_next_fn<Type> TOnNext, constraint::on_completed_fn TOnCompleted>
69 auto subscribe(TOnNext&& on_next, TOnCompleted&& on_completed) const
70 {
71 return subscribe_impl(make_specific_subscriber<Type>(std::forward<TOnNext>(on_next), std::forward<TOnCompleted>(on_completed)));
72 }
73
79 template<constraint::on_next_fn<Type> TOnNext = utils::empty_function_t<Type>,
80 constraint::on_error_fn TOnError = utils::rethrow_error_t,
81 constraint::on_completed_fn TOnCompleted = utils::empty_function_t<>>
82 auto subscribe(composite_subscription sub, TOnNext&& on_next = {}, TOnError&& on_error = {}, TOnCompleted&& on_completed = {}) const
83 {
84 return subscribe_impl(make_specific_subscriber<Type>(std::move(sub), std::forward<TOnNext>(on_next), std::forward<TOnError>(on_error), std::forward<TOnCompleted>(on_completed)));
85 }
86
92 template<constraint::on_next_fn<Type> TOnNext,
93 constraint::on_completed_fn TOnCompleted>
94 auto subscribe(composite_subscription sub, TOnNext&& on_next, TOnCompleted&& on_completed) const
95 {
96 return subscribe_impl(make_specific_subscriber<Type>(std::move(sub), std::forward<TOnNext>(on_next), std::forward<TOnCompleted>(on_completed)));
97 }
98
99private:
100 template<constraint::observer_of_type<Type> Obs>
101 auto subscribe_impl(const specific_subscriber<Type, Obs>& subscriber) const
102 {
103 return static_cast<const SpecificObservable*>(this)->subscribe_impl(subscriber);
104 }
105};
106} // namespace rpp::details
rpp::subscription_base with ability to add some dependent subscriptions as a part of this one: in cas...
Definition: composite_subscription.hpp:30
specific version of subscriber which stores type of observer used inside to prevent extra allocations
Definition: specific_subscriber.hpp:31
auto subscribe(TOnNext &&on_next={}, TOnError &&on_error={}, TOnCompleted &&on_completed={}) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:58
auto subscribe(TSub &&subscriber) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:23
auto subscribe(composite_subscription sub, TOnNext &&on_next, TOnCompleted &&on_completed) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:94
auto subscribe(composite_subscription sub, TOnNext &&on_next={}, TOnError &&on_error={}, TOnCompleted &&on_completed={}) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:82
auto subscribe(TOnNext &&on_next, TOnCompleted &&on_completed) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:69
auto subscribe(TObserver &&observer) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:34
auto subscribe(composite_subscription sub, TObserver &&observer) const
Main function of observable. Initiates subscription for provided subscriber and calls stored OnSubscr...
Definition: subscribe.hpp:45
Definition: member_overload.hpp:19