ezEngine  Milestone 7
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 >:

Public Types

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

Public Member Functions

void Broadcast (EventData pEventData)
 This function will broadcast to all registered users, that this event has just happened. More...
 
void 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 RemoveEventHandler (Handler handler) const
 Removes a previously registered handler. It is an error to remove a handler that was not registered. More...
 
 EZ_DISALLOW_COPY_AND_ASSIGN (ezEventBase)
 

Protected Member Functions

 ezEventBase (ezAllocatorBase *pAllocator)
 Constructor.
 

Private Attributes

bool m_bBroadcasting
 Used to detect recursive broadcasts and then throw asserts at you.
 
MutexType m_Mutex
 
ezDynamicArray< Handlerm_EventHandlers
 A dynamic array allows to have zero overhead as long as no event receivers are registered.
 

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

template<typename EventData , typename MutexType >
void 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.

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

template<typename EventData, typename MutexType >
void ezEventBase< EventData, MutexType >::Broadcast ( EventData  pEventData)

This function will broadcast to all registered users, that this event has just happened.

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

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.


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