DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs > Class Template Referenceabstract

Typed base class for inter-module events to realize CRTP. More...

#include <Module.h>

+ Inheritance diagram for DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >:

Public Types

using EventListenersType = TypedEventListeners< EventFuncArgs... >
 Type of the manager of event listeners, which relates event listeners (instances of ModuleBase) to their event functions. The event functions expect EventFuncArgs as further arguments.
 
- Public Types inherited from DynExp::InterModuleEventBase
using InterModuleEventPtrType = std::unique_ptr< InterModuleEventBase >
 Pointer type to store an inter-module event (InterModuleEventBase).
 

Public Member Functions

 InterModuleEvent ()=default
 Constructs an inter-module event.
 
 InterModuleEvent (const InterModuleEventBase &Other, ItemIDType CommunicatorID)
 Copy-constrcuts an inter-module event setting the CommunicatorID.
 
virtual ~InterModuleEvent ()
 
virtual InterModuleEventPtrType Clone (ItemIDType CommunicatorID) const override final
 Creates a deep copy of this inter-module instance.
 
virtual size_t GetID () const noexcept override final
 Returns the unique ID of this event type.
 
virtual std::string GetName () const override
 Returns the name of this event type.
 
- Public Member Functions inherited from DynExp::InterModuleEventBase
 InterModuleEventBase ()
 Constructs an inter-module event.
 
 InterModuleEventBase (const InterModuleEventBase &Other, ItemIDType CommunicatorID)
 Copy-constrcuts an inter-module event setting the CommunicatorID.
 
virtual ~InterModuleEventBase ()=0
 
auto GetCommunicatorID () const noexcept
 Getter for CommunicatorID.
 
- Public Member Functions inherited from DynExp::EventBase
 EventBase ()=default
 
virtual ~EventBase ()=0
 
void Invoke (ModuleInstance &Instance) const
 Invokes the event passing the receiving module's instance reference to it. Only to be called from ModuleBase.
 

Static Public Member Functions

static auto ID ()
 Getter for EventID.
 
static size_t Publish (InterModuleEventLibrary &Library)
 Publishes this event type to the InterModuleEventLibrary. This function should not be called manually.
 
static InterModuleEventPtrType Make ()
 Factory function for events of type DerivedEvent.
 
template<typename CallableT >
static void Register (const ModuleBase &Listener, CallableT EventFunc, ItemIDType CommunicatorID=ItemIDNotSet)
 Registers/Subscribes module Listener to the event with the event function EventFunc. Indirectly calls ModuleBase::AddRegisteredEvent(). If a module-communicator combination has already been registered, this registration is updated.
 
static void Deregister (const ModuleBase &Listener)
 Deregisters/unsubscribes module Listener from the event, regardless of the inter-module communicator instance used to register Listener to the event. Indirectly calls ModuleBase::RemoveRegisteredEvent().
 
static void Deregister (const ModuleBase &Listener, ItemIDType CommunicatorID)
 Deregisters/unsubscribes module Listener from the event, removing a single registration for a particular module/inter-module communicator combination. Indirectly calls ModuleBase::RemoveRegisteredEvent().
 

Private Member Functions

virtual void InvokeChild (ModuleInstance &Instance) const override final
 Invokes the event passing the receiving module's instance reference to it. Only to be called from ModuleBase.
 
Override

Override by derived classes.

virtual void InvokeWithParamsChild (ModuleInstance &Instance, EventListenersType::EventFunctionType EventFunc) const =0
 Called by InvokeChild(). Override to call EventFunc with Instance as the first argument and with further arguments of type EventFuncArgs.
 

Static Private Attributes

static const size_t EventID = InterModuleEvent<DerivedEvent, EventFuncArgs...>::Publish(InterModuleEventLibrary::Get())
 Unique ID assigned to this inter-module event.
 
static EventListenersType Listeners
 Holds one EventListenersType instance per derived event, which manages all the subscribers of DerivedEvent.
 

Detailed Description

template<typename DerivedEvent, typename... EventFuncArgs>
class DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >

Typed base class for inter-module events to realize CRTP.

Template Parameters
DerivedEventType of the class derived from InterModuleEvent
...EventFuncArgsTypes of the arguments to be passed to event functions registered/subscribed to DerivedEvent.

Definition at line 1210 of file Module.h.

Member Typedef Documentation

◆ EventListenersType

template<typename DerivedEvent , typename... EventFuncArgs>
using DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::EventListenersType = TypedEventListeners<EventFuncArgs...>

Type of the manager of event listeners, which relates event listeners (instances of ModuleBase) to their event functions. The event functions expect EventFuncArgs as further arguments.

Definition at line 1218 of file Module.h.

Constructor & Destructor Documentation

◆ InterModuleEvent() [1/2]

template<typename DerivedEvent , typename... EventFuncArgs>
DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::InterModuleEvent ( )
default

Constructs an inter-module event.

◆ InterModuleEvent() [2/2]

template<typename DerivedEvent , typename... EventFuncArgs>
DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::InterModuleEvent ( const InterModuleEventBase Other,
ItemIDType  CommunicatorID 
)
inline

Copy-constrcuts an inter-module event setting the CommunicatorID.

Parameters
OtherInter-module event to copy.
CommunicatorIDID of the DynExpInstr::InterModuleCommunicator instance that sends the event.

Definition at line 1228 of file Module.h.

◆ ~InterModuleEvent()

template<typename DerivedEvent , typename... EventFuncArgs>
virtual DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::~InterModuleEvent ( )
inlinevirtual

Definition at line 1231 of file Module.h.

Member Function Documentation

◆ Clone()

