aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include/eventHandler.h
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-23 21:13:28 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-23 21:13:28 +0200
commit51c8a51b53a850265955a3e4bc45b40ad3f8c477 (patch)
treec52258a911e52d0a5469942e0a11e373e92af0a9 /mwe/events/include/eventHandler.h
parent94d591b69c45470480db477bc4000ef35019e18b (diff)
custom commit poc working
Diffstat (limited to 'mwe/events/include/eventHandler.h')
-rw-r--r--mwe/events/include/eventHandler.h35
1 files changed, 22 insertions, 13 deletions
diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h
index 03017dd..e5b99d6 100644
--- a/mwe/events/include/eventHandler.h
+++ b/mwe/events/include/eventHandler.h
@@ -1,39 +1,48 @@
#pragma once
+
#include "event.h"
-#include <iostream>
+
#include <functional>
+#include <iostream>
template<typename EventType>
using EventHandler = std::function<void(const EventType& e)>;
-class IEventHandlerWrapper{
+
+class IEventHandlerWrapper {
public:
- void Exec(const Event& e)
- {
- Call(e);
- }
+ virtual ~IEventHandlerWrapper() = default;
+
+ void exec(const Event& e);
- virtual std::string GetType() const = 0;
+ virtual std::string getType() const = 0;
+ virtual bool isDestroyOnSuccess() const = 0;
private:
- virtual void Call(const Event& e) = 0;
+ virtual void call(const Event& e) = 0;
};
template<typename EventType>
class EventHandlerWrapper : public IEventHandlerWrapper {
public:
- explicit EventHandlerWrapper(const EventHandler<EventType>& handler)
+ explicit EventHandlerWrapper(const EventHandler<EventType>& handler, const bool destroyOnSuccess = false)
: m_handler(handler)
- , m_handlerType(m_handler.target_type().name()) {};
+ , m_handlerType(m_handler.target_type().name())
+ , m_destroyOnSuccess(destroyOnSuccess)
+ {
+ // std::cout << m_handlerType << std::endl;
+ }
private:
- void Call(const Event& e) override
+ void call(const Event& e) override
{
- if (e.GetEventType() == EventType::GetStaticEventType()) {
+ if (e.getEventType() == EventType::getStaticEventType()) {
m_handler(static_cast<const EventType&>(e));
}
}
- std::string GetType() const override { return m_handlerType; }
+ std::string getType() const override { return m_handlerType; }
+ bool isDestroyOnSuccess() const { return m_destroyOnSuccess; }
EventHandler<EventType> m_handler;
const std::string m_handlerType;
+ bool m_destroyOnSuccess { false };
};