MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
MetaImGUI::Signal< Args > Class Template Reference

A single-threaded multicast event source. More...

#include <Signal.h>

Public Types

using SlotId = std::size_t
 
using Slot = std::function< void(Args...)>
 

Public Member Functions

 Signal ()=default
 
 Signal (const Signal &)=delete
 
Signaloperator= (const Signal &)=delete
 
 Signal (Signal &&)=delete
 
Signaloperator= (Signal &&)=delete
 
 ~Signal ()=default
 
Connection Connect (Slot slot)
 Subscribe a slot.
 
void Emit (Args... args) const
 Fire the signal.
 
std::size_t SlotCount () const noexcept
 

Detailed Description

template<typename... Args>
class MetaImGUI::Signal< Args >

A single-threaded multicast event source.

Slots receive every Emit() in connection order. The Signal stores its slot table in a shared control block, so a Connection that outlives the Signal harmlessly disconnects nothing rather than dereferencing a dangling pointer.

Not thread-safe — Emit / Connect / Disconnect must all happen on the same thread (the UI thread, in this codebase). Cross-thread fan-out is the caller's job (see the m_pendingUpdateResult mutex hand-off in Application).

Definition at line 100 of file Signal.h.

Member Typedef Documentation

◆ Slot

template<typename... Args>
using MetaImGUI::Signal< Args >::Slot = std::function<void(Args...)>

Definition at line 103 of file Signal.h.

◆ SlotId

template<typename... Args>
using MetaImGUI::Signal< Args >::SlotId = std::size_t

Definition at line 102 of file Signal.h.

Constructor & Destructor Documentation

◆ Signal() [1/3]

template<typename... Args>
MetaImGUI::Signal< Args >::Signal ( )
default

◆ Signal() [2/3]

template<typename... Args>
MetaImGUI::Signal< Args >::Signal ( const Signal< Args > &  )
delete

◆ Signal() [3/3]

template<typename... Args>
MetaImGUI::Signal< Args >::Signal ( Signal< Args > &&  )
delete

◆ ~Signal()

template<typename... Args>
MetaImGUI::Signal< Args >::~Signal ( )
default

Member Function Documentation

◆ Connect()

template<typename... Args>
Connection MetaImGUI::Signal< Args >::Connect ( Slot  slot)
inline

Subscribe a slot.

Returns a RAII handle that disconnects on drop.

Definition at line 122 of file Signal.h.

Referenced by MetaImGUI::Application::Initialize().

◆ Emit()

template<typename... Args>
void MetaImGUI::Signal< Args >::Emit ( Args...  args) const
inline

Fire the signal.

Each connected slot is invoked once with args.

Slots are invoked from a snapshot, so a slot that disconnects itself or another slot during emission is safe — the snapshot is unaffected.

Definition at line 139 of file Signal.h.

Referenced by MetaImGUI::UIRenderer::RenderMainWindow(), and MetaImGUI::UIRenderer::RenderMenuBar().

◆ operator=() [1/2]

template<typename... Args>
Signal & MetaImGUI::Signal< Args >::operator= ( const Signal< Args > &  )
delete

◆ operator=() [2/2]

template<typename... Args>
Signal & MetaImGUI::Signal< Args >::operator= ( Signal< Args > &&  )
delete

◆ SlotCount()

template<typename... Args>
std::size_t MetaImGUI::Signal< Args >::SlotCount ( ) const
inlinenoexcept

Definition at line 150 of file Signal.h.


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