#include <observablesimple.h>
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.
T | Type of values. |
WEAK_HANDLE | True if handles shall hold a weak reference to the set, false (the default) for a strong reference. |
MAP | A map selector template to choose the underlying map implementation to use. |
LOCK | The lock implementation to use, for example ARWLock, Spinlock, RWSpinlock or NoOpLock. |
Classes | |
struct | Remove |
Public Member Functions | |
template<typename A > | |
Result< GenericData > | Insert (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 |
|
privatedefault |
|
static |
Creates a new empty SubscriptionSet.
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.
[in] | value | The value to insert as new element. |
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.
[in] | array | The array to which all current elements of the set shall be added. |
|
private |
|
private |
|
private |