Raven Engine v0.1
Loading...
Searching...
No Matches
Raven::EventDispatcher Class Reference

Routes an Event to a matching handler function. More...

#include <EventDispatcher.h>

Public Member Functions

 EventDispatcher (Event &event)
 Constructs an EventDispatcher for a given event.
template<typename T, typename F>
bool Dispatch (const F &func)
 Attempts to dispatch the stored event if it matches type T.

Detailed Description

Routes an Event to a matching handler function.

The EventDispatcher wraps a reference to a base Event and provides a type-safe Dispatch<T>(handler) method. If the stored event matches the specified type T, the handler is invoked with the casted event, and the event's Handled flag is updated. This enables clean separation of event routing logic without dynamic_cast overhead.

Template Parameters
None(class methods are templated)

Construct with an Event reference, then call Dispatch<ConcreteEvent>(func) for each event type you wish to handle.

Constructor & Destructor Documentation

◆ EventDispatcher()

Raven::EventDispatcher::EventDispatcher ( Event & event)
inlineexplicit

Constructs an EventDispatcher for a given event.

Parameters
eventThe event to dispatch.

Member Function Documentation

◆ Dispatch()

template<typename T, typename F>
bool Raven::EventDispatcher::Dispatch ( const F & func)
inline

Attempts to dispatch the stored event if it matches type T.

If the event's GetEventType() equals T::GetStaticType(), invokes the handler function func with the event cast to T&. The event's Handled flag is OR-ed with the handler's return value.

Template Parameters
TThe concrete Event subclass type to match.
FCallable type with signature bool(T&).
Parameters
funcThe handler to invoke on match.
Returns
true if the handler was invoked (regardless of its return), false otherwise.

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