A template class to manage callback, delegate and notification functions.
More...
#include <callback.h>
|
| void | subscribe (const TCallbackClientId client_id, const TCallbacks &handlers) |
| | Register callback, delegate, or notification functions. More...
|
| |
| void | unsubscribe (const TCallbackClientId client_id) |
| | Remove registered callbacks, delegates, or notifications. More...
|
| |
|
| template<typename TMemberFunction , typename... Arguments> |
| void | notify (TMemberFunction function, const Arguments &... arguments) |
| | Invoke a notification function. More...
|
| |
| template<typename TMemberFunction , typename... Arguments> |
| void | callback (TMemberFunction function, Arguments &&... arguments) |
| | Invoke a callback function. More...
|
| |
| template<typename TReturnType , typename TMemberFunction , typename... Arguments> |
| TReturnType | aggregate (TReturnType result, const std::function< TReturnType(TReturnType, TReturnType)> &combine, TMemberFunction function, const Arguments &... arguments) |
| | Invoke a delegate function and aggregate the results. More...
|
| |
| template<typename TMemberFunction , typename... Arguments> |
| bool | queryUnanimousApproval (bool default_result, TMemberFunction function, const Arguments &... arguments) |
| | Check for approval from all delegates. More...
|
| |
| template<typename TMemberFunction , typename... Arguments> |
| bool | queryAnyApproval (bool default_result, TMemberFunction function, const Arguments &... arguments) |
| | Check for approval by any delegate. More...
|
| |
template<typename TOwner, typename TCallbacks, typename TCallbackClientId = void *>
class CallbackManager< TOwner, TCallbacks, TCallbackClientId >
A template class to manage callback, delegate and notification functions.
- Template Parameters
-
| TOwner | CallbackManager is expected to be a nested class. TOwner is the enclosing class. |
| TCallbacks | A structure with callback hooks as members. |
| TCallbackClientId | Unique ID to allow update or removal of hooks. Typically the caller's 'this'. |
◆ aggregate()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
template<typename TReturnType , typename TMemberFunction , typename... Arguments>
| TReturnType CallbackManager< TOwner, TCallbacks, TCallbackClientId >::aggregate |
( |
TReturnType |
default_result, |
|
|
const std::function< TReturnType(TReturnType, TReturnType)> & |
combine, |
|
|
TMemberFunction |
function, |
|
|
const Arguments &... |
arguments |
|
) |
| |
|
private |
Invoke a delegate function and aggregate the results.
- Template Parameters
-
| TReturnType | The type returned by the delegates, and aggregated and returned by this method. |
- Parameters
-
| default_result | The result returned if there are no registered delegates. |
| combine | A function that combines results when there are multiple delegates. |
| function | A TCallbacks member selector for the callback to be invoked. |
| arguments | Any arguments to be passed to the callback functions. |
◆ callback()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
template<typename TMemberFunction , typename... Arguments>
| void CallbackManager< TOwner, TCallbacks, TCallbackClientId >::callback |
( |
TMemberFunction |
function, |
|
|
Arguments &&... |
arguments |
|
) |
| |
|
private |
Invoke a callback function.
- Parameters
-
| function | A TCallbacks member selector for the callback to be invoked. |
| arguments | Any arguments to be passed to the callback functions. |
◆ notify()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
template<typename TMemberFunction , typename... Arguments>
| void CallbackManager< TOwner, TCallbacks, TCallbackClientId >::notify |
( |
TMemberFunction |
function, |
|
|
const Arguments &... |
arguments |
|
) |
| |
|
private |
Invoke a notification function.
- Parameters
-
| function | A TCallbacks member selector for the callback to be invoked. |
| arguments | Any arguments to be passed to the callback functions. |
◆ queryAnyApproval()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
template<typename TMemberFunction , typename... Arguments>
| bool CallbackManager< TOwner, TCallbacks, TCallbackClientId >::queryAnyApproval |
( |
bool |
default_result, |
|
|
TMemberFunction |
function, |
|
|
const Arguments &... |
arguments |
|
) |
| |
|
inlineprivate |
Check for approval by any delegate.
- Parameters
-
| default_result | The result in the event there are no delegates. |
| function | A TCallbacks member selector for the delegate to be queried. |
| arguments | Any arguments to be passed to delegates. |
- Returns
- True if any delegate returns true, false otherwise.
◆ queryUnanimousApproval()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
template<typename TMemberFunction , typename... Arguments>
| bool CallbackManager< TOwner, TCallbacks, TCallbackClientId >::queryUnanimousApproval |
( |
bool |
default_result, |
|
|
TMemberFunction |
function, |
|
|
const Arguments &... |
arguments |
|
) |
| |
|
inlineprivate |
Check for approval from all delegates.
All delegates are queried.
- Parameters
-
| default_result | The result in the event there are no delegates. |
| function | A TCallbacks member selector for the delegate to be queried. |
| arguments | Any arguments to be passed to delegates. |
- Returns
- True if all delegates return true, false if any return false.
◆ subscribe()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
| void CallbackManager< TOwner, TCallbacks, TCallbackClientId >::subscribe |
( |
const TCallbackClientId |
client_id, |
|
|
const TCallbacks & |
handlers |
|
) |
| |
Register callback, delegate, or notification functions.
- Parameters
-
| client_id | A unique ID for the client. Suggest using its 'this' object value. |
| handlers | The handler functions to invoke for callbacks. |
◆ unsubscribe()
template<typename TOwner , typename TCallbacks , typename TCallbackClientId >
| void CallbackManager< TOwner, TCallbacks, TCallbackClientId >::unsubscribe |
( |
const TCallbackClientId |
client_id | ) |
|
Remove registered callbacks, delegates, or notifications.
- Parameters
-
| client_id | The ID the client registered its callback with. |
◆ registered_handlers
template<typename TOwner , typename TCallbacks , typename TCallbackClientId = void *>
| std::unordered_map<TCallbackClientId, TCallbacks> CallbackManager< TOwner, TCallbacks, TCallbackClientId >::registered_handlers |
|
private |
The list of subscribers to the callbacks.
◆ TOwner
template<typename TOwner , typename TCallbacks , typename TCallbackClientId = void *>
The documentation for this class was generated from the following files: