![]() |
Gorgon Game Engine
|
This class provides event mechanism. More...
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... | |
Event & | operator= (const Event &)=delete |
Copy assignment is disabled. More... | |
Event & | operator= (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... | |
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 passedvoid fn(Source_ &source, Params_... params)
the source and parameters will be passedClass members or lambda functions can also be used as event handlers. An event handler can be registered using Register function.
typedef intptr_t Token |
Data type for tokens.
Event | ( | ) |
Constructor for empty source.
|
explicit |
Constructor for class specific source.
|
explicit |
Constructor for class specific source.
~Event | ( | ) |
Destructor.
void Clear | ( | ) |
Removes all registered handlers from this event.
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.
Move assignment, should be called synchronized.
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:
This function can be called from event handler of the same event. The registered event handler will be called immediately in this case.
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())
void Swap | ( | Event< Source_, Params_ > & | other | ) |
Swaps two Events, used for move semantics.
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.