ezEngine  Milestone 9
ezEventBase< EventData, MutexType > Class Template Reference

This class allows to propagate events to code that might be interested in them. More...

#include <Event.h>

Inheritance diagram for ezEventBase< EventData, MutexType >:

Classes

class  Unsubscriber
 An object that can be passed to ezEvent::AddEventHandler to store the subscription information and automatically remove the event handler upon destruction. More...
 

Public Types

typedef ezDelegate< void(EventData)> Handler
 Notification callback type for events.
 

Public Member Functions

void Broadcast (EventData pEventData, ezUInt8 uiMaxRecursionDepth=0) const
 This function will broadcast to all registered users, that this event has just happened. Setting uiMaxRecursionDepth will allow you to permit recursions. When broadcasting consider up to what depth you want recursions to be permitted. By default no recursion is allowed. More...
 
ezEventSubscriptionID AddEventHandler (Handler handler) const
 Adds a function as an event handler. All handlers will be notified in the order that they were registered. More...
 
void AddEventHandler (Handler handler, Unsubscriber &unsubscriber) const
 An overload that adds an event handler and initializes the given Unsubscriber object. More...
 
void RemoveEventHandler (Handler handler) const
 Removes a previously registered handler. It is an error to remove a handler that was not registered. More...
 
void RemoveEventHandler (ezEventSubscriptionID &id) const
 Removes a previously registered handler via the returned subscription ID. More...
 
bool HasEventHandler (Handler handler) const
 Checks whether an event handler has already been registered.
 
 EZ_DISALLOW_COPY_AND_ASSIGN (ezEventBase)
 

Protected Member Functions

 ezEventBase (ezAllocatorBase *pAllocator)
 Constructor.
 

Detailed Description

template<typename EventData, typename MutexType>
class ezEventBase< EventData, MutexType >

This class allows to propagate events to code that might be interested in them.

An event can be anything that "happens" that might be of interest for other code, such that it can react on it in some way. Just create an instance of ezEvent and call "Broadcast" on it. Other interested code needs access to the variable (or at least to AddEventHandler / RemoveEventHandler) such that it can register itself as an interested party. To pass information to the handlers, create your own custom struct to package that information and then pass a pointer to that data through Broadcast. The handlers just need to cast the void-pointer to the proper struct and thus can get all the detailed information about the event.

Member Function Documentation

◆ AddEventHandler() [1/2]

template<typename EventData , typename MutexType >
ezEventSubscriptionID ezEventBase< EventData, MutexType >::AddEventHandler ( Handler  handler) const

Adds a function as an event handler. All handlers will be notified in the order that they were registered.

The return value can be stored and used to remove the event handler later again.

A callback can be registered multiple times with different pass-through data (or even with the same, though that is less useful).

◆ AddEventHandler() [2/2]

template<typename EventData , typename MutexType >
void ezEventBase< EventData, MutexType >::AddEventHandler ( Handler  handler,
Unsubscriber unsubscriber 
) const

An overload that adds an event handler and initializes the given Unsubscriber object.

When the Unsubscriber is destroyed, it will automatically remove the event handler.

◆ Broadcast()

template<typename EventData, typename MutexType >
void ezEventBase< EventData, MutexType >::Broadcast ( EventData  pEventData,
ezUInt8  uiMaxRecursionDepth = 0 
) const

This function will broadcast to all registered users, that this event has just happened. Setting uiMaxRecursionDepth will allow you to permit recursions. When broadcasting consider up to what depth you want recursions to be permitted. By default no recursion is allowed.

The notification is sent to all event handlers in the order that they were registered.

◆ RemoveEventHandler() [1/2]

template<typename EventData , typename MutexType >
void ezEventBase< EventData, MutexType >::RemoveEventHandler ( Handler  handler) const

Removes a previously registered handler. It is an error to remove a handler that was not registered.

Use exactly the same combination of callback/pass-through-data to unregister an event handlers. Otherwise an error occurs.

◆ RemoveEventHandler() [2/2]

template<typename EventData , typename MutexType >
void ezEventBase< EventData, MutexType >::RemoveEventHandler ( ezEventSubscriptionID &  id) const

Removes a previously registered handler via the returned subscription ID.

The ID will be reset to zero. If this is called with a zero ID, nothing happens.


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