Mountain  1.0.0
Simple C++ 2D Game Framework
Mountain::Event< Args > Class Template Reference

Encapsulates a delegate system similar to its C# implementation. More...

#include <event.hpp>

Public Types

using FunctionT = void(Args...)
 Signature of the event function.
 
using StdFunctionT = std::function< FunctionT >
 

Public Member Functions

void Invoke (Args... args) const
 Invokes the currently registered events with the provided parameters. More...
 
void Clear ()
 Clears the event list.
 
void operator() (Args... args) const
 Invokes the currently registered events with the provided parameters. Effectively the same as calling Invoke.
 
Eventoperator+= (StdFunctionT func)
 Adds a function to the event list. More...
 
Eventoperator-= (const StdFunctionT &func)
 Removes a function from the event list. More...
 

Detailed Description

template<typename... Args>
class Mountain::Event< Args >

Encapsulates a delegate system similar to its C# implementation.

It works by having an underlying list of functions that always return void and have the provided types as arguments The += and -= operators can be used to respectively add and remove events to the list

Event variable names should always start with 'on', for example: onUpdate, onReload, onCollision, etc...

Template Parameters
ArgsEvent function arguments
See also
C# events

Definition at line 25 of file event.hpp.

Member Function Documentation

◆ Invoke()

template<typename... Args>
void Mountain::Event< Args >::Invoke ( Args...  args) const

Invokes the currently registered events with the provided parameters.

Parameters
argsParameters

◆ operator+=()

template<typename... Args>
Event& Mountain::Event< Args >::operator+= ( StdFunctionT  func)

Adds a function to the event list.

Parameters
funcFunction
Returns
This

◆ operator-=()

template<typename... Args>
Event& Mountain::Event< Args >::operator-= ( const StdFunctionT &  func)

Removes a function from the event list.

Parameters
funcFunction
Returns
This

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