Generic class for observing and triggering events.
More...
#include <utils_signal.hpp>
|
using | function_type = std::function< T > |
| Type of the callable function stored in a slot. Can use any function/delegate type here, as long as it has a matching call operator. The function type does not need to be owning; in this case, the slot must be manually disconnected whenever the pointed function is destroyed.
|
|
using | slot_list_view = utils::view::adaptor< slot_list, slot_dereferencer, non_disconnected_filter > |
| Type of the view returned by slots().
|
|
template<typename T>
class lxgui::utils::signal< T >
Generic class for observing and triggering events.
The implementation guarantees that the following is safe:
- Connecting or disconnecting a slot from inside any other slot (including self).
- Destroying the signal from any slot.
- Calling the signal recursively from any slot (up to standard stack exhaustion limits).
Other notable behaviors:
- Slots will be called in order of connection.
- Slots connected while the signal is being triggered will not be called until the next trigger of the signal.
Example:
sig(42);
sig.
connect([](
int i) { std::cout << i << std::endl; });
sig(42);
sig.
connect([](
int i) { std::cout << 2*i << std::endl; });
sig(42);
sig(42);
sig(42);
int val = 0;
{
utils::scoped_connection sc = sig.
connect([](
int i) { val = i; });
sig(42);
}
sig(43);
Object representing the connection between a slot and a signal.
void disconnect() noexcept
Disconnect the slot.
Generic class for observing and triggering events.
connection connect(function_type function)
Connect a new slot to this signal.
Definition at line 142 of file utils_signal.hpp.
◆ function_type
Type of the callable function stored in a slot. Can use any function/delegate type here, as long as it has a matching call operator. The function type does not need to be owning; in this case, the slot must be manually disconnected whenever the pointed function is destroyed.
Definition at line 151 of file utils_signal.hpp.
◆ slot_list_view
◆ signal() [1/3]
◆ ~signal()
◆ signal() [2/3]
◆ signal() [3/3]
◆ connect()
Connect a new slot to this signal.
- Parameters
-
function | The function to store in the slot. |
- Returns
- A connection object, which can be used to disconnect the slot at any time.
- Note
- If the returned connection object is discarded, the slot will remain connected for the entire lifetime of the signal, or until disconnect_all is called. If this is not desirable, store the returned connection, and disconnect the slot when it should no longer be called. The RAII helper class scoped_connection can do this safely.
Definition at line 283 of file utils_signal.hpp.
◆ disconnect_all()
◆ empty()
Check if this signal contains any slot.
- Returns
- 'true' if at least one slot is connected.
Definition at line 258 of file utils_signal.hpp.
◆ operator()()
template<typename T >
template<typename... Args>
Trigger the signal.
- Parameters
-
args | Arguments to forward to all the connected slots. |
Definition at line 293 of file utils_signal.hpp.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ slots()
Return a constant view onto the connected slots.
- Returns
- A constant view onto the connected slots
- Warning
- Do not attempt to connect or disconnect slots while iterating over this view.
Definition at line 269 of file utils_signal.hpp.
The documentation for this class was generated from the following file: