Bromeon
Public Types | Public Member Functions
thor::EventSystem< Event, EventIdentifier > Class Template Reference

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

Inheritance diagram for thor::EventSystem< Event, EventIdentifier >:
Inheritance graph

List of all members.

Public Types

typedef std::tr1::function
< void(const Event &) > 
Listener
 Function type of listeners associated with Event.

Public Member Functions

 EventSystem ()
 Default constructor.
void TriggerEvent (const Event &event)
 Fires an event.
Connection Connect (const EventIdentifier &trigger, const Listener &listener)
 Connects an event to the specified listener.
void ClearConnections (EventIdentifier identifier)
 Disconnects listeners associated with a given event type.
void ClearAllConnections ()
 Disconnects all listeners.

Detailed Description

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

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

Template Parameters:
EventThe event type. For example, this can be a class or enum.
EventIdentifierThe 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 EventIdentifier and Event are distinct types, you have to provide a global function EventIdentifier ExtractEventIdentifier(const Event&) in the namespace of the Event type definition. Besides, the event system requires less-than operator < for EventIdentifier (enums can use the implicit conversion to int).

Constructor & Destructor Documentation

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

Default constructor.

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


Member Function Documentation

template<typename Event, typename EventIdentifier = Event>
void thor::EventSystem< Event, EventIdentifier >::ClearAllConnections ( )

Disconnects all listeners.

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

template<typename Event, typename EventIdentifier = Event>
void thor::EventSystem< Event, EventIdentifier >::ClearConnections ( EventIdentifier  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 EventIdentifier = Event>
Connection thor::EventSystem< Event, EventIdentifier >::Connect ( const EventIdentifier &  trigger,
const Listener listener 
)

Connects an event to the specified listener.

Duplicates are allowed (thus, the listener is invoked multiple times).

Parameters:
triggerThe event you want to associate with a listener function.
listenerThe 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.
template<typename Event, typename EventIdentifier = Event>
void thor::EventSystem< Event, EventIdentifier >::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 file: