aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include/eventHandler.h
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-25 20:59:34 +0200
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-10-25 20:59:34 +0200
commit15a4c4a1cf67e13be53ef423c51c56488f332ea9 (patch)
tree661084fc8171089ce32bf779f2b3a85d634b38e4 /mwe/events/include/eventHandler.h
parentf472e0ba3bf54fc5055cf9f08925bed3f98a1dbc (diff)
parentb3b762a34e7ccb4a0dcd041a693ac7180af16002 (diff)
merge conficts fixed
Diffstat (limited to 'mwe/events/include/eventHandler.h')
-rw-r--r--mwe/events/include/eventHandler.h50
1 files changed, 24 insertions, 26 deletions
diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h
index e5b99d6..7414801 100644
--- a/mwe/events/include/eventHandler.h
+++ b/mwe/events/include/eventHandler.h
@@ -4,45 +4,43 @@
#include <functional>
#include <iostream>
-template<typename EventType>
-using EventHandler = std::function<void(const EventType& e)>;
+template <typename EventType>
+using EventHandler = std::function<void(const EventType & e)>;
class IEventHandlerWrapper {
public:
- virtual ~IEventHandlerWrapper() = default;
+ virtual ~IEventHandlerWrapper() = default;
- void exec(const Event& e);
+ void exec(const Event & e);
- virtual std::string getType() const = 0;
- virtual bool isDestroyOnSuccess() 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>
+template <typename EventType>
class EventHandlerWrapper : public IEventHandlerWrapper {
public:
- explicit EventHandlerWrapper(const EventHandler<EventType>& handler, const bool destroyOnSuccess = false)
- : m_handler(handler)
- , m_handlerType(m_handler.target_type().name())
- , m_destroyOnSuccess(destroyOnSuccess)
- {
+ explicit EventHandlerWrapper(const EventHandler<EventType> & handler,
+ const bool destroyOnSuccess = false)
+ : m_handler(handler), m_handlerType(m_handler.target_type().name()),
+ m_destroyOnSuccess(destroyOnSuccess) {
// std::cout << m_handlerType << std::endl;
}
private:
- void call(const Event& e) override
- {
- if (e.getEventType() == EventType::getStaticEventType()) {
- m_handler(static_cast<const EventType&>(e));
- }
- }
-
- 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 };
+ void call(const Event & e) override {
+ if (e.getEventType() == EventType::getStaticEventType()) {
+ m_handler(static_cast<const EventType &>(e));
+ }
+ }
+
+ 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};
};