RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
rx-publish.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2 
3 #pragma once
4 
26 #if !defined(RXCPP_OPERATORS_RX_PUBLISH_HPP)
27 #define RXCPP_OPERATORS_RX_PUBLISH_HPP
28 
29 #include "../rx-includes.hpp"
30 #include "./rx-multicast.hpp"
31 
32 namespace rxcpp {
33 
34 namespace operators {
35 
36 namespace detail {
37 
38 template<class... AN>
39 struct publish_invalid_arguments {};
40 
41 template<class... AN>
42 struct publish_invalid : public rxo::operator_base<publish_invalid_arguments<AN...>> {
43  using type = observable<publish_invalid_arguments<AN...>, publish_invalid<AN...>>;
44 };
45 template<class... AN>
46 using publish_invalid_t = typename publish_invalid<AN...>::type;
47 
48 }
49 
52 template<class... AN>
53 auto publish(AN&&... an)
55  return operator_factory<publish_tag, AN...>(std::make_tuple(std::forward<AN>(an)...));
56 }
57 
71 template<class... AN>
72 auto publish_synchronized(AN&&... an)
74  return operator_factory<publish_synchronized_tag, AN...>(std::make_tuple(std::forward<AN>(an)...));
75 }
76 
77 }
78 
79 template<>
81 {
82  template<class Observable,
83  class Enabled = rxu::enable_if_all_true_type_t<
85  class SourceValue = rxu::value_type_t<Observable>,
86  class Subject = rxsub::subject<SourceValue>,
87  class Multicast = rxo::detail::multicast<SourceValue, rxu::decay_t<Observable>, Subject>,
89  >
90  static Result member(Observable&& o) {
91  return Result(Multicast(std::forward<Observable>(o), Subject(composite_subscription())));
92  }
93 
94  template<class Observable,
95  class Enabled = rxu::enable_if_all_true_type_t<
96  is_observable<Observable>>,
97  class SourceValue = rxu::value_type_t<Observable>,
98  class Subject = rxsub::subject<SourceValue>,
99  class Multicast = rxo::detail::multicast<SourceValue, rxu::decay_t<Observable>, Subject>,
101  >
102  static Result member(Observable&& o, composite_subscription cs) {
103  return Result(Multicast(std::forward<Observable>(o), Subject(cs)));
104  }
105 
106  template<class Observable, class T,
107  class Enabled = rxu::enable_if_all_true_type_t<
108  is_observable<Observable>>,
109  class SourceValue = rxu::value_type_t<Observable>,
110  class Subject = rxsub::behavior<SourceValue>,
111  class Multicast = rxo::detail::multicast<SourceValue, rxu::decay_t<Observable>, Subject>,
113  >
114  static Result member(Observable&& o, T first, composite_subscription cs = composite_subscription()) {
115  return Result(Multicast(std::forward<Observable>(o), Subject(first, cs)));
116  }
117 
118  template<class... AN>
119  static operators::detail::publish_invalid_t<AN...> member(AN...) {
120  std::terminate();
121  return {};
122  static_assert(sizeof...(AN) == 10000, "publish takes (optional CompositeSubscription) or (T, optional CompositeSubscription)");
123  }
124 };
125 
126 template<>
128 {
129  template<class Observable, class Coordination,
130  class Enabled = rxu::enable_if_all_true_type_t<
131  is_observable<Observable>,
133  class SourceValue = rxu::value_type_t<Observable>,
135  class Multicast = rxo::detail::multicast<SourceValue, rxu::decay_t<Observable>, Subject>,
137  >
138  static Result member(Observable&& o, Coordination&& cn, composite_subscription cs = composite_subscription()) {
139  return Result(Multicast(std::forward<Observable>(o), Subject(std::forward<Coordination>(cn), cs)));
140  }
141 
142  template<class... AN>
143  static operators::detail::publish_invalid_t<AN...> member(AN...) {
144  std::terminate();
145  return {};
146  static_assert(sizeof...(AN) == 10000, "publish_synchronized takes (Coordination, optional CompositeSubscription)");
147  }
148 };
149 
150 }
151 
152 #endif
auto publish_synchronized(AN &&...an) -> operator_factory< publish_synchronized_tag, AN... >
Turn a cold observable hot and allow connections to the source to be independent of subscriptions...
Definition: rx-publish.hpp:72
Definition: rx-behavior.hpp:70
a source of values that is shared across all subscribers and does not start until connectable_observa...
Definition: rx-connectable_observable.hpp:105
Definition: rx-all.hpp:26
typename std::decay< T >::type::value_type value_type_t
Definition: rx-util.hpp:35
Definition: rx-operators.hpp:323
controls lifetime for scheduler::schedule and observable<T, SourceOperator>::subscribe.
Definition: rx-subscription.hpp:364
Definition: rx-subject.hpp:237
Definition: rx-operators.hpp:69
static operators::detail::publish_invalid_t< AN... > member(AN...)
Definition: rx-publish.hpp:119
static operators::detail::publish_invalid_t< AN... > member(AN...)
Definition: rx-publish.hpp:143
static Result member(Observable &&o)
Definition: rx-publish.hpp:90
auto AN
Definition: rx-finally.hpp:105
Definition: rx-operators.hpp:47
static Result member(Observable &&o, Coordination &&cn, composite_subscription cs=composite_subscription())
Definition: rx-publish.hpp:138
auto publish(AN &&...an) -> operator_factory< publish_tag, AN... >
Turn a cold observable hot and allow connections to the source to be independent of subscriptions...
Definition: rx-publish.hpp:53
typename std::enable_if< all_true_type< BN... >::value >::type enable_if_all_true_type_t
Definition: rx-util.hpp:114
auto first() -> operator_factory< first_tag >
For each item from this observable reduce it by sending only the first item.
Definition: rx-reduce.hpp:378
static Result member(Observable &&o, composite_subscription cs)
Definition: rx-publish.hpp:102
Definition: rx-operators.hpp:317
Definition: rx-synchronize.hpp:164
static Result member(Observable &&o, T first, composite_subscription cs=composite_subscription())
Definition: rx-publish.hpp:114
allows connections to the source to be independent of subscriptions.
Definition: rx-predef.hpp:177
Definition: rx-coordination.hpp:37