qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::router::memh< _RawEvent, _CleanEvent, _Handler > Class Template Reference

Multiple-Event Multiple-Handler router (generic version) More...

#include <router.h>

Public Types

using _EventId = typename _RawEvent::id_type
using _HandlerId = typename _RawEvent::id_handler_type

Public Member Functions

 ~memh () noexcept
 Destructor that cleans up all event resolvers.
template<typename _Func>
void route (_RawEvent &event, _Func const &onError) const
 Routes an event to the appropriate handlers with error handling.
template<typename _Event>
void subscribe (_Handler &handler)
 Subscribe a handler to events of a specific type.
template<typename _Event>
void unsubscribe (_Handler &handler) const
 Unsubscribe a handler from events of a specific type.
void unsubscribe (_Handler const &handler) const
 Unsubscribe a handler from all event types.
void unsubscribe (_HandlerId const &id) const
 Unsubscribe a handler by ID from all event types.

Detailed Description

template<typename _RawEvent, bool _CleanEvent = true, typename _Handler = void>
class qb::router::memh< _RawEvent, _CleanEvent, _Handler >

Multiple-Event Multiple-Handler router (generic version)

Routes multiple event types to multiple handlers based on event type and handler IDs.

Template Parameters
_RawEventThe raw event base type
_CleanEventWhether to clean up events after routing
_HandlerThe handler type (void for heterogeneous handlers)

Member Function Documentation

◆ route()

template<typename _RawEvent, bool _CleanEvent = true, typename _Handler = void>
template<typename _Func>
void qb::router::memh< _RawEvent, _CleanEvent, _Handler >::route ( _RawEvent & event,
_Func const & onError ) const
inline

Routes an event to the appropriate handlers with error handling.

Template Parameters
_FuncType of the error handling function
Parameters
eventThe event to route
onErrorFunction to call if the event type is not registered

◆ subscribe()

template<typename _RawEvent, bool _CleanEvent = true, typename _Handler = void>
template<typename _Event>
void qb::router::memh< _RawEvent, _CleanEvent, _Handler >::subscribe ( _Handler & handler)
inline

Subscribe a handler to events of a specific type.

Template Parameters
_EventThe event type to subscribe to
Parameters
handlerThe handler to subscribe

◆ unsubscribe() [1/3]

template<typename _RawEvent, bool _CleanEvent = true, typename _Handler = void>
template<typename _Event>
void qb::router::memh< _RawEvent, _CleanEvent, _Handler >::unsubscribe ( _Handler & handler) const
inline

Unsubscribe a handler from events of a specific type.

Template Parameters
_EventThe event type to unsubscribe from
Parameters
handlerThe handler to unsubscribe

◆ unsubscribe() [2/3]

template<typename _RawEvent, bool _CleanEvent = true, typename _Handler = void>
void qb::router::memh< _RawEvent, _CleanEvent, _Handler >::unsubscribe ( _Handler const & handler) const
inline

Unsubscribe a handler from all event types.

Parameters
handlerThe handler to unsubscribe

◆ unsubscribe() [3/3]

template<typename _RawEvent, bool _CleanEvent = true, typename _Handler = void>
void qb::router::memh< _RawEvent, _CleanEvent, _Handler >::unsubscribe ( _HandlerId const & id) const
inline

Unsubscribe a handler by ID from all event types.

Parameters
idThe ID of the handler to unsubscribe