mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-04 03:15:59 -04:00
Minor updates to comments, template parameters names in EventDispatching.hh
This commit is contained in:
parent
a8edb0fe66
commit
3c903e101f
@ -30,41 +30,42 @@ namespace SDL2pp {
|
|||||||
*/
|
*/
|
||||||
namespace Private {
|
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 <typename EventHandler, typename EventType>
|
template <typename EventHandlerType, typename EventType>
|
||||||
auto DispatchEventHandlerFunctor(const EventType &event, EventHandler&& eventHandler) -> typename std::enable_if<IsEventHandlerFunctor<EventHandler, EventType>::value>::type
|
auto DispatchEventHandlerFunctor(const EventType &event, EventHandlerType&& eventHandler) -> typename std::enable_if<IsEventHandlerFunctor<EventHandlerType, EventType>::value>::type
|
||||||
{
|
{
|
||||||
eventHandler(event);
|
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 <typename EventHandler, typename EventType>
|
template <typename EventHandlerType, typename EventType>
|
||||||
auto DispatchEventHandlerFunctor(const EventType &, EventHandler&&) -> typename std::enable_if<!IsEventHandlerFunctor<EventHandler, EventType>::value>::type
|
auto DispatchEventHandlerFunctor(const EventType &, EventHandlerType&&) -> typename std::enable_if<!IsEventHandlerFunctor<EventHandlerType, EventType>::value>::type
|
||||||
{
|
{
|
||||||
// no-op
|
// 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 <typename EventHandler, typename EventType>
|
template <typename EventHandlerType, typename EventType>
|
||||||
auto DispatchEventHandlerObject(const EventType &event, EventHandler&& eventHandler) -> typename std::enable_if<IsEventHandlerObject<EventHandler, EventType>::value>::type
|
auto DispatchEventHandlerObject(const EventType &event, EventHandlerType&& eventHandler) -> typename std::enable_if<IsEventHandlerObject<EventHandlerType, EventType>::value>::type
|
||||||
{
|
{
|
||||||
eventHandler.HandleEvent(event);
|
eventHandler.HandleEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Templated function to dynamically dispatch an event of type EventType to an event handler object of type EventHandler.
|
* Templated function to do nothing when trying to dispatch an event of type EventType to an invalid event handler object of type EventHandlerType.
|
||||||
*
|
|
||||||
* This will be only called if 'eventHandler.HandleEvent(event)'
|
|
||||||
*/
|
*/
|
||||||
template <typename EventHandler, typename EventType>
|
template <typename EventHandlerType, typename EventType>
|
||||||
auto DispatchEventHandlerObject(const EventType &, EventHandler&&) -> typename std::enable_if<!IsEventHandlerObject<EventHandler, EventType>::value>::type
|
auto DispatchEventHandlerObject(const EventType &, EventHandlerType&&) -> typename std::enable_if<!IsEventHandlerObject<EventHandlerType, EventType>::value>::type
|
||||||
{
|
{
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
@ -72,13 +73,13 @@ namespace Private {
|
|||||||
/*
|
/*
|
||||||
* Templated class to dispatch an event to a given event handler:
|
* 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
|
* 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
|
* EvenTypes is a tuple containing a list of valid event types
|
||||||
*
|
*
|
||||||
* Basically, this class would be roughly the equivalent of the following pseudocode:
|
* 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;
|
* auto validEventHandler = false;
|
||||||
*
|
*
|
||||||
* for (auto eventType : eventTypes) {
|
* for (auto eventType : eventTypes) {
|
||||||
@ -92,7 +93,7 @@ namespace Private {
|
|||||||
* if (!validEventHandler) throw;
|
* if (!validEventHandler) throw;
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
template <typename EventHandler, bool ValidEventHandler, typename... EventTypes>
|
template <bool ValidEventHandler, typename EventHandlerType, typename... EventTypes>
|
||||||
struct EventDispatcher;
|
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
|
* The tail then is passed to another expansion of EventDispatcher along with the calculated value of IsEventHandler
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
template <typename EventHandler, bool ValidEventHandler, typename EventType, typename... EventTypes>
|
template <bool ValidEventHandler, typename EventHandlerType, typename EventType, typename... EventTypes>
|
||||||
struct EventDispatcher<EventHandler, ValidEventHandler, std::tuple<EventType, EventTypes...>> {
|
struct EventDispatcher<ValidEventHandler, EventHandlerType, std::tuple<EventType, EventTypes...>> {
|
||||||
static constexpr bool IsValidEventHandler = ValidEventHandler || IsEventHandler<EventHandler, EventType>::value;
|
static constexpr bool IsValidEventHandler = ValidEventHandler || IsEventHandler<EventHandlerType, EventType>::value;
|
||||||
|
|
||||||
using Filter = EventTypeFilter<EventType>;
|
using Filter = EventTypeFilter<EventType>;
|
||||||
|
|
||||||
static void DispatchEvent(const SDL_Event &event, EventHandler&& eventHandler) {
|
static void DispatchEvent(const SDL_Event &event, EventHandlerType&& eventHandler) {
|
||||||
if (Filter::ShouldHandleEvent(event)) {
|
if (Filter::ShouldHandleEvent(event)) {
|
||||||
DispatchEventHandlerFunctor(Filter::GetEventByType(event), std::forward<EventHandler>(eventHandler));
|
DispatchEventHandlerFunctor(Filter::GetEventByType(event), std::forward<EventHandlerType>(eventHandler));
|
||||||
DispatchEventHandlerObject(Filter::GetEventByType(event), std::forward<EventHandler>(eventHandler));
|
DispatchEventHandlerObject(Filter::GetEventByType(event), std::forward<EventHandlerType>(eventHandler));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventDispatcher<EventHandler, IsValidEventHandler, std::tuple<EventTypes...>>::DispatchEvent(event, std::forward<EventHandler>(eventHandler));
|
EventDispatcher<IsValidEventHandler, EventHandlerType, std::tuple<EventTypes...>>::DispatchEvent(event, std::forward<EventHandlerType>(eventHandler));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -126,11 +127,11 @@ namespace Private {
|
|||||||
* is placed in the IsValidEventHandler variable, finally when an event gets dispatched
|
* 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.
|
* an static_assert happens to verify if the event handler actually handled any events.
|
||||||
*/
|
*/
|
||||||
template <typename EventHandler, bool ValidEventHandler>
|
template <bool ValidEventHandler, typename EventHandlerType>
|
||||||
struct EventDispatcher<EventHandler, ValidEventHandler, std::tuple<>> {
|
struct EventDispatcher<ValidEventHandler, EventHandlerType, std::tuple<>> {
|
||||||
static constexpr auto IsValidEventHandler = ValidEventHandler;
|
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");
|
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.
|
* Templated class expand a list of event handlers so they can be dispatched.
|
||||||
*/
|
*/
|
||||||
template <typename... EventHandlers>
|
template <typename... EventHandlerTypes>
|
||||||
void DispatchEvent(const SDL_Event &, EventHandlers&&...);
|
void DispatchEvent(const SDL_Event &, EventHandlerTypes&&...);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Instantiation of the class to expand a list of event handlers so they can be dispatched.
|
* 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.
|
* This "peels" the first event handler from the arguments, dispatchs it and then expands the tail of the list.
|
||||||
*/
|
*/
|
||||||
template <typename EventHandler, typename... EventHandlers>
|
template <typename EventHandlerType, typename... EventHandlerTypes>
|
||||||
void DispatchEvent(const SDL_Event &event, EventHandler&& eventHandler, EventHandlers&&... eventHandlers) {
|
void DispatchEvent(const SDL_Event &event, EventHandlerType&& eventHandler, EventHandlerTypes&&... eventHandlers) {
|
||||||
EventDispatcher<EventHandler, false, ValidEventTypes>::DispatchEvent(event, std::forward<EventHandler>(eventHandler));
|
EventDispatcher<false, EventHandlerType, ValidEventTypes>::DispatchEvent(event, std::forward<EventHandlerType>(eventHandler));
|
||||||
DispatchEvent(event, eventHandlers...);
|
DispatchEvent(event, eventHandlers...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user