aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/EventHandler.h
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-16 13:55:47 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-16 13:55:47 +0100
commit6e7003c73110cf9ad7e4c72de703dfdc2292d8ca (patch)
tree124818d404aab746cfd36a544f5c8241a4306b15 /src/crepe/api/EventHandler.h
parent337a957a9e605f16287506b6afda56950e562db3 (diff)
added hpp files and auto
Diffstat (limited to 'src/crepe/api/EventHandler.h')
-rw-r--r--src/crepe/api/EventHandler.h53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/crepe/api/EventHandler.h b/src/crepe/api/EventHandler.h
index 0ab90de..2a684c0 100644
--- a/src/crepe/api/EventHandler.h
+++ b/src/crepe/api/EventHandler.h
@@ -1,9 +1,11 @@
#pragma once
-#include "Event.h"
+
#include <functional>
-#include <iostream>
-#include <typeindex>
+#include <string>
+
+#include "Event.h"
+namespace crepe {
/**
* \brief A type alias for an event handler function.
*
@@ -12,7 +14,6 @@
*
* \tparam EventType The type of event this handler will handle.
*/
-// TODO: typedef
template <typename EventType>
using EventHandler = std::function<bool(const EventType & e)>;
@@ -25,12 +26,12 @@ using EventHandler = std::function<bool(const EventType & e)>;
*/
class IEventHandlerWrapper {
public:
- /**
+ /**
* \brief Virtual destructor for IEventHandlerWrapper.
*/
- virtual ~IEventHandlerWrapper() = default;
+ virtual ~IEventHandlerWrapper() = default;
- /**
+ /**
* \brief Executes the handler with the given event.
*
* This method calls the `call()` method of the derived class, passing the event to the handler.
@@ -38,19 +39,19 @@ public:
* \param e The event to be processed.
* \return A boolean value indicating whether the event is handled.
*/
- bool exec(const Event & e);
+ bool exec(const Event & e);
- /**
+ /**
* \brief Get the type of the event handler.
*
* This method returns the type of the event handler as a string.
*
* \return A string representing the handler's type.
*/
- virtual std::string get_type() const = 0;
+ virtual std::string get_type() const = 0;
private:
- /**
+ /**
* \brief The method responsible for handling the event.
*
* This method is implemented by derived classes to process the event.
@@ -58,7 +59,7 @@ private:
* \param e The event to be processed.
* \return A boolean value indicating whether the event is handled.
*/
- virtual bool call(const Event & e) = 0;
+ virtual bool call(const Event & e) = 0;
};
/**
@@ -74,18 +75,17 @@ private:
template <typename EventType>
class EventHandlerWrapper : public IEventHandlerWrapper {
public:
- /**
+ /**
* \brief Constructs an EventHandlerWrapper with a given handler.
*
* The constructor takes an event handler function and stores it in the wrapper.
*
* \param handler The event handler function.
*/
- explicit EventHandlerWrapper(const EventHandler<EventType> & handler)
- : m_handler(handler), m_handler_type(m_handler.target_type().name()) {}
+ explicit EventHandlerWrapper(const EventHandler<EventType> & handler);
private:
- /**
+ /**
* \brief Calls the stored event handler with the event.
*
* This method casts the event to the appropriate type and calls the handler.
@@ -93,20 +93,23 @@ private:
* \param e The event to be handled.
* \return A boolean value indicating whether the event is handled.
*/
- bool call(const Event & e) override {
- return m_handler(static_cast<const EventType &>(e));
- }
+ bool call(const Event & e) override;
- /**
+ /**
* \brief Returns the type of the handler.
*
* This method returns a string representing the type of the event handler.
*
* \return The handler type as a string.
*/
- std::string get_type() const override { return m_handler_type; }
- //! The event handler function.
- EventHandler<EventType> m_handler;
- //! The type name of the handler function.
- const std::string m_handler_type;
+ std::string get_type() const override;
+
+ //! The event handler function.
+ EventHandler<EventType> m_handler;
+ //! The type name of the handler function.
+ const std::string m_handler_type;
};
+
+} // namespace crepe
+
+#include "EventHandler.hpp"