Saga
Saga Game Engine
Loading...
Searching...
No Matches
Saga::EventMap Class Reference

A mapping between events (which are ints under the hood) and callbacks. More...

#include <eventmap.h>

Public Types

enum  Id : uint64_t
 
typedef Map::iterator iterator
 
typedef Map::const_iterator const_iterator
 
typedef Map::value_type value_type
 

Public Member Functions

const_iterator begin () const
 
const_iterator end () const
 
iterator begin ()
 
iterator end ()
 
template<typename Event >
iterator find (Event event)
 
template<typename Event >
const_iterator find (Event event) const
 
template<typename Event , typename ... DataType>
Id addListener (Event event, std::shared_ptr< std::function< void(DataType...)> > callbackFunc)
 Add a listener to a specific event.
 
template<typename Event >
void removeListener (Event event, Id id)
 Remove a listener from an event, by their id.
 
template<typename Event , typename ... DataType>
void invoke (Event event, DataType... args)
 Invoke an event. This calls all listeners attached to that event, with the specified parameters.
 

Detailed Description

A mapping between events (which are ints under the hood) and callbacks.

Member Typedef Documentation

◆ const_iterator

typedef Map::const_iterator Saga::EventMap::const_iterator

◆ iterator

typedef Map::iterator Saga::EventMap::iterator

◆ value_type

typedef Map::value_type Saga::EventMap::value_type

Member Enumeration Documentation

◆ Id

enum Saga::EventMap::Id : uint64_t

Member Function Documentation

◆ addListener()

template<typename Event , typename ... DataType>
Id Saga::EventMap::addListener ( Event  event,
std::shared_ptr< std::function< void(DataType...)> >  callbackFunc 
)
inline

Add a listener to a specific event.

Template Parameters
Eventanything castable to an int.
DataTypethe type of data the callback function accepts.
Parameters
event
callbackFuncthe callback that happens when this event is triggered.
Returns
Id the id of the listener. This can be use to remove the listener later.

◆ begin() [1/2]

iterator Saga::EventMap::begin ( )
inline

◆ begin() [2/2]

const_iterator Saga::EventMap::begin ( ) const
inline

◆ end() [1/2]

iterator Saga::EventMap::end ( )
inline

◆ end() [2/2]

const_iterator Saga::EventMap::end ( ) const
inline

◆ find() [1/2]

template<typename Event >
iterator Saga::EventMap::find ( Event  event)
inline

◆ find() [2/2]

template<typename Event >
const_iterator Saga::EventMap::find ( Event  event) const
inline

◆ invoke()

template<typename Event , typename ... DataType>
void Saga::EventMap::invoke ( Event  event,
DataType...  args 
)
inline

Invoke an event. This calls all listeners attached to that event, with the specified parameters.

Template Parameters
Eventanything castable to an int.
DataType
Parameters
event
argsthe parameters used in calling the listeners.

◆ removeListener()

template<typename Event >
void Saga::EventMap::removeListener ( Event  event,
Id  id 
)
inline

Remove a listener from an event, by their id.

Template Parameters
Eventanything castable to an int.
Parameters
event
id

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