List of all members | Public Member Functions
thor::ScopedConnection Class Reference

RAII style connection with automatic disconnect. More...

Inherits NonCopyable.

Public Member Functions

 ScopedConnection ()
 Default constructor. More...
 
 ScopedConnection (const Connection &connection)
 Constructor: Initializes the instance with a given Connection. More...
 
 ScopedConnection (ScopedConnection &&source)
 Move constructor. More...
 
ScopedConnectionoperator= (ScopedConnection &&source)
 Move assignment operator. More...
 
 ~ScopedConnection ()
 Destructor: Disconnects the event-listener connection. More...
 
bool isConnected () const
 Checks whether the instance currently references a listener. More...
 

Detailed Description

RAII style connection with automatic disconnect.

In contrast to thor::Connection, the thor::ScopedConnection class disconnects its referenced listener in the destructor. You can use ScopedConnection for temporary listeners that aren't needed after the end of scope. Alternatively, you can link a connection to the lifetime of another object by making it a member variable.
ScopedConnection is noncopyable, but it is movable.

Constructor & Destructor Documentation

thor::ScopedConnection::ScopedConnection ( )

Default constructor.

Initializes an invalid connection.

thor::ScopedConnection::ScopedConnection ( const Connection connection)
explicit

Constructor: Initializes the instance with a given Connection.

Scoped connections must be initialized in the constructor. You cannot assign a new value later.

Parameters
connectionConnection which is copied. It may be invalid.
thor::ScopedConnection::ScopedConnection ( ScopedConnection &&  source)

Move constructor.

Invalidates source such that it no longer disconnects the connection upon destruction.

thor::ScopedConnection::~ScopedConnection ( )

Destructor: Disconnects the event-listener connection.

In case the instance isn't connected, nothing happens.

Member Function Documentation

bool thor::ScopedConnection::isConnected ( ) const

Checks whether the instance currently references a listener.

Returns
true if this instance is currently connected.
ScopedConnection& thor::ScopedConnection::operator= ( ScopedConnection &&  source)

Move assignment operator.

Invalidates source such that it no longer disconnects the connection upon destruction.


The documentation for this class was generated from the following file: