OmniSciDB
a5dc49c757
|
#include <CallbackManager.h>
Public Member Functions | |
IDType | registerCallback (CallbackType callback) |
void | unregisterCallback (IDType id) |
void | notify (const ContextType &context) |
bool | isEmpty () const |
Private Attributes | |
std::map< IDType, CallbackType > | callbacks_ |
IDType | next_id_ |
bool | is_notifying_ |
std::vector< IDType > | deferred_unregister_ids_ |
Template class for managing notification callbacks
IDType must be an intergral type CallbackType must be a callable type: lambda, functor, etc ContextType can be any basic type, struct, or class
Notification broadcast is in registration order IDs DO NOT wrap around, and a free-list is not used, so IDType must not be exhaustible
Unregistering a callback during notification handling will defer unregistration until notification completes
Example:
struct MyContextType { int value; ... }; using MyCallbackType = std::function<void(const MyContextType&)>; using MyCallbackID = uint32_t;
class SomeClass { CallbackManager<MyCallbackID, MyCallbackType, MyContextType> callbacks;
SomeClass() { callbacks.registerCallback([this](const MyContextType& context) { handleCallback(context); } ); }
void handleCallback(const MyContextType& context) { doStuff(context.value); } };
Definition at line 63 of file CallbackManager.h.
|
inline |
Definition at line 102 of file CallbackManager.h.
References CallbackManager< IDType, CallbackType, ContextType >::callbacks_.
|
inline |
Definition at line 86 of file CallbackManager.h.
References CallbackManager< IDType, CallbackType, ContextType >::callbacks_, CallbackManager< IDType, CallbackType, ContextType >::deferred_unregister_ids_, CallbackManager< IDType, CallbackType, ContextType >::is_notifying_, and CallbackManager< IDType, CallbackType, ContextType >::unregisterCallback().
|
inline |
Definition at line 70 of file CallbackManager.h.
References CallbackManager< IDType, CallbackType, ContextType >::callbacks_, CHECK_LT, and CallbackManager< IDType, CallbackType, ContextType >::next_id_.
|
inline |
Definition at line 76 of file CallbackManager.h.
References CallbackManager< IDType, CallbackType, ContextType >::callbacks_, CHECK, CallbackManager< IDType, CallbackType, ContextType >::deferred_unregister_ids_, and CallbackManager< IDType, CallbackType, ContextType >::is_notifying_.
Referenced by CallbackManager< IDType, CallbackType, ContextType >::notify().
|
private |
Definition at line 106 of file CallbackManager.h.
Referenced by CallbackManager< IDType, CallbackType, ContextType >::isEmpty(), CallbackManager< IDType, CallbackType, ContextType >::notify(), CallbackManager< IDType, CallbackType, ContextType >::registerCallback(), and CallbackManager< IDType, CallbackType, ContextType >::unregisterCallback().
|
private |
Definition at line 109 of file CallbackManager.h.
Referenced by CallbackManager< IDType, CallbackType, ContextType >::notify(), and CallbackManager< IDType, CallbackType, ContextType >::unregisterCallback().
|
private |
Definition at line 108 of file CallbackManager.h.
Referenced by CallbackManager< IDType, CallbackType, ContextType >::notify(), and CallbackManager< IDType, CallbackType, ContextType >::unregisterCallback().
|
private |
Definition at line 107 of file CallbackManager.h.
Referenced by CallbackManager< IDType, CallbackType, ContextType >::registerCallback().