Ocean
Ocean::ScopedSubscriptionT< T, TOwner > Class Template Reference

This class implements a subscription object which can be used unique subscriptions to e.g., callback functions. More...

Inheritance diagram for Ocean::ScopedSubscriptionT< T, TOwner >:

Public Member Functions

 ScopedSubscriptionT ()=default
 Creates an invalid (unsubscribed) subscription object. More...
 
 ScopedSubscriptionT (ScopedSubscriptionT< T, TOwner > &&scopedSubscription)
 Move constructor. More...
 
 ~ScopedSubscriptionT ()
 Destructs the object and releases the subscription if any. More...
 
void release ()
 Explicitly releases the subscription before this object is disposes. More...
 
bool isValid () const
 Returns whether this object holds a valid subscription. More...
 
 operator bool () const
 Returns whether this object holds a valid subscription. More...
 
ScopedSubscriptionT< T, TOwner > & operator= (ScopedSubscriptionT< T, TOwner > &&scopedSubscription)
 Move operator. More...
 
bool operator== (const ScopedSubscriptionT< T, TOwner > &scopedSubscription) const
 Returns whether two subscription objects are identical. More...
 
bool operator!= (const ScopedSubscriptionT< T, TOwner > &scopedSubscription) const
 Returns whether two subscription objects are not identical. More...
 
size_t operator() (const ScopedSubscriptionT< T, TOwner > &scopedSubscription) const
 Hash function. More...
 

Protected Types

using ReleaseCallbackFunction = std::function< void(const T &subscriptionId)>
 Definition of a callback function for release requests. More...
 

Protected Member Functions

 ScopedSubscriptionT (const ScopedSubscriptionT< T, TOwner > &scopedSubscription)=delete
 Disabled copy constructor. More...
 
 ScopedSubscriptionT (const T &subscriptionId, ReleaseCallbackFunction releaseCallbackFunction)
 Creates a new subscription object for a valid subscription id. More...
 
ScopedSubscriptionT< T, TOwner > & operator= (const ScopedSubscriptionT< T, TOwner > &scopedSubscription)=delete
 The disabled assign operator. More...
 

Protected Attributes

std::unique_ptr< T > subscriptionId_ = nullptr
 The subscription id, nullptr if invalid. More...
 
ReleaseCallbackFunction releaseCallbackFunction_ = nullptr
 The callback function which will be used when the subscription needs to be released. More...
 

Private Attributes

friend TOwner
 

Detailed Description

template<typename T, typename TOwner>
class Ocean::ScopedSubscriptionT< T, TOwner >

This class implements a subscription object which can be used unique subscriptions to e.g., callback functions.

The subscription exists as long as the object exists.

Template Parameters
TThe data type of the subscription id
TOwnerThe data type of the class in which this subscription object will be defined

Member Typedef Documentation

◆ ReleaseCallbackFunction

template<typename T , typename TOwner >
using Ocean::ScopedSubscriptionT< T, TOwner >::ReleaseCallbackFunction = std::function<void(const T& subscriptionId)>
protected

Definition of a callback function for release requests.

Parameters
subscriptionIdThe id of the subscription to be released

Constructor & Destructor Documentation

◆ ScopedSubscriptionT() [1/4]

template<typename T , typename TOwner >
Ocean::ScopedSubscriptionT< T, TOwner >::ScopedSubscriptionT ( )
default

Creates an invalid (unsubscribed) subscription object.

◆ ScopedSubscriptionT() [2/4]

template<typename T , typename TOwner >
Ocean::ScopedSubscriptionT< T, TOwner >::ScopedSubscriptionT ( ScopedSubscriptionT< T, TOwner > &&  scopedSubscription)
inline

Move constructor.

Parameters
scopedSubscriptionThe object to be moved

◆ ~ScopedSubscriptionT()

template<typename T , typename TOwner >
Ocean::ScopedSubscriptionT< T, TOwner >::~ScopedSubscriptionT

Destructs the object and releases the subscription if any.

