HomeReferenceEvent.h ⇀ Events

Events class

An instance of this class acts as a proxy to an event stream node. It takes shared ownership of the node, so while it exists, the node will not be destroyed. Copy, move and assignment semantics are similar to std::shared_ptr.

Synopsis

template
<
    typename D,
    typename E = Token 
>
class Events
{
public:
    using DomainT = D;
    using ValueT = E;

    // Constructor
    Events();
    Events(const Events&);  // Copy
    Events(Events&&);       // Move

    // Assignemnt
    Events& operator=(const Events&);   // Copy
    Events& operator=(Events&& other);  // Move

    // Tests if two instances link to the same node
    bool Equals(const Events& other) const;

    // Tests if this instance is linked to a node
    bool IsValid() const;

    // Sets weight override for linked node
    void SetWeightHint(WeightHint hint);

    // Equivalent to react::Merge(*this, args ...)
    TempEvents<D,E,/*unspecified*/>
        Merge(const Events<D,TValues>& ... args) const;

    // Equivalent to react::Filter(*this, f)
    TempEvents<D,E,/*unspecified*/>
        Filter(F&& f) const;

    // Equivalent to react::Transform(*this, f)
    TempEvents<D,T,/*unspecified*/>
        Transform(F&& f) const;

    // Equivalent to react::Tokenize(*this)
    TempEvents<D,Token,/*unspecified*/>
        Tokenize() const;
};

Template parameters

D The domain this event stream belongs to. Aliases as member type DomainT.
E Event value type. Aliased as member type ValueT. If this parameter is omitted, Token is used as the default.
Should be DefaultConstructible, CopyConstructible and CopyAssignable.
Can be MoveConstructible and MoveAssignable to avoid copying when possible.

Constructor member function

Syntax

Events();                    // (1)
Events(const Events& other); // (2)
Events(Events&& other);      // (3)

Semantics

(1) Creates an invalid event stream that is not linked to an event node.

(2) Creates an event stream that links to the same event node as other.

(3) Creates an event stream that moves shared ownership of the event node from other to this. As a result, other becomes invalid.

Note: The default constructor creates an invalid proxy, which is equivalent to std::shared_ptr(nullptr).


operator= member function

Syntax

Events& operator=(const Events&);   // (1)
Events& operator=(Events&& other);  // (2)

Semantics

(1) Links this to the same node as other. If this was already linked to another node, it releases its previous ownership.

(2) Transfers shared ownership of the linked node from other to this. If this was already linked to another node, it release its previous ownership. As a result, other becomes invalid.


Equals member function

Syntax

bool Equals(const Events& other) const;

Semantics

Returns true, if both this and other link to the same event node. Since some reactive types use == as a combination operator, this function is used for unambiguous comparison.


IsValid member function

Syntax

bool IsValid() const;

Semantics

Returns true, if this is linked to an event node.


Merge, Filter, Transform, Tokenize member function

Syntax

template <typename ... TValues>
TempEvents<D,E,/*unspecified*/> Merge(const Events<D,TValues>& ... args) const;

template <typename F>
TempEvents<D,E,/*unspecified*/> Filter(F&& f) const;

template <typename F>
TempEvents<D,T,/*unspecified*/> Transform(F&& f) const;

TempEvents<D,Token,/*unspecified*/> Tokenize() const;

Semantics

Semantically equivalent to the respective free functions in namespace react.