20 template<
typename... Args>
23 class ConnectionHandle;
32 class SignalImplBase :
public std::enable_shared_from_this<SignalImplBase>
35 SignalImplBase() =
default;
37 virtual ~SignalImplBase() =
default;
39 virtual void disconnect(
const ConnectionHandle &handle) noexcept = 0;
40 virtual bool blockConnection(
const GenerationalIndex &
id,
bool blocked) = 0;
41 virtual bool isConnectionActive(
const GenerationalIndex &
id)
const noexcept = 0;
42 virtual bool isConnectionBlocked(
const GenerationalIndex &
id)
const = 0;
93 if (
auto shared_impl = checkedLock()) {
94 shared_impl->disconnect(*
this);
109 return static_cast<bool>(checkedLock());
130 if (
auto shared_impl = checkedLock()) {
131 return shared_impl->blockConnection(*m_id, blocked);
133 throw std::out_of_range(
"Cannot block a non-active connection!");
145 if (
auto shared_impl = checkedLock()) {
146 return shared_impl->isConnectionBlocked(*m_id);
148 throw std::out_of_range(
"Cannot check whether a non-active connection is blocked!");
156 template<
typename... Args>
159 auto shared_impl = m_signalImpl.lock();
160 return shared_impl && shared_impl == std::static_pointer_cast<Private::SignalImplBase>(signal.m_impl);
166 auto thisSignalImpl = m_signalImpl.lock();
167 auto otherSignalImpl = other.m_signalImpl.lock();
170 if (thisSignalImpl && otherSignalImpl) {
171 return (thisSignalImpl == otherSignalImpl) && (m_id == other.m_id);
175 if (!m_id.has_value() && !other.m_id.has_value() && !thisSignalImpl && !otherSignalImpl) {
201 template<
typename...>
204 std::weak_ptr<Private::SignalImplBase> m_signalImpl;
205 std::optional<Private::GenerationalIndex> m_id;
208 ConnectionHandle(std::weak_ptr<Private::SignalImplBase> signalImpl, std::optional<Private::GenerationalIndex>
id)
209 : m_signalImpl{
std::move(signalImpl) }, m_id{
std::move(id) }
212 void setId(
const Private::GenerationalIndex &
id)
219 std::shared_ptr<Private::SignalImplBase> checkedLock() const noexcept
221 if (m_id.has_value()) {
222 auto shared_impl = m_signalImpl.lock();
223 if (shared_impl && shared_impl->isConnectionActive(*m_id)) {
261 m_connection.disconnect();
262 m_connection = std::move(other.m_connection);
270 : m_connection(std::move(h))
303 return &m_connection;
311 return &m_connection;
322 m_connection.disconnect();
A ConnectionHandle represents the connection of a Signal to a slot (i.e. a function that is called wh...
void disconnect() noexcept
bool belongsTo(const Signal< Args... > &signal) const
ConnectionHandle(const ConnectionHandle &) noexcept=default
ConnectionHandle & operator=(const ConnectionHandle &) noexcept=default
bool operator==(const ConnectionHandle &other) const
ConnectionHandle()=default
ConnectionHandle(ConnectionHandle &&) noexcept=default
A ScopedConnection is a RAII-style way to make sure a Connection is disconnected.
const ConnectionHandle & handle() const
ScopedConnection()=default
A ScopedConnection can be default constructed.
ScopedConnection & operator=(ConnectionHandle &&h) noexcept
ConnectionHandle & handle()
~ScopedConnection() noexcept
const ConnectionHandle * operator->() const
ScopedConnection(ConnectionHandle &&h) noexcept
ConnectionHandle * operator->()
ScopedConnection(ScopedConnection &&) noexcept=default
A Signal provides a mechanism for communication between objects.
The main namespace of the KDBindings library.