SubscriptionSet< T, WEAK_HANDLE, MAP, LOCK > Class Template Reference

#include <observablesimple.h>

Detailed Description

template<typename T, Bool WEAK_HANDLE = false, typename MAP = HashMapSelector<>, typename LOCK = ARWLock>
class maxon::SubscriptionSet< T, WEAK_HANDLE, MAP, LOCK >

A SubscriptionSet allows to add values to itself and to control their lifetime within the set by a handle. For example this can be used to manage a set of listeners. This class is completely thread-safe (when LOCK is a proper lock), so elements can be inserted, removed and get in parallel.

You have to use the Create function to create a new SubscriptionSet.

Template Parameters
TType of values.
WEAK_HANDLETrue if handles shall hold a weak reference to the set, false (the default) for a strong reference.
MAPA map selector template to choose the underlying map implementation to use.
LOCKThe lock implementation to use, for example ARWLock, Spinlock, RWSpinlock or NoOpLock.

Classes

struct  Remove
 

Public Member Functions

template<typename A >
Result< GenericDataInsert (A &&value)
 
template<typename ARRAY >
Result< void > GetValues (ARRAY &array) const
 

Static Public Member Functions

static Result< StrongRef< SubscriptionSet > > Create ()
 

Private Types

using Map = typename MAP::template Type< UInt, T >
 

Private Member Functions

 SubscriptionSet ()=default
 
 MAXON_DISALLOW_COPY_AND_ASSIGN (SubscriptionSet)
 

Private Attributes

SynchronizedValue< Map, LOCK > _map
 
AtomicUInt _lastId
 

Member Typedef Documentation

◆ Map

using Map = typename MAP::template Type<UInt, T>
private

Constructor & Destructor Documentation

◆ SubscriptionSet()

SubscriptionSet ( )
privatedefault

Member Function Documentation

◆ Create()

static Result<StrongRef<SubscriptionSet> > Create ( )
static

Creates a new empty SubscriptionSet.

Returns
A new subscription set.

◆ Insert()

Result<GenericData> Insert ( A &&  value)

Inserts a new element into the set. The lifetime of the element within the set will be tied to the lifetime of the returned handle, i.e., you have to keep the returned handle alive as long as the element shall be in the set.

Parameters
[in]valueThe value to insert as new element.
Returns
A handle to control the lifetime of the new element.

◆ GetValues()

Result<void> GetValues ( ARRAY &  array) const

Adds all current elements of the set to the given array. Note that the order of elements may be unspecified, that depends on the chosen MAP. For example a HashMap leads to unspecified order, while a sorted ArrayMap guarantees insertion order.

Parameters
[in]arrayThe array to which all current elements of the set shall be added.
Returns
OK on success.

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( SubscriptionSet< T, WEAK_HANDLE, MAP, LOCK >  )
private

Member Data Documentation

◆ _map

SynchronizedValue<Map, LOCK> _map
private

◆ _lastId

AtomicUInt _lastId
private