ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
subscription_base.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/subscriptions/details/subscription_state.hpp>
14
15#include <memory>
16
17namespace rpp
18{
19class composite_subscription;
20
25{
26protected:
27 subscription_base(std::shared_ptr<details::subscription_state> state)
28 : m_state{std::move(state)} {}
29
30 const std::shared_ptr<details::subscription_state>& get_state() const { return m_state; }
31
33public:
35 : m_state{std::make_shared<details::subscription_state>()} {}
36
37 subscription_base(const subscription_base&) = default;
38 subscription_base(subscription_base&&) noexcept = default;
39 subscription_base& operator=(const subscription_base& other) = default;
40 subscription_base& operator=(subscription_base&& other) noexcept = default;
41
42 bool operator==(const subscription_base& rhs) const = default;
43
44 virtual ~subscription_base() = default;
45
46 static subscription_base empty() { return subscription_base{ nullptr }; }
47
51 [[nodiscard]] bool is_subscribed() const
52 {
53 return m_state && m_state->is_subscribed();
54 }
55
59 void unsubscribe() const
60 {
61 if (m_state)
62 {
63 m_state->unsubscribe();
64 m_state.reset();
65 }
66 }
67
68private:
69 mutable std::shared_ptr<details::subscription_state> m_state{};
70};
71
72} // namespace rpp
rpp::subscription_base with ability to add some dependent subscriptions as a part of this one: in cas...
Definition: composite_subscription.hpp:30
Base subscription implementation used as base class/interface and core implementation for derrived su...
Definition: subscription_base.hpp:25
bool is_subscribed() const
indicates current status of subscription
Definition: subscription_base.hpp:51
void unsubscribe() const
initiates unsubscription process (if subscribed)
Definition: subscription_base.hpp:59