◆ ScopedSubscriptionT() [3/4]

template<typename T , typename TOwner >
Ocean::ScopedSubscriptionT< T, TOwner >::ScopedSubscriptionT ( const ScopedSubscriptionT< T, TOwner > &  scopedSubscription)
protecteddelete

Disabled copy constructor.

Parameters
scopedSubscriptionThe object which would be copied

◆ ScopedSubscriptionT() [4/4]

template<typename T , typename TOwner >
Ocean::ScopedSubscriptionT< T, TOwner >::ScopedSubscriptionT ( const T &  subscriptionId,
ReleaseCallbackFunction  releaseCallbackFunction 
)
inlineexplicitprotected

Creates a new subscription object for a valid subscription id.

Parameters
subscriptionIdThe subscription id, must be valid
releaseCallbackFunctionThe callback function which will be used when the subscription needs to be released, must be valid

Member Function Documentation

◆ isValid()

template<typename T , typename TOwner >
bool Ocean::ScopedSubscriptionT< T, TOwner >::isValid
inline

Returns whether this object holds a valid subscription.

Returns
True, if so

◆ operator bool()

template<typename T , typename TOwner >
Ocean::ScopedSubscriptionT< T, TOwner >::operator bool
inlineexplicit

Returns whether this object holds a valid subscription.

Returns
True, if so

◆ operator!=()

template<typename T , typename TOwner >
bool Ocean::ScopedSubscriptionT< T, TOwner >::operator!= ( const ScopedSubscriptionT< T, TOwner > &  scopedSubscription) const
inline

Returns whether two subscription objects are not identical.

Parameters
scopedSubscriptionThe second subscription object to compare
Returns
True, if so

◆ operator()()

template<typename T , typename TOwner >
size_t Ocean::ScopedSubscriptionT< T, TOwner >::operator() ( const ScopedSubscriptionT< T, TOwner > &  scopedSubscription) const
inline

Hash function.

Parameters
scopedSubscriptionThe object for which the hash value will be determined
Returns
The resulting hash value

◆ operator=() [1/2]

template<typename T , typename TOwner >
ScopedSubscriptionT<T, TOwner>& Ocean::ScopedSubscriptionT< T, TOwner >::operator= ( const ScopedSubscriptionT< T, TOwner > &  scopedSubscription)
protecteddelete

The disabled assign operator.

Parameters
scopedSubscriptionThe object which would be assigned
Returns
The reference to this object

◆ operator=() [2/2]

template<typename T , typename TOwner >
ScopedSubscriptionT< T, TOwner > & Ocean::ScopedSubscriptionT< T, TOwner >::operator= ( ScopedSubscriptionT< T, TOwner > &&  scopedSubscription)
inline

Move operator.

Parameters
scopedSubscriptionThe object to be moved
Returns
Reference to this object

◆ operator==()

template<typename T , typename TOwner >
bool Ocean::ScopedSubscriptionT< T, TOwner >::operator== ( const ScopedSubscriptionT< T, TOwner > &  scopedSubscription) const
inline

Returns whether two subscription objects are identical.

Parameters
scopedSubscriptionThe second subscription object to compare
Returns
True, if so

◆ release()

template<typename T , typename TOwner >
void Ocean::ScopedSubscriptionT< T, TOwner >::release

Explicitly releases the subscription before this object is disposes.

Field Documentation

◆ releaseCallbackFunction_

template<typename T , typename TOwner >
ReleaseCallbackFunction Ocean::ScopedSubscriptionT< T, TOwner >::releaseCallbackFunction_ = nullptr
protected

The callback function which will be used when the subscription needs to be released.

◆ subscriptionId_

template<typename T , typename TOwner >
std::unique_ptr<T> Ocean::ScopedSubscriptionT< T, TOwner >::subscriptionId_ = nullptr
protected

The subscription id, nullptr if invalid.

◆ TOwner

template<typename T , typename TOwner >
friend Ocean::ScopedSubscriptionT< T, TOwner >::TOwner
private

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