ReadonlySignal¶
-
template<typename T, size_t MaxDeps = 8, typename Filter = std::not_equal_to<T>, size_t HistorySize = 0>
class ReadonlySignal¶ Immutable view of a Signal that prevents modifications.
ReadonlySignal wraps a Signal and exposes only read operations (get, peek). This is useful for providing safe read-only access to signals without allowing modifications from external code.
- Since
v0.1.0
Key Features:
Read-only access to Signal values
Automatic dependency tracking (same as Signal::get()).
peek() for untracked reads.
Cannot be copied or moved (references underlying Signal).
No overhead - just a thin wrapper pointer.
Usage:
Signal<int> counter(0); ReadonlySignal<int> readonlyCounter(counter); // Can read int value = readonlyCounter.get(); // Cannot write (these methods don't exist) // readonlyCounter.set(5); // Compile error // readonlyCounter.update(...); // Compile errorNote
For simplicity, consider using the readonly helper.
- Template Parameters:¶
- typename T¶
Type of value stored in the underlying signal.
- size_t MaxDeps = 8¶
Maximum number of dependents (must match underlying Signal).
- typename Filter = std::not_equal_to<T>¶
Filter type for change detection (must match underlying Signal).
- size_t HistorySize = 0¶
Size of history buffer (must match underlying Signal).
Public Functions¶
-
inline explicit ReadonlySignal(Signal<T, MaxDeps, Filter, HistorySize> &signal)¶
Construct ReadonlySignal from underlying Signal.
- Since
v0.1.0
- Parameters:¶
- Signal<T, MaxDeps, Filter, HistorySize> &signal¶
Reference to Signal to wrap (must outlive this ReadonlySignal).
-
inline T get() const¶
Get current value with dependency tracking.
Same behavior as Signal::get(). Registers caller as dependent if called from within Computed or Effect.
- Returns:¶
Current value of underlying signal.
-
inline T operator()() const¶
Function call operator for convenient access.
Equivalent to get().
- Returns:¶
Current value of underlying signal.
-
inline T peek()¶
Read value without dependency tracking.
Same behavior as Signal::peek().
- Returns:¶
Current value without registering as dependent.
-
~ReadonlySignal() = default¶
-
ReadonlySignal(const ReadonlySignal&) = delete¶
-
ReadonlySignal &operator=(const ReadonlySignal&) = delete¶
-
ReadonlySignal(ReadonlySignal&&) = delete¶
-
ReadonlySignal &operator=(ReadonlySignal&&) = delete¶
See Also¶
Reactive Nodes - Nodes Overview