Arnold Engine
 
Loading...
Searching...
No Matches
AE::Events::EventHandler Class Reference

A utility class that safely routes events to type-specific handler functions. More...

#include <Event.h>

Public Member Functions

 EventHandler (Event &event)
 Constructs an EventHandler for a specific event.
 
template<typename T>
bool TryHandle (HandlerFn< T > handler)
 Attempts to handle an event if it matches the specified type.
 

Detailed Description

A utility class that safely routes events to type-specific handler functions.

The EventHandler provides a type-safe way to handle different types of events by:

  1. Checking if an incoming event matches a specific type
  2. If matched, converting the event to its specific type safely
  3. Routing it to the appropriate handler function

Example usage:

void OnEvent(Event& e) {
EventHandler handler(e);
// Try to handle a window close event
if (handler.TryHandle<WindowCloseEvent>(BIND_EVENT_FN(OnWindowClose))) {
return; // Event was successfully handled
}
// Event wasn't a window close event, try other handlers...
}
bool OnWindowClose(WindowCloseEvent& e) {
// Handle window close...
return true; // Mark event as handled
}
EventHandler(Event &event)
Constructs an EventHandler for a specific event.
Definition Event.h:119
Base class for the event system.
Definition Event.h:61
Event triggered when the window is closed.
Definition ApplicationEvent.h:49
Note
Handler functions should return true if they've handled the event and false if the event should continue propagating to other handlers.

Constructor & Destructor Documentation

◆ EventHandler()

AE::Events::EventHandler::EventHandler ( Event & event)
inline

Constructs an EventHandler for a specific event.

Parameters
eventThe event to potentially handle.

Member Function Documentation

◆ TryHandle()

template<typename T>
bool AE::Events::EventHandler::TryHandle ( HandlerFn< T > handler)
inline

Attempts to handle an event if it matches the specified type.

Template Parameters
TThe specific event type to check for.
Parameters
handlerThe function to handle the event if types match.
Returns
true if the event type matched and the handler was called, false if the event was of a different type.

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