Line data Source code
1 : // Copyright 2024 Accenture. 2 : 3 : /** 4 : * \ingroup async 5 : */ 6 : #ifndef GUARD_44C9F9DB_11A5_4094_AB12_8B02A7C1F937 7 : #define GUARD_44C9F9DB_11A5_4094_AB12_8B02A7C1F937 8 : 9 : #include "async/Types.h" 10 : 11 : namespace async 12 : { 13 : /** 14 : * A template class that encapsulates specific event behavior, allowing setEvent to be used without 15 : * explicitly specifying the eventMask. 16 : * 17 : * \tparam EventDispatcher EventDispatcher class, from which the Event is encapsulated. 18 : * \tparam Event Event number to encapsulate. 19 : */ 20 : template<typename EventDispatcher, size_t Event> 21 : class EventPolicy 22 : { 23 : public: 24 : using EventDispatcherType = EventDispatcher; 25 : using HandlerFunctionType = typename EventDispatcher::HandlerFunctionType; 26 : 27 : static EventMaskType const EVENT_MASK = static_cast<EventMaskType>(1U << Event); 28 : 29 : explicit EventPolicy(EventDispatcher& eventDispatcher); 30 : 31 : void setEventHandler(HandlerFunctionType handlerFunction); 32 : void removeEventHandler(); 33 : 34 : void setEvent(); 35 : 36 : private: 37 : EventDispatcher& _eventDispatcher; 38 : }; 39 : 40 : /** 41 : * Inline implementations. 42 : */ 43 : template<typename EventDispatcher, size_t Event> 44 195 : inline EventPolicy<EventDispatcher, Event>::EventPolicy(EventDispatcher& eventDispatcher) 45 195 : : _eventDispatcher(eventDispatcher) 46 : {} 47 : 48 : template<typename EventDispatcher, size_t Event> 49 : inline void 50 388 : EventPolicy<EventDispatcher, Event>::setEventHandler(HandlerFunctionType const handlerFunction) 51 : { 52 388 : _eventDispatcher.setEventHandler(Event, handlerFunction); 53 386 : } 54 : 55 : template<typename EventDispatcher, size_t Event> 56 2 : inline void EventPolicy<EventDispatcher, Event>::removeEventHandler() 57 : { 58 2 : _eventDispatcher.removeEventHandler(Event); 59 : } 60 : 61 : template<typename EventDispatcher, size_t Event> 62 19 : inline void EventPolicy<EventDispatcher, Event>::setEvent() 63 : { 64 19 : _eventDispatcher.setEvents(EVENT_MASK); 65 9 : } 66 : 67 : } // namespace async 68 : 69 : #endif // GUARD_44C9F9DB_11A5_4094_AB12_8B02A7C1F937