List of all members | Public Member Functions
thor::EventSystem< Event, EventId > Class Template Reference

Class for object-oriented handling of user-defined events. More...

Inherits NonCopyable.

Public Member Functions

 EventSystem ()
 Default constructor. More...
 
void triggerEvent (const Event &event)
 Fires an event. More...
 
Connection connect (const EventId &trigger, std::function< void(const Event &)> unaryListener)
 Connects an event to the specified unary listener. More...
 
Connection connect0 (const EventId &trigger, std::function< void()> nullaryListener)
 Connects an event to the specified nullary listener. More...
 
void clearConnections (EventId identifier)
 Disconnects listeners associated with a given event type. More...
 
void clearAllConnections ()
 Disconnects all listeners. More...
 

Detailed Description

template<typename Event, typename EventId = Event>
class thor::EventSystem< Event, EventId >

Class for object-oriented handling of user-defined events.

Template Parameters
EventThe event type. For example, this can be a class or enum.
EventIdThe type that distinguishes different events. This isn't necessarily the event type itself. Consider SFML: The event type would be sf::Event, but the identifier is sf::Event::EventType. When you use custom events where EventId and Event are distinct types, you have to provide a global function EventId getEventId(const Event&) in the namespace of the Event type definition. Besides, the event system requires less-than operator < for EventId (enums can use the implicit conversion to int).

Constructor & Destructor Documentation

template<typename Event , typename EventId = Event>
thor::EventSystem< Event, EventId >::EventSystem ( )

Default constructor.

Sets up an EventSystem where Event and EventId are the same types.

Member Function Documentation

template<typename Event , typename EventId = Event>
void thor::EventSystem< Event, EventId >::clearAllConnections ( )

Disconnects all listeners.

Removes all event-listener connections, independently of the event type.

template<typename Event , typename EventId = Event>
void thor::EventSystem< Event, EventId >::clearConnections ( EventId  identifier)

Disconnects listeners associated with a given event type.

Parameters
identifierThe event type identifier of which you want to remove all connected listeners.
template<typename Event , typename EventId = Event>
Connection thor::EventSystem< Event, EventId >::connect ( const EventId &  trigger,
std::function< void(const Event &)>  unaryListener 
)

Connects an event to the specified unary listener.

Duplicates are allowed (thus, the listener is invoked multiple times). Use this function if your callback should receive the event that triggered it as a parameter.

Parameters
triggerThe event you want to associate with a listener function.
unaryListenerThe function that is invoked when a trigger event is fired.
Returns
A connection which can be used to remove the listener. If you don't need this functionality, just ignore the return value.
Warning
Inside the listener functions, you are not allowed to modify the EventSystem instance that calls them. If you want a callback to insert or remove other callbacks, delay these modifications until the callback returns.
template<typename Event , typename EventId = Event>
Connection thor::EventSystem< Event, EventId >::connect0 ( const EventId &  trigger,
std::function< void()>  nullaryListener 
)

Connects an event to the specified nullary listener.

Duplicates are allowed (thus, the listener is invoked multiple times). Use this function if you don't care about the event that triggered the callback, and thus don't need a parameter for it.

Parameters
triggerThe event you want to associate with a listener function.
nullaryListenerThe function that is invoked when a trigger event is fired.
Returns
A connection which can be used to remove the listener. If you don't need this functionality, just ignore the return value.
Warning
Inside the listener functions, you are not allowed to modify the EventSystem instance that calls them. If you want a callback to insert or remove other callbacks, delay these modifications until the callback returns.
template<typename Event , typename EventId = Event>
void thor::EventSystem< Event, EventId >::triggerEvent ( const Event &  event)

Fires an event.

Calls all listener functions that are currently associated with event.


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