Struct scoped_connection
Synopsis
#include <src/entt/signal/sigh.hpp>
struct scoped_connection
Description
Scoped connection class.
Opaque object the aim of which is to allow users to release an already estabilished connection without having to keep a reference to the signal or the sink that generated it.
A scoped connection automatically breaks the link between the two objects when it goes out of scope.
Mentioned in
- Events, Signals And Everything In Between / Signals
Methods
scoped_connection overload | Default constructor. | |
scoped_connection overload | Constructs a scoped connection from a basic connection. | |
scoped_connection overload | Default copy constructor, deleted on purpose. | |
~scoped_connection | Automatically breaks the link on destruction. | |
operator bool | Checks whether a scoped connection is properly initialized. | |
operator= overload | Default copy assignment operator, deleted on purpose. | |
operator= overload | Acquires a connection. | |
release | Breaks the connection. |
Source
Lines 196-247 in src/entt/signal/sigh.hpp.
struct scoped_connection {
/*! @brief Default constructor. */
scoped_connection() = default;
/**
* @brief Constructs a scoped connection from a basic connection.
* @param other A valid connection object.
*/
scoped_connection(const connection &other)
: conn{other}
{}
/*! @brief Default copy constructor, deleted on purpose. */
scoped_connection(const scoped_connection &) = delete;
/*! @brief Automatically breaks the link on destruction. */
~scoped_connection() {
conn.release();
}
/**
* @brief Default copy assignment operator, deleted on purpose.
* @return This scoped connection.
*/
scoped_connection & operator=(const scoped_connection &) = delete;
/**
* @brief Acquires a connection.
* @param other The connection object to acquire.
* @return This scoped connection.
*/
scoped_connection & operator=(connection other) {
conn = std::move(other);
return *this;
}
/**
* @brief Checks whether a scoped connection is properly initialized.
* @return True if the connection is properly initialized, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return static_cast<bool>(conn);
}
/*! @brief Breaks the connection. */
void release() {
conn.release();
}
private:
connection conn;
};