5 #if !defined(RXCPP_SOURCES_RX_SCOPE_HPP) 6 #define RXCPP_SOURCES_RX_SCOPE_HPP 8 #include "../rx-includes.hpp" 33 template<
class ResourceFactory,
class ObservableFactory>
36 typedef rxu::decay_t<ResourceFactory> resource_factory_type;
37 typedef rxu::decay_t<ObservableFactory> observable_factory_type;
38 typedef decltype((*(resource_factory_type*)
nullptr)()) resource_type;
39 typedef decltype((*(observable_factory_type*)
nullptr)(resource_type())) collection_type;
40 typedef typename collection_type::value_type value_type;
45 template<
class ResourceFactory,
class ObservableFactory>
46 struct scope :
public source_base<rxu::value_type_t<scope_traits<ResourceFactory, ObservableFactory>>>
48 typedef scope_traits<ResourceFactory, ObservableFactory> traits;
49 typedef typename traits::resource_factory_type resource_factory_type;
50 typedef typename traits::observable_factory_type observable_factory_type;
51 typedef typename traits::resource_type resource_type;
52 typedef typename traits::value_type value_type;
56 values(resource_factory_type rf, observable_factory_type of)
57 : resource_factory(std::move(rf))
58 , observable_factory(std::move(of))
61 resource_factory_type resource_factory;
62 observable_factory_type observable_factory;
67 scope(resource_factory_type rf, observable_factory_type of)
68 : initial(std::move(rf), std::move(of))
72 template<
class Subscriber>
73 void on_subscribe(Subscriber o)
const {
76 :
public std::enable_shared_from_this<state_type>
79 state_type(values i, Subscriber o)
85 rxu::detail::maybe<resource_type> resource;
88 auto state = std::make_shared<state_type>(state_type(initial, std::move(o)));
91 [&](){
return state->resource_factory(); },
93 if (state->resource.empty()) {
96 state->out.add(state->resource->get_subscription());
99 [state](){
return state->observable_factory(state->resource.get()); },
101 if (selectedCollection.empty()) {
105 selectedCollection->subscribe(state->out);
113 template<
class ResourceFactory,
class ObservableFactory>
114 auto scope(ResourceFactory rf, ObservableFactory of)
117 detail::scope<ResourceFactory, ObservableFactory>(std::move(rf), std::move(of)));
Definition: rx-all.hpp:26
a source of values. subscribe or use one of the operator methods that return a new observable...
Definition: rx-observable.hpp:510
auto scope(ResourceFactory rf, ObservableFactory of) -> observable< rxu::value_type_t< detail::scope_traits< ResourceFactory, ObservableFactory >>, detail::scope< ResourceFactory, ObservableFactory >>
Returns an observable that makes an observable by the specified observable factory using the resource...
Definition: rx-scope.hpp:114
auto on_exception(const F &f, const OnError &c) -> typename std::enable_if< detail::is_on_error< OnError >::value, typename detail::maybe_from_result< F >::type >::type
Definition: rx-observer.hpp:639
static const bool value
Definition: rx-subscription.hpp:38