// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #pragma once /*! \file rx-lift.hpp \brief takes any function that will take a subscriber for this observable and produce a subscriber. this is intended to allow externally defined operators, that use make_subscriber, to be connected into the expression. \tparam ResultType the type of the emitted results. \tparam Operator the type of the operator. \return An observable that emitting the items from its source. */ #if !defined(RXCPP_OPERATORS_RX_LIFT_HPP) #define RXCPP_OPERATORS_RX_LIFT_HPP #include "../rx-includes.hpp" namespace rxcpp { namespace detail { template struct is_lift_function_for { struct tag_not_valid {}; template static auto check(int) -> decltype((*(CF*)nullptr)(*(CS*)nullptr)); template static tag_not_valid check(...); using for_type = rxu::decay_t; using func_type = rxu::decay_t; using detail_result = decltype(check(0)); static const bool value = rxu::all_true_type< is_subscriber, is_subscriber, std::is_convertible::type>>::value; }; } namespace operators { namespace detail { template struct lift_traits { typedef rxu::decay_t result_value_type; typedef rxu::decay_t source_operator_type; typedef rxu::decay_t operator_type; typedef typename source_operator_type::value_type source_value_type; }; template struct lift_operator : public operator_base::result_value_type> { typedef lift_traits traits; typedef typename traits::source_operator_type source_operator_type; typedef typename traits::operator_type operator_type; source_operator_type source; operator_type chain; lift_operator(source_operator_type s, operator_type op) : source(std::move(s)) , chain(std::move(op)) { } template void on_subscribe(Subscriber o) const { auto lifted = chain(std::move(o)); trace_activity().lift_enter(source, chain, o, lifted); source.on_subscribe(std::move(lifted)); trace_activity().lift_return(source, chain); } }; template class lift_factory { typedef rxu::decay_t operator_type; operator_type chain; public: lift_factory(operator_type op) : chain(std::move(op)) {} template auto operator()(const Observable& source) -> decltype(source.template lift(chain)) { return source.template lift(chain); static_assert(rxcpp::detail::is_lift_function_for, subscriber, Operator>::value, "Function passed for lift() must have the signature subscriber<...>(subscriber)"); } }; } template auto lift(Operator&& op) -> detail::lift_factory { return detail::lift_factory(std::forward(op)); } } } #endif