guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::event::EventSubscriber< EventType > Class Template Reference

A queue of the events of one type published on an EventBus, waiting to be read. More...

#include <headers/guillaume/event/event_subscriber.hpp>

Public Member Functions

 EventSubscriber (EventBus &eventBus)
 Create an empty queue and subscribe it to a bus.
 ~EventSubscriber (void)=default
 Destroy the queue. The bus is not told: see the note of the class.
bool hasPendingEvents (void) const
 Tell whether at least one event is waiting.
std::shared_ptr< EventType > getNextEvent (void)
 Take the oldest waiting event out of the queue.

Detailed Description

template<utility::event::InheritFromEvent EventType>
class guillaume::event::EventSubscriber< EventType >

A queue of the events of one type published on an EventBus, waiting to be read.

The bus delivers events the moment the engine polls them. A subscriber stores them, in arrival order, until its owner is ready: Application reads its quit-event subscriber before each frame, and each input system reads its own (through EventManager) during the Event phase.

...
while (quit.hasPendingEvents()) {
auto event = quit.getNextEvent();
}
A queue of the events of one type published on an EventBus, waiting to be read.
Note
The bus keeps a pointer to the subscriber and has no way to drop it: a subscriber must not be copied or moved, and must live at least as long as events are published on the bus.
Template Parameters
EventTypeThe exact event type to queue.
See also
EventBus
EventManager

Definition at line 58 of file event_subscriber.hpp.

Constructor & Destructor Documentation

◆ EventSubscriber()

template<utility::event::InheritFromEvent EventType>
guillaume::event::EventSubscriber< EventType >::EventSubscriber ( EventBus & eventBus)

Create an empty queue and subscribe it to a bus.

Parameters
eventBusThe bus whose events of type EventType are queued, starting with the next one published.

Member Function Documentation

◆ getNextEvent()

template<utility::event::InheritFromEvent EventType>
std::shared_ptr< EventType > guillaume::event::EventSubscriber< EventType >::getNextEvent ( void )

Take the oldest waiting event out of the queue.

Returns
The event, or nullptr when the queue is empty.

◆ hasPendingEvents()

template<utility::event::InheritFromEvent EventType>
bool guillaume::event::EventSubscriber< EventType >::hasPendingEvents ( void ) const

Tell whether at least one event is waiting.

Returns
True when getNextEvent() would return an event.

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