Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::Connection Class Reference

RAII handle for signal connections. More...

#include <Connection.hpp>

Public Types

using DisconnectFunc = std::function<void(CallbackId)>

Public Member Functions

 Connection ()=default
 Default constructor creates an empty connection.
 Connection (CallbackId id, DisconnectFunc disconnectFunc)
 Constructs a connection with disconnect callback.
 ~Connection ()
 Destructor automatically disconnects.
 Connection (Connection &&other) noexcept
 Move constructor transfers ownership.
Connection & operator= (Connection &&other) noexcept
 Move assignment transfers ownership.
 Connection (const Connection &)=delete
Connection & operator= (const Connection &)=delete
void disconnect ()
 Manually disconnect from the signal.
bool isConnected () const
 Check if still connected.
CallbackId getId () const
 Get the callback ID.
CallbackId release ()
 Release ownership without disconnecting.

Detailed Description

RAII handle for signal connections.

Connection manages the lifetime of a callback registration. When the Connection object is destroyed, it automatically disconnects from the signal, preventing memory leaks and dangling callback issues.

Note
Connection is move-only to prevent accidental disconnection through copies.
auto conn = signal.connect([](int x) { ... });
// Connection is active
conn.disconnect(); // Or let conn go out of scope

Definition at line 57 of file Connection.hpp.

Member Typedef Documentation

◆ DisconnectFunc

using esengine::Connection::DisconnectFunc = std::function<void(CallbackId)>

Definition at line 59 of file Connection.hpp.

Constructor & Destructor Documentation

◆ Connection() [1/4]

esengine::Connection::Connection ( )
default

Default constructor creates an empty connection.

Referenced by Connection(), Connection(), operator=(), and operator=().

◆ Connection() [2/4]

esengine::Connection::Connection ( CallbackId id,
DisconnectFunc disconnectFunc )
inline

Constructs a connection with disconnect callback.

Parameters
idThe callback identifier
disconnectFuncFunction to call when disconnecting

Definition at line 71 of file Connection.hpp.

◆ ~Connection()

esengine::Connection::~Connection ( )
inline

Destructor automatically disconnects.

Definition at line 77 of file Connection.hpp.

References disconnect().

◆ Connection() [3/4]

esengine::Connection::Connection ( Connection && other)
inlinenoexcept

Move constructor transfers ownership.

Parameters
otherConnection to move from

Definition at line 85 of file Connection.hpp.

References Connection(), and esengine::INVALID_CALLBACK_ID.

◆ Connection() [4/4]

esengine::Connection::Connection ( const Connection & )
delete

References Connection().

Member Function Documentation

◆ disconnect()

void esengine::Connection::disconnect ( )
inline

Manually disconnect from the signal.

Definition at line 113 of file Connection.hpp.

References esengine::INVALID_CALLBACK_ID, and isConnected().

Referenced by ~Connection(), and operator=().

◆ getId()

CallbackId esengine::Connection::getId ( ) const
inlinenodiscard

Get the callback ID.

Returns
The callback identifier

Definition at line 133 of file Connection.hpp.

◆ isConnected()

bool esengine::Connection::isConnected ( ) const
inlinenodiscard

Check if still connected.

Returns
true if connected, false otherwise

Definition at line 125 of file Connection.hpp.

References esengine::INVALID_CALLBACK_ID.

Referenced by disconnect().

◆ operator=() [1/2]

Connection & esengine::Connection::operator= ( Connection && other)
inlinenoexcept

Move assignment transfers ownership.

Parameters
otherConnection to move from
Returns
Reference to this

Definition at line 96 of file Connection.hpp.

References Connection(), disconnect(), and esengine::INVALID_CALLBACK_ID.

◆ operator=() [2/2]

Connection & esengine::Connection::operator= ( const Connection & )
delete

References Connection().

◆ release()

CallbackId esengine::Connection::release ( )
inline

Release ownership without disconnecting.

Returns
The callback ID

Definition at line 141 of file Connection.hpp.

References esengine::INVALID_CALLBACK_ID.


The documentation for this class was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/events/Connection.hpp