-
Notifications
You must be signed in to change notification settings - Fork 0
SFME::Mediator
Sztergbaum Roman edited this page Feb 4, 2018
·
66 revisions
Welcome to the page of the SFME::Mediator module
A complete example can be found here
Content for EventManager.
template <typename TEvent, typename ... Args>
void emit(Args &&... args) noexcept;- TEvent: The type of event you wish to broadcast.
- Args: The arguments possibly necessary to the creation of the TEvent object.
- TEvent must be a class derived from BaseEvent class.
#include <SFME/mediator/mediator.hpp>
#include "InputEvent.hpp"
#include "ShutdownEvent.hpp"
int main()
{
sfme::mediator::EventManager evtMgr;
// InputEvent constructor take 1 arguments
// constructor -> InputEvent(char keycode);
evtMgr.emit<InputEvent>('a');
// ShutdownEvent is default constructible
evtMgr.emit<ShutdownEvent>();
return 0;
}
template <typename TEvent, typename TReceiver>
void subscribe(TReceiver &receiver) noexcept;- TEvent: Represents the type of event you want to subscribe.
- Receiver: Represents the instance of the class that wishes to subscribe to this type of event.
- TEvent must be a class derived from BaseEvent class.
- The instance that uses the subscribe member function must be derived from the Receiver class. The use of the CRTP is here only for readability.
#include <SFME/mediator/mediator.hpp>
#include "InputEvent.hpp"
class Example : public sfme::mediator::Receiver<Example>
{
Example(sfme::mediator::EventManager& evtMgr) noexcept
{
evtMgr.subscribe<InputEvent>(*this);
}
};
int main()
{
sfme::mediator::EventManager evtMgr;
Example ex(evtMgr);
return 0;
}Content for BaseEvent.
Content for Receiver.
Content of the examples.