Gromacs  2022.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::MDModulesNotifier< CallParameter, MDModulesNotifierBase > Class Template Reference

#include <gromacs/utility/mdmodulesnotifier.h>

Inherits MDModulesNotifierBase.

Description

template<class CallParameter, class MDModulesNotifierBase>
class gmx::MDModulesNotifier< CallParameter, MDModulesNotifierBase >

Organizes notifications about an event of interest to modules.

An object of this type permits modules to subscribe to the corresponding event. The template types of this type encode what information is available when the event occurs. Modules subscribe() by providing a callback function that accepts a single parameter of such an event type. The code that handles that event has the responsibilty to call notify() afterwards. The subscribed modules then receive the callback with the requested event type as an argument.

See gmx::MDModulesNotifiers for sequence diagrams for an example.

This suits scenarios where several objects are built (or re-built) and one or more modules need to know when one or more of such objects are available (or updated), so they can adapt their internal state accordingly. Examples include responding to loading input data, or to changes related to a recurring process like checkpointing or partitioning. The coupling between these modules is now expressed indirectly. This improves the modularity and testability of those modules.

The implementation provides the necessary flexibility to be parameterized with multiple event types and provide callback() and notify() methods corresponding to each related event. This is done by inheriting from a series of base classes, each of which handles a single type of event. BuildMDModulesNotifier implements the details. To create a class of this type that provides two events with callbacks that receive respectively types TypeA and TypeB, use BuildMDModulesNotifier<TypeA, TypeB>::type.

Template Parameters
CallParameterof the function to be notified
MDModulesNotifierBaseclass to be extended with a notification with CallParameter
Note
All added subscribers are required to out-live the MDModulesNotifier

Public Member Functions

void notify (CallParameter callParameter) const
 Notifies subscribers of the event described by callbackParameter. More...
 
void subscribe (std::function< void(CallParameter)> callBackFunction)
 Add callback function to be called when notify() is called. More...
 

Member Function Documentation

template<class CallParameter , class MDModulesNotifierBase >
void gmx::MDModulesNotifier< CallParameter, MDModulesNotifierBase >::notify ( CallParameter  callParameter) const
inline

Notifies subscribers of the event described by callbackParameter.

Parameters
[in]callParameterof the function to be called back
template<class CallParameter , class MDModulesNotifierBase >
void gmx::MDModulesNotifier< CallParameter, MDModulesNotifierBase >::subscribe ( std::function< void(CallParameter)>  callBackFunction)
inline

Add callback function to be called when notify() is called.

Parameters
[in]callBackFunctionto be called

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