Gorgon Game Engine
Event< Source_, Params_ > Class Template Reference

This class provides event mechanism. More...

Inheritance diagram for Event< Source_, Params_ >:
[legend]

Public Types

typedef intptr_t Token
 Data type for tokens. More...
 

Public Member Functions

 Event ()
 Constructor for empty source. More...
 
 Event (const Event &)=delete
 Copy constructor is disabled. More...
 
 Event (Event &&event)
 Move constructor. More...
 
template<class S_ = Source_>
 Event (typename std::enable_if<!std::is_same< S_, void >::value, S_ >::type &source)
 Constructor for class specific source. More...
 
template<class S_ = Source_>
 Event (typename std::enable_if<!std::is_same< S_, void >::value, S_ >::type *source)
 Constructor for class specific source. More...
 
 ~Event ()
 Destructor. More...
 
void Clear ()
 Removes all registered handlers from this event. More...
 
void operator() (Params_... args)
 Fire this event. More...
 
Eventoperator= (const Event &)=delete
 Copy assignment is disabled. More...
 
Eventoperator= (Event &&other)
 Move assignment, should be called synchronized. More...
 
template<class C_ , typename... A_>
Token Register (C_ &c, void(C_::*fn)(A_...))
 Registers a new function to be called when this event is triggered. More...
 
template<class F_ >
Token Register (F_ fn)
 Registers a new function to be called when this event is triggered. More...
 
void Swap (Event &other)
 Swaps two Events, used for move semantics. More...
 
void Unregister (Token token)
 Unregisters the given marked with the given token. More...
 

Static Public Attributes

static const Token EmptyToken
 value for an empty token More...
 

Detailed Description

template<class Source_ = void, typename... Params_>
class Gorgon::Event< Source_, Params_ >

This class provides event mechanism.

Different function signatures are allowed to as event handlers. These are:

  • void fn() neither event source nor event parameters are supplied.
  • void fn(Params_... params) parameters will be passed
  • void fn(Source_ &source, Params_... params) the source and parameters will be passed

Class members or lambda functions can also be used as event handlers. An event handler can be registered using Register function.

Member Typedef Documentation

◆ Token

typedef intptr_t Token

Data type for tokens.

Constructor & Destructor Documentation

◆ Event() [1/5]

Event ( )

Constructor for empty source.

◆ Event() [2/5]

Event ( typename std::enable_if<!std::is_same< S_, void >::value, S_ >::type &  source)
explicit

Constructor for class specific source.

◆ Event() [3/5]

Event ( typename std::enable_if<!std::is_same< S_, void >::value, S_ >::type *  source)
explicit

Constructor for class specific source.

◆ Event() [4/5]

Event ( Event< Source_, Params_ > &&  event)

Move constructor.

◆ ~Event()

~Event ( )

Destructor.

◆ Event() [5/5]

Event ( const Event< Source_, Params_ > &  )
delete

Copy constructor is disabled.

Member Function Documentation

◆ Clear()

void Clear ( )

Removes all registered handlers from this event.

◆ operator()()

void operator() ( Params_...  args)

Fire this event.

This function will never allow recursive firing from the same thread, i.e. an event handler cannot cause this event to be fired again.

◆ operator=() [1/2]

Event& operator= ( const Event< Source_, Params_ > &  )
delete

Copy assignment is disabled.

◆ operator=() [2/2]

Event& operator= ( Event< Source_, Params_ > &&  other)

Move assignment, should be called synchronized.

◆ Register() [1/2]

Token Register ( C_ &  c,
void(C_::*)(A_...)  fn 
)

Registers a new function to be called when this event is triggered.

This variant is designed to be used with member functions. Example:

A a;
b.ClickEvent.Register(a, &A::f);

This function can be called from event handler of the same event. The registered event handler will be called immediately in this case.

◆ Register() [2/2]

Token Register ( F_  fn)

Registers a new function to be called when this event is triggered.

This function can be called from event handler of the same event. The registered event handler will be called immediately in this case. If you register a class with a () operator, this class will be copied. If you require call to be made to the same instance, instead of using Register(a) use Register(a, &decltype(a)::operator())

◆ Swap()

void Swap ( Event< Source_, Params_ > &  other)

Swaps two Events, used for move semantics.

◆ Unregister()

void Unregister ( Token  token)

Unregisters the given marked with the given token.

This function performs no operation if the token is not contained within this event. A handler can be unregistered safely while the event is being fired. In this case, if the event that is being deleted is different from the current event handler, the deleted event handler might have already been fired. If not, it will not be fired.

Member Data Documentation

◆ EmptyToken

const Event< C_, P_... >::Token EmptyToken
static

value for an empty token


The documentation for this class was generated from the following file:
Gorgon::Input::Keyboard::Keycodes::A
constexpr Key A
Definition: Keyboard.h:80