template<typename DerivedEvent , typename... EventFuncArgs>
virtual InterModuleEventPtrType DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Clone ( ItemIDType  CommunicatorID) const
inlinefinaloverridevirtual

Creates a deep copy of this inter-module instance.

Parameters
CommunicatorIDID of the DynExpInstr::InterModuleCommunicator instance that sends the event.
Returns
Returns the copy.

Implements DynExp::InterModuleEventBase.

Definition at line 1253 of file Module.h.

◆ Deregister() [1/2]

template<typename DerivedEvent , typename... EventFuncArgs>
static void DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Deregister ( const ModuleBase Listener)
inlinestatic

Deregisters/unsubscribes module Listener from the event, regardless of the inter-module communicator instance used to register Listener to the event. Indirectly calls ModuleBase::RemoveRegisteredEvent().

Parameters
ListenerModule to deregister/unsubscribe.

Definition at line 1271 of file Module.h.

◆ Deregister() [2/2]

template<typename DerivedEvent , typename... EventFuncArgs>
static void DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Deregister ( const ModuleBase Listener,
ItemIDType  CommunicatorID 
)
inlinestatic

Deregisters/unsubscribes module Listener from the event, removing a single registration for a particular module/inter-module communicator combination. Indirectly calls ModuleBase::RemoveRegisteredEvent().

Parameters
ListenerModule to deregister/unsubscribe.
CommunicatorIDRefer to TypedEventListeners::Deregister().

Definition at line 1280 of file Module.h.

◆ GetID()

template<typename DerivedEvent , typename... EventFuncArgs>
virtual size_t DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::GetID ( ) const
inlinefinaloverridevirtualnoexcept

Returns the unique ID of this event type.

Implements DynExp::InterModuleEventBase.

Definition at line 1254 of file Module.h.

◆ GetName()

template<typename DerivedEvent , typename... EventFuncArgs>
virtual std::string DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::GetName ( ) const
inlineoverridevirtual

◆ ID()

template<typename DerivedEvent , typename... EventFuncArgs>
static auto DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::ID ( )
inlinestatic

Getter for EventID.

Returns
Returns EventID.

Definition at line 1237 of file Module.h.

◆ InvokeChild()

template<typename DerivedEvent , typename... EventFuncArgs>
virtual void DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::InvokeChild ( ModuleInstance Instance) const
inlinefinaloverrideprivatevirtual

Invokes the event passing the receiving module's instance reference to it. Only to be called from ModuleBase.

Parameters
InstanceModule instance handle.

Implements DynExp::EventBase.

Definition at line 1286 of file Module.h.

◆ InvokeWithParamsChild()

template<typename DerivedEvent , typename... EventFuncArgs>
virtual void DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::InvokeWithParamsChild ( ModuleInstance Instance,
EventListenersType::EventFunctionType  EventFunc 
) const
privatepure virtual

Called by InvokeChild(). Override to call EventFunc with Instance as the first argument and with further arguments of type EventFuncArgs.

Parameters
InstanceHandle to the module thread's data of the module EventFunc is invoked on.
EventFuncEvent function to invoke.

◆ Make()

template<typename DerivedEvent , typename... EventFuncArgs>
static InterModuleEventPtrType DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Make ( )
inlinestatic

Factory function for events of type DerivedEvent.

Returns
Returns a pointer to a new, default-constructed inter-module event.

Definition at line 1251 of file Module.h.

◆ Publish()

template<typename DerivedEvent , typename ... EventFuncArgs>
size_t DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Publish ( InterModuleEventLibrary Library)
static

Publishes this event type to the InterModuleEventLibrary. This function should not be called manually.

Parameters
LibraryInterModuleEventLibrary instance to publish this event type to.
Returns
Returns the unique ID of this event type.

Definition at line 1365 of file Module.h.

◆ Register()

template<typename DerivedEvent , typename... EventFuncArgs>
template<typename CallableT >
static void DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Register ( const ModuleBase Listener,
CallableT  EventFunc,
ItemIDType  CommunicatorID = ItemIDNotSet 
)
inlinestatic

Registers/Subscribes module Listener to the event with the event function EventFunc. Indirectly calls ModuleBase::AddRegisteredEvent(). If a module-communicator combination has already been registered, this registration is updated.

Template Parameters
CallableTType of the event function (member function of Listener's derived type) to invoke for Listener when the event is triggered.
Parameters
ListenerModule to register/subscribe.
EventFuncEvent function to invoke on module Listener when the event is triggered.
CommunicatorIDRefer to TypedEventListeners::Register().

Definition at line 1262 of file Module.h.

Member Data Documentation

◆ EventID

template<typename DerivedEvent , typename... EventFuncArgs>
const size_t DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::EventID = InterModuleEvent<DerivedEvent, EventFuncArgs...>::Publish(InterModuleEventLibrary::Get())
staticprivate

Unique ID assigned to this inter-module event.

Initializes the static InterModuleEvent::EventID variable to the unique type ID of DerivedEvent. Also ensures that InterModuleEvent::Publish() is called for each inter-module event type.

Definition at line 1311 of file Module.h.

◆ Listeners

template<typename DerivedEvent , typename... EventFuncArgs>
InterModuleEvent< DerivedEvent, EventFuncArgs... >::EventListenersType DynExp::InterModuleEvent< DerivedEvent, EventFuncArgs >::Listeners
staticprivate

Holds one EventListenersType instance per derived event, which manages all the subscribers of DerivedEvent.

Instantiate the respective static InterModuleEvent::Listeners variable to avoid linker errors.

Definition at line 1317 of file Module.h.


The documentation for this class was generated from the following file: