From 3c903e101fb6bb383abb19f479805c21f910c622 Mon Sep 17 00:00:00 2001 From: Vraiment Date: Tue, 8 Aug 2017 23:01:08 -0700 Subject: [PATCH] Minor updates to comments, template parameters names in EventDispatching.hh --- SDL2pp/Private/EventDispatching.hh | 67 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/SDL2pp/Private/EventDispatching.hh b/SDL2pp/Private/EventDispatching.hh index d91a40b..9108e2c 100644 --- a/SDL2pp/Private/EventDispatching.hh +++ b/SDL2pp/Private/EventDispatching.hh @@ -30,41 +30,42 @@ namespace SDL2pp { */ namespace Private { /* - * Templated function to dynamically dispatch an event of type EventType to an event handler functor of type EventHandler. + * Templated function to dynamically dispatch an event of type EventType to an event handler functor of type EventHandlerType. * - * This will be only called if 'eventHandler(event)' + * This will be only called if 'eventHandler(event)' can be called */ - template - auto DispatchEventHandlerFunctor(const EventType &event, EventHandler&& eventHandler) -> typename std::enable_if::value>::type + template + auto DispatchEventHandlerFunctor(const EventType &event, EventHandlerType&& eventHandler) -> typename std::enable_if::value>::type { eventHandler(event); } /* - * Templated function to do nothing when trying to dispatch an event of type EventType to an invalid event handler functor of type EventHandler. + * Templated function to do nothing when trying to dispatch an event of type EventType to an invalid event handler functor of type EventHandlerType. */ - template - auto DispatchEventHandlerFunctor(const EventType &, EventHandler&&) -> typename std::enable_if::value>::type + template + auto DispatchEventHandlerFunctor(const EventType &, EventHandlerType&&) -> typename std::enable_if::value>::type { // no-op } /* - * Templated function to do nothing when trying to dispatch an event of type EventType to an invalid event handler object of type EventHandler. + * Templated function to dynamically dispatch an event of type EventType to an event handler object of type EventHandlerType. + * + * This will be only called if 'eventHandler.HandleEvent(event)' can be called */ - template - auto DispatchEventHandlerObject(const EventType &event, EventHandler&& eventHandler) -> typename std::enable_if::value>::type + template + auto DispatchEventHandlerObject(const EventType &event, EventHandlerType&& eventHandler) -> typename std::enable_if::value>::type { eventHandler.HandleEvent(event); } + /* - * Templated function to dynamically dispatch an event of type EventType to an event handler object of type EventHandler. - * - * This will be only called if 'eventHandler.HandleEvent(event)' + * Templated function to do nothing when trying to dispatch an event of type EventType to an invalid event handler object of type EventHandlerType. */ - template - auto DispatchEventHandlerObject(const EventType &, EventHandler&&) -> typename std::enable_if::value>::type + template + auto DispatchEventHandlerObject(const EventType &, EventHandlerType&&) -> typename std::enable_if::value>::type { // no-op } @@ -72,13 +73,13 @@ namespace Private { /* * Templated class to dispatch an event to a given event handler: * - * EventHandler is the type of the event handler * ValidEventHandler is a boolean to detect if the event was actially valid for any of the event types + * EventHandlerType is the type of the event handler * EvenTypes is a tuple containing a list of valid event types * * Basically, this class would be roughly the equivalent of the following pseudocode: * - * DispatchEvent(SDL_Event event, EventHandler eventHandler, EventTypes eventTypes) { + * DispatchEvent(SDL_Event event, EventHandlerType eventHandler, EventTypes eventTypes) { * auto validEventHandler = false; * * for (auto eventType : eventTypes) { @@ -92,7 +93,7 @@ namespace Private { * if (!validEventHandler) throw; * } */ - template + template struct EventDispatcher; /* @@ -102,20 +103,20 @@ namespace Private { * The tail then is passed to another expansion of EventDispatcher along with the calculated value of IsEventHandler * */ - template - struct EventDispatcher> { - static constexpr bool IsValidEventHandler = ValidEventHandler || IsEventHandler::value; + template + struct EventDispatcher> { + static constexpr bool IsValidEventHandler = ValidEventHandler || IsEventHandler::value; using Filter = EventTypeFilter; - static void DispatchEvent(const SDL_Event &event, EventHandler&& eventHandler) { + static void DispatchEvent(const SDL_Event &event, EventHandlerType&& eventHandler) { if (Filter::ShouldHandleEvent(event)) { - DispatchEventHandlerFunctor(Filter::GetEventByType(event), std::forward(eventHandler)); - DispatchEventHandlerObject(Filter::GetEventByType(event), std::forward(eventHandler)); + DispatchEventHandlerFunctor(Filter::GetEventByType(event), std::forward(eventHandler)); + DispatchEventHandlerObject(Filter::GetEventByType(event), std::forward(eventHandler)); } - EventDispatcher>::DispatchEvent(event, std::forward(eventHandler)); + EventDispatcher>::DispatchEvent(event, std::forward(eventHandler)); } }; @@ -126,11 +127,11 @@ namespace Private { * is placed in the IsValidEventHandler variable, finally when an event gets dispatched * an static_assert happens to verify if the event handler actually handled any events. */ - template - struct EventDispatcher> { + template + struct EventDispatcher> { static constexpr auto IsValidEventHandler = ValidEventHandler; - static void DispatchEvent(const SDL_Event &, EventHandler&&) { + static void DispatchEvent(const SDL_Event &, EventHandlerType&&) { static_assert(IsValidEventHandler, "One of the given event handlers is not a valid one"); } }; @@ -138,17 +139,17 @@ namespace Private { /* * Templated class expand a list of event handlers so they can be dispatched. */ - template - void DispatchEvent(const SDL_Event &, EventHandlers&&...); + template + void DispatchEvent(const SDL_Event &, EventHandlerTypes&&...); /* * Instantiation of the class to expand a list of event handlers so they can be dispatched. * * This "peels" the first event handler from the arguments, dispatchs it and then expands the tail of the list. */ - template - void DispatchEvent(const SDL_Event &event, EventHandler&& eventHandler, EventHandlers&&... eventHandlers) { - EventDispatcher::DispatchEvent(event, std::forward(eventHandler)); + template + void DispatchEvent(const SDL_Event &event, EventHandlerType&& eventHandler, EventHandlerTypes&&... eventHandlers) { + EventDispatcher::DispatchEvent(event, std::forward(eventHandler)); DispatchEvent(event, eventHandlers...); }