aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/EventHandler.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-20 22:33:14 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-20 22:33:14 +0100
commit48f69cedaf16038d980071d43d32e22caae44c17 (patch)
treed52db1e10dc82eb02c7d22dbe3fa8648c457c2ce /src/crepe/api/EventHandler.h
parent6808307cf65a4b686621f08a58effecc0a9c6bb8 (diff)
parentda379a58033c0ef3c9c854326a3fca25d6e54319 (diff)
merge `loek/scripts` into `loek/collision-system`
Diffstat (limited to 'src/crepe/api/EventHandler.h')
-rw-r--r--src/crepe/api/EventHandler.h46
1 files changed, 15 insertions, 31 deletions
diff --git a/src/crepe/api/EventHandler.h b/src/crepe/api/EventHandler.h
index 0ab90de..ef659fd 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.
*
@@ -11,8 +13,9 @@
* indicating whether the event is handled.
*
* \tparam EventType The type of event this handler will handle.
+ *
+ * Returning \c false from an event handler results in the event being propogated to other listeners for the same event type, while returning \c true stops propogation altogether.
*/
-// TODO: typedef
template <typename EventType>
using EventHandler = std::function<bool(const EventType & e)>;
@@ -21,7 +24,7 @@ using EventHandler = std::function<bool(const EventType & e)>;
* \brief An abstract base class for event handler wrappers.
*
* This class provides the interface for handling events. Derived classes must implement the
- * `call()` method to process events and the `get_type()` method to return the handler's type.
+ * `call()` method to process events
*/
class IEventHandlerWrapper {
public:
@@ -40,15 +43,6 @@ public:
*/
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;
-
private:
/**
* \brief The method responsible for handling the event.
@@ -81,8 +75,7 @@ public:
*
* \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:
/**
@@ -93,20 +86,11 @@ 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));
- }
-
- /**
- * \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; }
+ bool call(const Event & e) override;
//! The event handler function.
- EventHandler<EventType> m_handler;
- //! The type name of the handler function.
- const std::string m_handler_type;
+ EventHandler<EventType> handler;
};
+
+} // namespace crepe
+
+#include "EventHandler.hpp"