From 880a7b1fb233a67303ad5a4155dc459f79734762 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Mon, 11 Nov 2024 10:50:40 +0100 Subject: big cleanup events + events are now structs --- src/crepe/api/EventHandler.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/crepe/api/EventHandler.h (limited to 'src/crepe/api/EventHandler.h') diff --git a/src/crepe/api/EventHandler.h b/src/crepe/api/EventHandler.h new file mode 100644 index 0000000..eea1c79 --- /dev/null +++ b/src/crepe/api/EventHandler.h @@ -0,0 +1,38 @@ +#pragma once +#include +#include +#include +#include "Event.h" + +template +using EventHandler = std::function; + +class IEventHandlerWrapper { +public: + virtual ~IEventHandlerWrapper() = default; + + bool exec(const Event & e); + + virtual std::string get_type() const = 0; + +private: + virtual bool call(const Event & e) = 0; +}; + +template +class EventHandlerWrapper : public IEventHandlerWrapper { +public: + explicit EventHandlerWrapper(const EventHandler & handler) + : m_handler(handler), m_handler_type(m_handler.target_type().name()) { + } + +private: + bool call(const Event & e) override { + return m_handler(static_cast(e)); + } + + std::string get_type() const override { return m_handler_type; } + + EventHandler m_handler; + const std::string m_handler_type; +}; -- cgit v1.2.3