Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::reactive::Property< T > Class Template Reference

#include <property.hpp>

Inheritance diagram for aria::reactive::Property< T >:
[legend]

Public Types

using value_type = T

Public Member Functions

 Property (T initial=T{})
 ~Property () noexcept override
 Property (const Property &)=delete
Propertyoperator= (const Property &)=delete
 Property (Property &&)=delete
Propertyoperator= (Property &&)=delete
get () const
 Auto-tracked read.
const T & get_ref () const
 Auto-tracked read by const reference.
peek () const noexcept(std::is_nothrow_copy_constructible_v< T >)
 Snapshot read that does NOT register a dependency.
const T & peek_ref () const noexcept
 Snapshot read by const reference (never tracks, never copies).
 operator T () const
 Convenience: implicit conversion behaves like .get() so expressions read naturally (int total = price + tax;).
void set (const T &new_val)
 Commit a new value.
void set (T &&new_val)
Propertyoperator= (const T &v)
Propertyoperator= (T &&v)
template<std::invocable< T & > Fn>
void mutate (Fn &&fn)
 Mutate-in-place: always fires a change (cannot detect no-op because the mutation is opaque).
::aria::Subscription on_changed (std::function< void(const T &)> fn)
 Run fn(new_value) every time the value changes.
::aria::Subscription bind (std::function< void(const T &)> fn)
 Fire once with the current value, then on every subsequent change.
::aria::Subscription observe (std::function< void(const T &, const T &)> fn)
 Two-argument form: receive (old, new).
std::any get_any () const override
 Read the current value as a std::any.
bool set_any (const std::any &value) override
 Try to set the property's value from a std::any.
::aria::Subscription subscribe_any (std::function< void(const std::any &)> on_changed_any) override
 Subscribe to value changes.
const std::type_info & type () const noexcept override
 The runtime type of the wrapped value.
Public Member Functions inherited from aria::reactive::Node
 Node (NodeKind kind) noexcept
virtual ~Node () noexcept
 Node (const Node &)=delete
Nodeoperator= (const Node &)=delete
 Node (Node &&)=delete
Nodeoperator= (Node &&)=delete
NodeKind kind () const noexcept
NodeState state () const noexcept
std::uint64_t version () const noexcept
const std::string & debug_name () const noexcept
void set_debug_name (std::string name)
const std::string & effective_debug_name () const
 A non-empty debug label for diagnostic output.
void notify_changed ()
 Called by a Source after its value has actually changed: bumps the version and colors all downstream nodes MaybeDirty.
void mark_downstream_maybe_dirty ()
 Mark self and all reachable descendants as MaybeDirty.
void mark_dirty () noexcept
 Escalate state to Dirty (used by Graph::pull after confirming an upstream has truly moved).
std::uint32_t depth () const noexcept
 Topological depth used by flush ordering.
void set_depth (std::uint32_t d) noexcept
virtual bool recompute ()
 Recompute hook for Derivation / Reaction nodes.
virtual std::shared_ptr< Noderetain_for_recompute () noexcept
 Reactions are shared-owned and may cancel themselves while running.
void attach_as_observer_of (Node &source, Edge &edge) noexcept
void detach_edge (Edge &edge) noexcept
void clear_sources () noexcept
 Drop every upstream edge.
template<class F>
void for_each_observer (F &&f)
 Iterate the observer list (used by Graph to color downstream nodes).
