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

Hands each engine event to the listeners subscribed to its type. More...

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

Public Types

using Listener
using ListenerList

Public Member Functions

 EventBus (void)=default
 Create a bus with no listener.
 ~EventBus (void)=default
 Destroy the bus and its listeners.
void publish (std::shared_ptr< utility::event::Event > event)
 Call, before returning, every listener subscribed to the exact type of an event.
template<utility::event::InheritFromEvent EventType>
void subscribe (Listener listener)
 Add a listener for one event type.

Detailed Description

Hands each engine event to the listeners subscribed to its type.

Application owns one bus and passes to publish() every input event the engine polls at the start of a frame; the listeners are called at once, in subscription order. The systems do not subscribe directly: they use EventManager (or EventSubscriber), whose listener only queues the event so the system can process it later in the frame, during its phase.

bus.subscribe<utility::event::KeyboardEvent>(
[](std::shared_ptr<utility::event::Event> event) {
auto keyboardEvent = std::dynamic_pointer_cast<
utility::event::KeyboardEvent>(event);
});
bus.publish(event); // a std::shared_ptr<utility::event::Event>
Hands each engine event to the listeners subscribed to its type.
Definition event_bus.hpp:67
void subscribe(Listener listener)
Add a listener for one event type.
void publish(std::shared_ptr< utility::event::Event > event)
Call, before returning, every listener subscribed to the exact type of an event.
Definition event_bus.cpp:39
Delivery of engine events to the systems that subscribed to them.
Definition event_bus.hpp:34

Things to watch out for:

  • The match is on the exact type of the event object: a listener subscribed to a base event type does not receive derived events.
  • A listener cannot be removed. Whatever it captures must stay alive as long as events are published.
See also
EventSubscriber
EventManager

Definition at line 66 of file event_bus.hpp.

Member Typedef Documentation

◆ Listener

Initial value:
std::function<void(
std::shared_ptr<utility::event::Event>)>

Function called with each event of the subscribed type

Definition at line 69 of file event_bus.hpp.

◆ ListenerList

Initial value:
std::vector<Listener>

Listeners of one event type, in subscription order

Definition at line 74 of file event_bus.hpp.

Member Function Documentation

◆ publish()

void guillaume::event::EventBus::publish ( std::shared_ptr< utility::event::Event > event)

Call, before returning, every listener subscribed to the exact type of an event.

Nothing happens when the event is null or when its type has no listener. An exception thrown by a listener propagates and the remaining listeners are not called.

Parameters
eventThe event to deliver. It is shared with the listeners, which may keep it.

Definition at line 39 of file event_bus.cpp.

◆ subscribe()

template<utility::event::InheritFromEvent EventType>
void guillaume::event::EventBus::subscribe ( Listener listener)

Add a listener for one event type.

Template Parameters
EventTypeThe exact event type to listen to.
Parameters
listenerThe function to call with each published event of that type. It receives the event as a base Event pointer and casts it itself.

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