A signal is a reactive variable that can propagate its changes to dependents and react to changes of its dependencies.
Instances of this class act as a proxies to signal nodes.
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
.
Signals are created by constructor functions, i.e. MakeSignal.
template
<
typename D,
typename S
>
class Signal
{
public:
using DomainT = D;
using ValueT = S;
// Constructor
Signal();
Signal(const Signal&); // Copy
Signal(Signal&&); // Move
// Assignment
Signal& operator=(const Signal&); // Copy
Signal& operator=(Signal&& other); // Move
// Tests if two Signal instances are equal
bool Equals(const Signal& other) const;
// Tests if this instance is linked to a node
bool IsValid() const;
// Sets weight override for linked node
void SetWeightHint(WeightHint hint);
// Returns the current signal value
const S& Value() const;
const S& operator()() const;
// Equivalent to react::Flatten(*this)
S Flatten() const;
};
D | The domain this signal belongs to. Aliases as member type DomainT . |
E |
Signal value type. Aliased as member type ValueT .Should be DefaultConstructible , CopyConstructible and CopyAssignable .Can be MoveConstructible and MoveAssignable to avoid copying when possible.
|
Signal(); // (1)
Signal(const Signal& other); // (2)
Signal(Signal&& other); // (3)
(1) Creates an invalid signal that is not linked to a signal node.
(2) Creates a signal that links to the same signal node as other
.
(3) Creates a signal that moves shared ownership of the signal 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)
.
Signal& operator=(const Signal&); // (1)
Signal& operator=(Signal&& other); // (2)
(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.
bool Equals(const Signal& other) const;
Returns true, if both this
and other
link to the same signal node.
This function is used to compare two signals, because ==
is used as a combination operator instead.
bool IsValid() const;
Returns true, if this
is linked to a signal node.
const S& Value() const;
const S& operator()() const;
Returns a const reference to the current signal value.
S Flatten() const;
Semantically equivalent to the respective free function in namespace react
.