ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
from_signal.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/subjects/publish_subject.hpp>
14
15#include <rppqt/sources/fwd.hpp>
16
17#include <QObject>
18#include <tuple>
19
20namespace rppqt::details
21{
22 template<typename... Args>
24 {
26
27 decltype(std::declval<subject>().get_observer()) observer;
28
29 template<typename... Vals>
30 void operator()(Vals&&... vals) const
31 {
32 observer.on_next(std::make_tuple(std::forward<Vals>(vals)...));
33 }
34 };
35
36 template<typename Arg>
38 {
40 decltype(std::declval<subject>().get_observer()) observer;
41
42 template<rpp::constraint::decayed_same_as<Arg> Val>
43 void operator()(Val&& val) const
44 {
45 observer.on_next(std::forward<Val>(val));
46 }
47 };
48
49 template<>
51 {
53 decltype(std::declval<subject>().get_observer()) observer;
54
55 void operator()() const
56 {
57 observer.on_next(rpp::utils::none{});
58 }
59 };
60} // namespace rppqt::details
61
62namespace rppqt::source
63{
75 template<std::derived_from<QObject> TSignalQObject, std::derived_from<TSignalQObject> TObject, typename R, typename... Args>
76 auto from_signal(const TObject& object, R (TSignalQObject::*signal)(Args...))
77 {
78 using on_next_impl = details::from_signal_on_event<Args...>;
79 const auto subj = typename on_next_impl::subject{};
80
81 QObject::connect(&object, signal, on_next_impl{subj.get_observer()});
82 QObject::connect(&object, &QObject::destroyed, [observer = subj.get_observer()] { observer.on_completed(); });
83
84 return subj.get_observable();
85 }
86} // namespace rppqt::source
Subject which just multicasts values to observers subscribed on it. It contains two parts: observer a...
Definition publish_subject.hpp:81
auto from_signal(const TObject &object, R(TSignalQObject::*signal)(Args...))
Creates rpp::observable that emits a items from provided QT signal.
Definition from_signal.hpp:76
Definition utils.hpp:25
Definition from_signal.hpp:24