|
Ocean
|
This class implements a handler for scoped subscriptions to callback functions. More...
#include <ScopedSubscription.h>
Public Types | |
| using | CallbackFunctionType = TCallbackFunction |
| Definition of the data type of the callback function. | |
Public Types inherited from Ocean::ScopedSubscriptionHandler | |
| using | ScopedSubscriptionType = ScopedSubscriptionT< unsigned int, ScopedSubscriptionHandler > |
| Definition of a scoped subscription object. | |
Public Member Functions | |
| ScopedSubscriptionType | addCallback (TCallbackFunction callbackFunction) |
| Adds a new callback function to this handler. | |
| size_t | subscriptions () const |
| Returns the number of subscriptions. | |
| bool | isEmpty () const |
| Returns whether no subscription exists. | |
Static Public Attributes | |
| static constexpr bool | isThreadSafe_ = tThreadSafe |
| True, if this handler is thread-safe. | |
Protected Types | |
| using | CallbackMap = std::unordered_map< unsigned int, TCallbackFunction > |
| Definition of an unordered map mapping subscription ids to callback functions. | |
Protected Member Functions | |
| template<class... TArgs> | |
| TCallbackFunction::result_type | callCallbacks (TArgs &&... args) |
| Calls all callback functions of this handler. | |
| void | removeCallback (const unsigned int &subscriptionId) |
| Removes a callback function from the handler. | |
Protected Member Functions inherited from Ocean::ScopedSubscriptionHandler | |
| ScopedSubscriptionType | scopedSubscription (const unsigned int &subscriptionId, ScopedSubscriptionType::ReleaseCallbackFunction releaseCallbackFunction) |
| Returns the subscription object for a given subscription id. | |
Protected Attributes | |
| CallbackMap | callbackMap_ |
| The map mapping subscription ids to callback functions. | |
| unsigned int | subscriptionIdCounter_ = 0u |
| The counter for subscription ids. | |
| TemplatedLock< tThreadSafe > | lock_ |
| The optional lock object. | |
Private Attributes | |
| friend | TOwner |
This class implements a handler for scoped subscriptions to callback functions.
The class mainly wraps a counter for subscription ids and a map holding the callback functions.
| TCallbackFunction | The data type of the callback function |
| TOwner | The owner of this handler (the class in which the handler will be located) |
| tThreadSafe | True, to make the handler thread-safe |
| using Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::CallbackFunctionType = TCallbackFunction |
Definition of the data type of the callback function.
|
protected |
Definition of an unordered map mapping subscription ids to callback functions.
| ScopedSubscriptionHandler::ScopedSubscriptionType Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::addCallback | ( | TCallbackFunction | callbackFunction | ) |
Adds a new callback function to this handler.
| callbackFunction | The callback function to add, must be valid |
|
protected |
Calls all callback functions of this handler.
| args | The arguments of the callback function |
| TArgs | The data types of the callback functions |
| bool Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::isEmpty | ( | ) | const |
Returns whether no subscription exists.
|
protected |
Removes a callback function from the handler.
| subscriptionId | The id of the subscription to be removed |
| size_t Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::subscriptions | ( | ) | const |
Returns the number of subscriptions.
|
protected |
The map mapping subscription ids to callback functions.
|
staticconstexpr |
True, if this handler is thread-safe.
|
mutableprotected |
The optional lock object.
|
protected |
The counter for subscription ids.
|
private |