class EE::Scene::EventConnection

Overview

Move-only handle that disconnects a Node event listener on destruction. More…

#include <eventconnection.hpp>

class EventConnection {
public:
    // construction

    EventConnection();
    EventConnection(EventConnection&& other);
    EventConnection(const EventConnection&);
    ~EventConnection();

    // methods

    EventConnection& operator=(EventConnection&& other);
    EventConnection& operator=(const EventConnection&);
    void disconnect();
    operator bool() const;
};

Detailed Documentation

Move-only handle that disconnects a Node event listener on destruction.

EventConnection provides scoped ownership for a listener registered with Node::connect(). If the connection is destroyed first, its listener is removed from the emitter. If the emitter is destroyed first, the connection expires and its eventual destruction is a safe no-op.

A connection does not keep its emitting Node alive. Moving a connection transfers listener ownership; copying is disabled so that exactly one handle owns the scoped listener.

Emitter destruction silently expires the connection. EventConnection is therefore not a replacement for UIWidget::OnClose: observers that must perform work when a widget closes must still connect to that widget-level notification.

Event registration, dispatch, disconnection, and connection destruction must all happen on the emitter’s owning thread. EventConnection does not make Node ‘s event registry thread-safe.

Construction

EventConnection()

Creates a disconnected handle.

EventConnection(EventConnection&& other)

Transfers listener ownership from other.

~EventConnection()

Disconnects the owned listener, if its emitter still exists.

Methods

EventConnection& operator=(EventConnection&& other)

Disconnects the currently owned listener and transfers ownership from other.

void disconnect()

Removes the listener and makes this handle disconnected.

Calling disconnect() more than once, or after the emitter has been destroyed, is safe.

operator bool() const

Returns:

True while this handle owns a listener and the emitter’s event state still exists.