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.
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
-
| T | The concrete Event subclass type to match. |
| F | Callable type with signature bool(T&). |
- Parameters
-
| func | The handler to invoke on match. |
- Returns
- true if the handler was invoked (regardless of its return), false otherwise.