template<class F>
void for_each_source (F &&f) const
 Iterate the source list (used by a Derivation in pull() to compare each upstream's current version against observed_version).
bool has_observers () const noexcept
bool has_sources () const noexcept
Public Member Functions inherited from aria::IProperty
virtual ~IProperty () noexcept=default

Additional Inherited Members

Static Public Member Functions inherited from aria::reactive::Node
static Graphgraph () noexcept
 Returns the process-wide singleton Graph this node belongs to.
Protected Member Functions inherited from aria::reactive::Node
void retire_ () noexcept
 Retire before derived members (including user captures) are destroyed.
void bump_version_ () noexcept
void set_state_ (NodeState s) noexcept
Protected Member Functions inherited from aria::IProperty
 IProperty () noexcept=default
 IProperty (const IProperty &)=delete
IPropertyoperator= (const IProperty &)=delete
 IProperty (IProperty &&)=delete
IPropertyoperator= (IProperty &&)=delete

Member Typedef Documentation

◆ value_type

template<PropertyValue T>
using aria::reactive::Property< T >::value_type = T

Constructor & Destructor Documentation

◆ Property() [1/3]

template<PropertyValue T>
aria::reactive::Property< T >::Property ( T initial = T{})
inlineexplicit

◆ ~Property()

template<PropertyValue T>
aria::reactive::Property< T >::~Property ( )
inlineoverridenoexcept

◆ Property() [2/3]

template<PropertyValue T>
aria::reactive::Property< T >::Property ( const Property< T > & )
delete

◆ Property() [3/3]

template<PropertyValue T>
aria::reactive::Property< T >::Property ( Property< T > && )
delete

Member Function Documentation

◆ operator=() [1/4]

template<PropertyValue T>
Property & aria::reactive::Property< T >::operator= ( const Property< T > & )
delete

◆ operator=() [2/4]

template<PropertyValue T>
Property & aria::reactive::Property< T >::operator= ( Property< T > && )
delete

◆ get()

template<PropertyValue T>
T aria::reactive::Property< T >::get ( ) const
inlinenodiscard

Auto-tracked read.

If a TrackingContext is active (inside a Derivation's compute or a Reaction's body), this read becomes an upstream edge of that context.

◆ get_ref()

template<PropertyValue T>
const T & aria::reactive::Property< T >::get_ref ( ) const
inlinenodiscard

Auto-tracked read by const reference.

Same auto-tracking semantics as get(), but avoids copying T on hot paths (UI bindings reading Property<std::string> etc.). The reference is valid until the next mutation on the graph thread; never store it across an await / re-entry into the graph.

◆ peek()

template<PropertyValue T>
T aria::reactive::Property< T >::peek ( ) const
inlinenodiscardnoexcept

Snapshot read that does NOT register a dependency.

Equivalent to untracked([&]{ return p.get(); }) but cheaper.

noexcept is conditional on T's copy ctor — for trivially copyable types this is a free promise; for T that may throw on copy (e.g. std::string under low-memory conditions) we degrade gracefully rather than terminate.

◆ peek_ref()

template<PropertyValue T>
const T & aria::reactive::Property< T >::peek_ref ( ) const
inlinenodiscardnoexcept

Snapshot read by const reference (never tracks, never copies).

◆ operator T()

template<PropertyValue T>
aria::reactive::Property< T >::operator T ( ) const
inline

Convenience: implicit conversion behaves like .get() so expressions read naturally (int total = price + tax;).

◆ set() [1/2]

template<PropertyValue T>
void aria::reactive::Property< T >::set ( const T & new_val)
inline

Commit a new value.

No-op if equal to the current one. Emits a graph-wide invalidation pulse otherwise.

◆ set() [2/2]

template<PropertyValue T>
void aria::reactive::Property< T >::set ( T && new_val)
inline

◆ operator=() [3/4]

template<PropertyValue T>
Property & aria::reactive::Property< T >::operator= ( const T & v)
inline

◆ operator=() [4/4]

template<PropertyValue T>
Property & aria::reactive::Property< T >::operator= ( T && v)
inline

◆ mutate()

template<PropertyValue T>
template<std::invocable< T & > Fn>
void aria::reactive::Property< T >::mutate ( Fn && fn)
inline

Mutate-in-place: always fires a change (cannot detect no-op because the mutation is opaque).

Useful for container-valued Properties where a full equality check would be expensive.

◆ on_changed()

template<PropertyValue T>
::aria::Subscription aria::reactive::Property< T >::on_changed ( std::function< void(const T &)> fn)
inlinenodiscard

Run fn(new_value) every time the value changes.

Returns a Subscription RAII handle; drop it to stop receiving callbacks. The argument borrows this property's value; copy it before mutating or destroying the property if it is needed afterwards.

◆ bind()

template<PropertyValue T>
::aria::Subscription aria::reactive::Property< T >::bind ( std::function< void(const T &)> fn)
inlinenodiscard

Fire once with the current value, then on every subsequent change.

This is the idiomatic "bind a UI widget to this property" path.

◆ observe()

template<PropertyValue T>
::aria::Subscription aria::reactive::Property< T >::observe ( std::function< void(const T &, const T &)> fn)
inlinenodiscard

Two-argument form: receive (old, new).

Implemented on top of on_changed by stashing the last-seen value in a shared cell.

◆ get_any()

template<PropertyValue T>
std::any aria::reactive::Property< T >::get_any ( ) const
inlinenodiscardoverridevirtual

Read the current value as a std::any.

The runtime type is guaranteed to equal type().

Implements aria::IProperty.

◆ set_any()

template<PropertyValue T>
bool aria::reactive::Property< T >::set_any ( const std::any & value)
inlinenodiscardoverridevirtual

Try to set the property's value from a std::any.

Returns true on success, false when the runtime types don't match (in which case the property is left unchanged).

Implements aria::IProperty.

◆ subscribe_any()

template<PropertyValue T>
::aria::Subscription aria::reactive::Property< T >::subscribe_any ( std::function< void(const std::any &)> on_changed)
inlinenodiscardoverridevirtual

Subscribe to value changes.

The callback receives the new value as std::any of the same runtime type as type().

Implements aria::IProperty.

◆ type()

template<PropertyValue T>
const std::type_info & aria::reactive::Property< T >::type ( ) const
inlinenodiscardoverridevirtualnoexcept

The runtime type of the wrapped value.

Useful for callers that want to gate their std::any_cast on a name comparison before paying the cost of the cast.

Implements aria::IProperty.


The documentation for this class was generated from the following file: