#include <icy/signal.h>Thread-safe signal and slot implementation for callback-based event dispatch.
| Return | Name | Description |
|---|---|---|
int | attach const inline | Connects a lambda or std::function to the signal. |
int | attach const inline | Connects a pre-constructed SlotPtr to the signal. |
bool | detach const inline | Detaches the slot with the given ID. |
bool | detach const inline | Detaches all slots associated with the given instance pointer. |
bool | detach const inline | Detaches the slot whose delegate compares equal to other->delegate. |
void | detachAll const inline | Detaches and destroys all currently attached slots. |
RT | emit virtual inline | Emits the signal, invoking all live attached slots in priority order. |
std::vector< SlotPtr > | slots const inline | Returns a snapshot copy of the current slot list. |
size_t | nslots const inline | Returns the number of slots currently registered with this signal. |
int | operator+= inline | Attaches a function; equivalent to attach(func). |
int | operator+= inline | Attaches a pre-constructed slot; equivalent to attach(slot). |
bool | operator-= inline | Detaches the slot with the given ID; equivalent to detach(id). |
bool | operator-= inline | Detaches all slots for the given instance; equivalent to detach(instance). |
bool | operator-= inline | Detaches the slot matching slot's delegate; equivalent to detach(slot). |
Signal | Defaulted constructor. | |
Signal inline | Copy constructor; copies the slot list and last-assigned ID from r. | |
Signal & | operator= inline | Copy assignment operator; copies the slot list and last-assigned ID from r. |
const inline
inline int attach(Function const & func, void * instance, int id, int priority) constConnects a lambda or std::function to the signal.
func The callable to invoke when the signal is emitted.
instance Optional owner pointer used for instance-based detach; pass nullptr if not applicable.
id Explicit slot ID to assign; pass -1 to auto-assign.
priority Higher values are called first; pass -1 for default ordering.
The assigned slot ID, which can be passed to [detach()](#detach-2) to disconnect.
const inline
inline int attach(SlotPtr slot) constConnects a pre-constructed SlotPtr to the signal.
Duplicate slots (matched by delegate equality) are removed before insertion. Slots are kept sorted in descending priority order after insertion.
slot The slot to attach. Must have a valid delegate.The assigned slot ID, which can be passed to [detach()](#detach-2) to disconnect.
std::logic_error if slot->id is set explicitly and already in use.const inline
inline bool detach(int id) constDetaches the slot with the given ID.
Safe to call from within a slot's callback (the slot is marked dead before erasure).
id The slot ID returned by [attach()](#attach-3).true if a slot was found and removed; false if the ID was not found.
const inline
inline bool detach(const void * instance) constDetaches all slots associated with the given instance pointer.
Useful for bulk disconnect when an object is destroyed. Matches slots by their stored instance pointer, not by delegate equality.
instance The owner pointer used when the slots were attached.true if at least one slot was removed; false otherwise.
const inline
inline bool detach(SlotPtr other) constDetaches the slot whose delegate compares equal to other->delegate.
Used by the [slot()](api_icy.md#slot) helper overloads and operator-= to disconnect a specific class-member or function binding by value.
other A slot whose delegate is compared against attached slots.true if a matching slot was found and removed; false otherwise.
const inline
inline void detachAll() constDetaches and destroys all currently attached slots.
Each slot is marked dead before removal. After this call [nslots()](#nslots) returns 0.
virtual inline
virtual inline RT emit(Args... args)Emits the signal, invoking all live attached slots in priority order.
For [Signal](icy-Signal.html#signal)<bool(...)>: iterates slots and returns true as soon as any slot returns true, stopping further propagation. Returns false if no slot handled the event.
For [Signal](icy-Signal.html#signal)<void(...)>: calls every live slot unconditionally.
Emission snapshots raw slot pointers under a shared lock, then invokes delegates without holding the lock. Dead slots are swept after the outermost emission returns, allowing attach/detach inside callbacks without copying shared_ptrs on the hot path.
args Arguments forwarded to each connected slot.For bool return type: true if any slot handled the event, false otherwise. For void return type: nothing.
const inline
inline std::vector< SlotPtr > slots() constReturns a snapshot copy of the current slot list.
The copy is taken under a shared lock, so it is safe to call concurrently with attach/detach operations. Only currently live slots are returned.
A vector of SlotPtr representing all currently registered slots.
const inline
inline size_t nslots() constReturns the number of slots currently registered with this signal.
The count is taken under a shared lock. Slots that were concurrently killed but not yet erased may still be included in the count.
The number of entries in the internal slot list.
inline
inline int operator+=(Function const & func)Attaches a function; equivalent to attach(func).
Assigned slot ID.
inline
inline int operator+=(SlotPtr slot)Attaches a pre-constructed slot; equivalent to attach(slot).
Assigned slot ID.
inline
inline bool operator-=(int id)Detaches the slot with the given ID; equivalent to detach(id).
true if removed.
inline
inline bool operator-=(const void * instance)Detaches all slots for the given instance; equivalent to detach(instance).
true if any removed.
inline
inline bool operator-=(SlotPtr slot)Detaches the slot matching slot's delegate; equivalent to detach(slot).
true if removed.
Signal() = defaultDefaulted constructor.
inline
inline Signal(const Signal & r)Copy constructor; copies the slot list and last-assigned ID from r.
r The signal to copy from.inline
inline Signal & operator=(const Signal & r)Copy assignment operator; copies the slot list and last-assigned ID from r.
r The signal to copy from.Reference to this signal.
std::function< RT(Args...)> Function()std::shared_ptr< internal::Slot< RT, Args... > > SlotPtr()internal::Slot< RT, Args... > Slot()| Return | Name | Description |
|---|---|---|
MutexT | _mutex | |
std::vector< SlotPtr > | _slots | |
size_t | _liveCount | |
int | _lastId | |
EmitDepth | _emitDepth | |
SweepFlag | _needsSweep |
MutexT _mutexstd::vector< SlotPtr > _slotssize_t _liveCount = 0int _lastId = 0EmitDepth _emitDepth {}SweepFlag _needsSweep {}| Return | Name | Description |
|---|---|---|
size_t | killMatchingLocked const inline | |
size_t | emitDepthLocked const inline | |
void | beginEmitLocked const inline | |
bool | endEmitLocked const inline | |
void | requestSweepLocked const inline | |
bool | consumeSweepRequest const inline | |
void | sweepLocked const inline | |
void | finishEmit inline | |
void | resetEmitState inline |
const inline
template<typename Matcher> inline size_t killMatchingLocked(Matcher && matcher, bool removeAll) constconst inline
inline size_t emitDepthLocked() constconst inline
inline void beginEmitLocked() constconst inline
inline bool endEmitLocked() constconst inline
inline void requestSweepLocked() constconst inline
inline bool consumeSweepRequest() constconst inline
inline void sweepLocked() constinline
inline void finishEmit()inline
inline void resetEmitState()