Sen API
Sen Libraries
Toggle main menu visibility
Loading...
Searching...
No Matches
subscription.h
Go to the documentation of this file.
1
// === subscription.h ==================================================================================================
2
// Sen Infrastructure
3
// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4
// See the LICENSE.txt file for more information.
5
// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6
// =====================================================================================================================
7
8
#ifndef SEN_CORE_OBJ_SUBSCRIPTION_H
9
#define SEN_CORE_OBJ_SUBSCRIPTION_H
10
11
// sen
12
#include "
sen/core/obj/interest.h
"
13
#include "
sen/core/obj/object_list.h
"
14
#include "
sen/core/obj/object_source.h
"
15
16
// std
17
#include <memory>
18
#include <utility>
19
20
namespace
sen
21
{
22
25
27
template
<
typename
T>
28
struct
Subscription
29
{
30
public
:
31
SEN_COPY_CONSTRUCT(
Subscription
) =
delete
;
32
SEN_COPY_ASSIGN(
Subscription
) =
delete
;
33
34
public
:
// special members
35
Subscription
(
Subscription
&& other)
noexcept
;
36
Subscription
&
operator=
(
Subscription
&& other)
noexcept
;
37
Subscription
() =
default
;
38
~Subscription
();
39
40
public
:
43
void
attachTo
(std::shared_ptr<ObjectSource> src, std::shared_ptr<Interest> interest,
bool
notifyAboutExisting);
44
48
void
release
(
bool
notifyAboutExisting =
true
);
49
51
[[nodiscard]] std::shared_ptr<ObjectSource>
getSource
()
const
{
return
source_; }
52
53
public
:
54
ObjectList<T>
list
;
// NOLINT(misc-non-private-member-variables-in-classes)
55
56
private
:
57
std::shared_ptr<ObjectSource> source_;
58
};
59
60
//-------------------------------------------------------------------------------------------------------------------
61
// Inline implementation
62
//-------------------------------------------------------------------------------------------------------------------
63
64
template
<
typename
T>
65
inline
Subscription<T>::Subscription
(
Subscription
&& other)
noexcept
66
{
67
release
(
true
);
68
69
list
= std::move(other.list);
70
source_ = std::move(other.source_);
71
72
if
(source_)
73
{
74
source_->replaceSubscriber(&other.list, &
list
);
75
}
76
}
77
78
template
<
typename
T>
79
inline
Subscription<T>
&
Subscription<T>::operator=
(
Subscription<T>
&& other)
noexcept
80
{
81
if
(
this
!= &other)
82
{
83
release
(
true
);
84
85
list
= std::move(other.list);
86
source_ = std::move(other.source_);
87
88
if
(source_)
89
{
90
source_->replaceSubscriber(&other.list, &
list
);
91
}
92
}
93
94
return
*
this
;
95
}
96
97
template
<
typename
T>
98
inline
Subscription<T>::~Subscription
()
99
{
100
release
(
true
);
101
}
102
103
template
<
typename
T>
104
inline
void
Subscription<T>::attachTo
(std::shared_ptr<ObjectSource> src,
105
std::shared_ptr<Interest> interest,
106
bool
notifyAboutExisting)
107
{
108
release
();
109
110
source_ = std::move(src);
111
source_->addSubscriber(std::move(interest), &
list
, notifyAboutExisting);
112
}
113
114
template
<
typename
T>
115
inline
void
Subscription<T>::release
(
bool
notifyAboutExisting)
116
{
117
if
(source_)
118
{
119
source_->removeSubscriber(&
list
, notifyAboutExisting);
120
source_.reset();
121
}
122
}
123
125
126
}
// namespace sen
127
128
#endif
// SEN_CORE_OBJ_SUBSCRIPTION_H
sen::ObjectList
A list of objects that is managed by some source based on user-expressed interests.
Definition
object_list.h:30
sen::Subscription::attachTo
void attachTo(std::shared_ptr< ObjectSource > src, std::shared_ptr< Interest > interest, bool notifyAboutExisting)
Attaches this subscription to a source and registers the given interest. Objects matching the interes...
Definition
subscription.h:104
sen::Subscription::operator=
Subscription & operator=(Subscription &&other) noexcept
Definition
subscription.h:79
sen::Subscription::release
void release(bool notifyAboutExisting=true)
Detaches from the source, unregistering the list as a subscriber. Called automatically on destruction...
Definition
subscription.h:115
sen::Subscription::~Subscription
~Subscription()
Definition
subscription.h:98
sen::Subscription::Subscription
Subscription(Subscription &&other) noexcept
Definition
subscription.h:65
interest.h
sen
Definition
assert.h:17
object_list.h
object_source.h
sen::Subscription::Subscription
Subscription()=default
sen::Subscription::list
ObjectList< T > list
Definition
subscription.h:54
sen::Subscription::getSource
std::shared_ptr< ObjectSource > getSource() const
Returns the source currently attached to this subscription, or nullptr if none.
Definition
subscription.h:51
libs
core
include
sen
core
obj
subscription.h
Generated by
1.17.0