Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
EventHandler< T > Class Template Reference

Handler for a type of event. More...

#include <event.h>

Public Types

typedef std::function< void(T &) callbackType)
 The type of function that should be passed.
 
typedef int subId
 The Subscription Id.
 

Public Member Functions

 EventHandler ()
 Construct a new Event Handler object.
 
void fire (T &event)
 Fire an event.
 
subId subscribe (const callbackType &func)
 Subscribe to an event.
 
subId subscribe (callbackType &&func)
 Subscribe to an event.
 
void unsubscribe (subId id)
 Unsubscribe from an event.
 
const std::type_info * getTypeInfo () const
 Get the Type Info of T.
 

Detailed Description

template<class T>
class EventHandler< T >

Handler for a type of event.

Todo
Make it thread-safe
Template Parameters
Tthe event that should extend IEvent

Member Typedef Documentation

◆ callbackType

template<class T >
typedef std::function<void(T &) EventHandler< T >::callbackType)

The type of function that should be passed.

All event-receiving functions should be declared as a void return type with a single parameter, the event in question.

◆ subId

template<class T >
typedef int EventHandler< T >::subId

The Subscription Id.

Used to unsubscribe from events.

Constructor & Destructor Documentation

◆ EventHandler()

template<class T >
EventHandler< T >::EventHandler ( )
inline

Construct a new Event Handler object.

It will not compile if you try it with a class that does not derive from IEvent

Member Function Documentation

◆ fire()

template<class T >
void EventHandler< T >::fire ( T & event)
inline

Fire an event.

Cascade the event to all of the listeners

Parameters
eventthe event

◆ getTypeInfo()

template<class T >
const std::type_info * EventHandler< T >::getTypeInfo ( ) const
inline

Get the Type Info of T.

Returns the type info of T

Returns
const std::type_info* the type info of T

◆ subscribe() [1/2]

template<class T >
subId EventHandler< T >::subscribe ( callbackType && func)
inline

Subscribe to an event.

Subscribe to an event for rvalue functions

Parameters
functhe function that will listen to events
Returns
subId the id to use for unsubscribe

◆ subscribe() [2/2]

template<class T >
subId EventHandler< T >::subscribe ( const callbackType & func)
inline

Subscribe to an event.

Subscribe to an event for lvalue functions

Parameters
functhe function that will listen to events
Returns
subId the id to use for unsubscribe

◆ unsubscribe()

template<class T >
void EventHandler< T >::unsubscribe ( subId id)
inline

Unsubscribe from an event.

Stop listening from events

Parameters
idthe id of the listener

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