• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 /*! \file rx-ignore_elements.hpp
6 
7     \brief Do not emit any items from the source Observable, but allow termination notification (either onError or onCompleted) to pass through unchanged.
8 
9     \return Observable that emits termination notification from the source observable.
10 
11     \sample
12     \snippet ignore_elements.cpp ignore_elements sample
13     \snippet output.txt ignore_elements sample
14 */
15 
16 #if !defined(RXCPP_OPERATORS_RX_IGNORE_ELEMENTS_HPP)
17 #define RXCPP_OPERATORS_RX_IGNORE_ELEMENTS_HPP
18 
19 #include "../rx-includes.hpp"
20 
21 namespace rxcpp {
22 
23 namespace operators {
24 
25 namespace detail {
26 
27 template<class... AN>
28 struct ignore_elements_invalid_arguments {};
29 
30 template<class... AN>
31 struct ignore_elements_invalid : public rxo::operator_base<ignore_elements_invalid_arguments<AN...>> {
32     using type = observable<ignore_elements_invalid_arguments<AN...>, ignore_elements_invalid<AN...>>;
33 };
34 template<class... AN>
35 using ignore_elements_invalid_t = typename ignore_elements_invalid<AN...>::type;
36 
37 template<class T>
38 struct ignore_elements {
39     typedef rxu::decay_t<T> source_value_type;
40 
41     template<class Subscriber>
42     struct ignore_elements_observer
43     {
44         typedef ignore_elements_observer<Subscriber> this_type;
45         typedef source_value_type value_type;
46         typedef rxu::decay_t<Subscriber> dest_type;
47         typedef observer<value_type, this_type> observer_type;
48         dest_type dest;
49 
ignore_elements_observerrxcpp::operators::detail::ignore_elements::ignore_elements_observer50         ignore_elements_observer(dest_type d)
51             : dest(d)
52         {
53         }
54 
on_nextrxcpp::operators::detail::ignore_elements::ignore_elements_observer55         void on_next(source_value_type) const {
56             // no-op; ignore element
57         }
58 
on_errorrxcpp::operators::detail::ignore_elements::ignore_elements_observer59         void on_error(rxu::error_ptr e) const {
60             dest.on_error(e);
61         }
62 
on_completedrxcpp::operators::detail::ignore_elements::ignore_elements_observer63         void on_completed() const {
64             dest.on_completed();
65         }
66 
makerxcpp::operators::detail::ignore_elements::ignore_elements_observer67         static subscriber<value_type, observer_type> make(dest_type d) {
68             return make_subscriber<value_type>(d, this_type(d));
69         }
70     };
71 
72     template<class Subscriber>
operator ()rxcpp::operators::detail::ignore_elements73     auto operator()(Subscriber dest) const
74         -> decltype(ignore_elements_observer<Subscriber>::make(std::move(dest))) {
75         return      ignore_elements_observer<Subscriber>::make(std::move(dest));
76     }
77 };
78 
79 }
80 
81 /*! @copydoc rx-ignore_elements.hpp
82 */
83 template<class... AN>
ignore_elements(AN &&...an)84 auto ignore_elements(AN&&... an)
85 ->     operator_factory<ignore_elements_tag, AN...> {
86     return operator_factory<ignore_elements_tag, AN...>(std::make_tuple(std::forward<AN>(an)...));
87 }
88 
89 }
90 
91 template<>
92 struct member_overload<ignore_elements_tag>
93 {
94     template<class Observable,
95             class SourceValue = rxu::value_type_t<Observable>,
96             class Enabled = rxu::enable_if_all_true_type_t<
97                 is_observable<Observable>>,
98             class IgnoreElements = rxo::detail::ignore_elements<SourceValue>>
memberrxcpp::member_overload99     static auto member(Observable&& o)
100     -> decltype(o.template lift<SourceValue>(IgnoreElements())) {
101         return  o.template lift<SourceValue>(IgnoreElements());
102     }
103 
104     template<class... AN>
memberrxcpp::member_overload105     static operators::detail::ignore_elements_invalid_t<AN...> member(AN...) {
106         std::terminate();
107         return {};
108         static_assert(sizeof...(AN) == 10000, "ignore_elements takes no arguments");
109     }
110 };
111 
112 }
113 
114 #endif
115