Ocean
Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe > Class Template Reference

This class implements a handler for scoped subscriptions to callback functions. More...

Inheritance diagram for Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >:

Public Types

using CallbackFunctionType = TCallbackFunction
 Definition of the data type of the callback function. More...
 
- Public Types inherited from Ocean::ScopedSubscriptionHandler
using ScopedSubscriptionType = ScopedSubscriptionT< unsigned int, ScopedSubscriptionHandler >
 Definition of a scoped subscription object. More...
 

Public Member Functions

ScopedSubscriptionType addCallback (TCallbackFunction callbackFunction)
 Adds a new callback function to this handler. More...
 
size_t subscriptions () const
 Returns the number of subscriptions. More...
 
bool isEmpty () const
 Returns whether no subscription exists. More...
 

Static Public Attributes

static constexpr bool isThreadSafe_ = tThreadSafe
 True, if this handler is thread-safe. More...
 

Protected Types

using CallbackMap = std::unordered_map< unsigned int, TCallbackFunction >
 Definition of an unordered map mapping subscription ids to callback functions. More...
 

Protected Member Functions

template<class... TArgs>
TCallbackFunction::result_type callCallbacks (TArgs &&... args)
 Calls all callback functions of this handler. More...
 
void removeCallback (const unsigned int &subscriptionId)
 Removes a callback function from the handler. More...
 
- 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. More...
 

Protected Attributes

CallbackMap callbackMap_
 The map mapping subscription ids to callback functions. More...
 
unsigned int subscriptionIdCounter_ = 0u
 The counter for subscription ids. More...
 
TemplatedLock< tThreadSafe > lock_
 The optional lock object. More...
 

Private Attributes

friend TOwner
 

Detailed Description

template<typename TCallbackFunction, typename TOwner, bool tThreadSafe>
class Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >

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.

Template Parameters
TCallbackFunctionThe data type of the callback function
TOwnerThe owner of this handler (the class in which the handler will be located)
tThreadSafeTrue, to make the handler thread-safe

Member Typedef Documentation

◆ CallbackFunctionType

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
using Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::CallbackFunctionType = TCallbackFunction

Definition of the data type of the callback function.

◆ CallbackMap

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
using Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::CallbackMap = std::unordered_map<unsigned int, TCallbackFunction>
protected

Definition of an unordered map mapping subscription ids to callback functions.

Member Function Documentation

◆ addCallback()

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
ScopedSubscriptionHandler::ScopedSubscriptionType Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::addCallback ( TCallbackFunction  callbackFunction)

Adds a new callback function to this handler.

Parameters
callbackFunctionThe callback function to add, must be valid
Returns
The resulting scoped subscription object, the callback function will be in use until the resulting subscription object exists

◆ callCallbacks()

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
template<class... TArgs>
TCallbackFunction::result_type Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::callCallbacks ( TArgs &&...  args)
protected

Calls all callback functions of this handler.

Parameters
argsThe arguments of the callback function
Returns
The resulting of any of the callback functions
Template Parameters
TArgsThe data types of the callback functions

◆ isEmpty()

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
bool Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::isEmpty

Returns whether no subscription exists.

Returns
True, if so

◆ removeCallback()

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
void Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::removeCallback ( const unsigned int &  subscriptionId)
protected

Removes a callback function from the handler.

Parameters
subscriptionIdThe id of the subscription to be removed

◆ subscriptions()

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
size_t Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::subscriptions

Returns the number of subscriptions.

Returns
The handler's subscriptions

Field Documentation

◆ callbackMap_

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
CallbackMap Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::callbackMap_
protected

The map mapping subscription ids to callback functions.

◆ isThreadSafe_

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
constexpr bool Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::isThreadSafe_ = tThreadSafe
staticconstexpr

True, if this handler is thread-safe.

◆ lock_

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
TemplatedLock<tThreadSafe> Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::lock_
mutableprotected

The optional lock object.

◆ subscriptionIdCounter_

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
unsigned int Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::subscriptionIdCounter_ = 0u
protected

The counter for subscription ids.

◆ TOwner

template<typename TCallbackFunction , typename TOwner , bool tThreadSafe>
friend Ocean::ScopedSubscriptionCallbackHandlerT< TCallbackFunction, TOwner, tThreadSafe >::TOwner
private

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