Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::Property< T > Class Template Reference

UI-owned typed value with node-scoped observers and explicit partial delivery. WidgetTree and its Scheduler are borrowed and must outlive this object. All operations and destruction use the UI thread. Retained snapshots may outlive every UI owner. Each changed set invalidates the source target synchronously, then publishes in observer registration order on the data lane with reject overflow. No atomic multicast is promised. Callbacks run only through Scheduler between frames; reentrant set appends notifications after already accepted events. Scheduler budgets bound a self-updating callback chain. T construction/copy/move/comparison and callback construction/move must not reenter UI APIs. T destruction may reenter after replacement: the old value is retained until all publication attempts finish. Destructors must not throw or call members of an object being destroyed. More...

#include <property.hpp>

Public Member Functions

 ~Property ()
 Logically close the source; executing callbacks retain their captures until return. Existing Subscription tokens remain ordinary Scheduler tokens and may be disconnected later. Their callbacks are suppressed after source closure. Wrong-thread destruction terminates, matching the UI ownership contract of Subscription and WidgetTree.
 Property (const Property &)=delete
Property & operator= (const Property &)=delete
std::expected< std::shared_ptr< const PropertyChange< T > >, TreeError > snapshot () const
 Obtain an independent immutable owner, even after the target node was removed. Access on another thread returns WRONG_THREAD. Transfer requires T to support destruction on the thread releasing the last owner; UI reentry from T destruction requires a live UI context.
std::expected< PropertyUpdate< T >, TreeError > set (const T &value)
 Commit a changed value and invalidate its target before attempting notifications. unexpected means no library-controlled value, revision, queue or invalidation change. A successful changed receipt may contain rejected/cancelled notifications. Never retry set as a way to deliver the missing events: equal set is a no-op. Consumers can read snapshot to resync. Tree affinity/session/lifetime/frame failures propagate; revision overflow is IDENTITY_EXHAUSTED. Allocation or T comparison/copy failures occur before commit.
std::expected< PropertyUpdate< T >, TreeError > set (T &&value)
 Commit a candidate by moving it directly into the immutable snapshot. Commit and notification semantics match set(const T&). There is no intermediate T. Escaping exceptions are translated. Termination inside a noexcept T move cannot be caught.
template<class W, class Callback>
std::expected< Subscription, TreeError > observe (Node< W > receiver, Callback &&callback)
 Register an ordinary Subscription tied to a receiving node in the same tree. The callback owns its captures and receives (W&, shared_ptr<const PropertyChange<T>>). The entire callback borrows W through WidgetTree::connect, so removal during invocation defers widget destruction. Source destruction suppresses later callbacks independently. Registration does not send the initial value or invalidate the receiving node; the source target is invalidated by set. Additional receiver changes request their own invalidation. Expired endpoint records are reclaimed before the finite limit is checked (NODE_LIMIT). Reentrant destruction during registration rechecks capacity and source lifetime (closed). Tree/Scheduler errors propagate; callback construction exceptions become CALLBACK_FAILED.

Static Public Member Functions

static std::expected< std::unique_ptr< Property >, TreeError > create (WidgetTree &tree, Node< Widget > target, const T &initial, Invalidation kind, PropertyOptions options={})
 Create a source bound to one checked invalidation target; no initial notification. The target must belong to tree and be live outside a frame. Invalid kind/zero capacity is INVALID_ARGUMENT; allocation failure is NO_MEMORY. T exceptions are CALLBACK_FAILED. The const-reference overload copies directly inside the error boundary; T must support copying.
static std::expected< std::unique_ptr< Property >, TreeError > create (WidgetTree &tree, Node< Widget > target, T &&initial, Invalidation kind, PropertyOptions options={})
 Create a source by moving its initial value directly into the snapshot. Validation and lifetime match the const-reference overload. There is no intermediate T. Escaping exceptions are translated. Termination inside a noexcept T move cannot be caught.

Friends

struct detail::ManagedNavigationRecord

Detailed Description

template<std::equality_comparable T>
class portals::Property< T >

UI-owned typed value with node-scoped observers and explicit partial delivery. WidgetTree and its Scheduler are borrowed and must outlive this object. All operations and destruction use the UI thread. Retained snapshots may outlive every UI owner. Each changed set invalidates the source target synchronously, then publishes in observer registration order on the data lane with reject overflow. No atomic multicast is promised. Callbacks run only through Scheduler between frames; reentrant set appends notifications after already accepted events. Scheduler budgets bound a self-updating callback chain. T construction/copy/move/comparison and callback construction/move must not reenter UI APIs. T destruction may reenter after replacement: the old value is retained until all publication attempts finish. Destructors must not throw or call members of an object being destroyed.

Template Parameters
TEquality-comparable value constructible from T&&, owning its data transitively. Published aliases must remain immutable; construction/copy/move/comparison must not reenter UI APIs and destruction must not throw. Operations of T must not terminate; a noexcept move that allocates cannot report failure through this API. Const-reference overloads additionally require an actual valid copy operation, rather than relying on copy traits.

Member Function Documentation

◆ create() [1/2]

template<std::equality_comparable T>
std::expected< std::unique_ptr< Property >, TreeError > portals::Property< T >::create ( WidgetTree & tree,
Node< Widget > target,
const T & initial,
Invalidation kind,
PropertyOptions options = {} )
inlinestatic

Create a source bound to one checked invalidation target; no initial notification. The target must belong to tree and be live outside a frame. Invalid kind/zero capacity is INVALID_ARGUMENT; allocation failure is NO_MEMORY. T exceptions are CALLBACK_FAILED. The const-reference overload copies directly inside the error boundary; T must support copying.

Parameters
treeBorrowed UI-owned tree and scheduler, both required to outlive the property.
targetLive node in tree invalidated by each changed set.
initialBorrowed value copied into immutable revision zero; retained only during this call.
kindInvalidation to request on change; none explicitly requests no work.
optionsPositive observer endpoint limit.
Returns
New property, tree validation/frame errors, INVALID_ARGUMENT, NO_MEMORY, or CALLBACK_FAILED.

◆ create() [2/2]

template<std::equality_comparable T>
std::expected< std::unique_ptr< Property >, TreeError > portals::Property< T >::create ( WidgetTree & tree,
Node< Widget > target,
T && initial,
Invalidation kind,
PropertyOptions options = {} )
inlinestatic

Create a source by moving its initial value directly into the snapshot. Validation and lifetime match the const-reference overload. There is no intermediate T. Escaping exceptions are translated. Termination inside a noexcept T move cannot be caught.

Parameters
treeBorrowed UI tree and scheduler; both must outlive this property.
targetLive node invalidated by each changed set.
initialCandidate moved after target/options validation; borrowed until return.
kindInvalidation requested on change; NONE requests no work.
optionsPositive observer endpoint limit.
Returns
New property or validation/frame error, INVALID_ARGUMENT, NO_MEMORY, CALLBACK_FAILED.

◆ observe()

template<std::equality_comparable T>
template<class W, class Callback>
std::expected< Subscription, TreeError > portals::Property< T >::observe ( Node< W > receiver,
Callback && callback )
inline

Register an ordinary Subscription tied to a receiving node in the same tree. The callback owns its captures and receives (W&, shared_ptr<const PropertyChange<T>>). The entire callback borrows W through WidgetTree::connect, so removal during invocation defers widget destruction. Source destruction suppresses later callbacks independently. Registration does not send the initial value or invalidate the receiving node; the source target is invalidated by set. Additional receiver changes request their own invalidation. Expired endpoint records are reclaimed before the finite limit is checked (NODE_LIMIT). Reentrant destruction during registration rechecks capacity and source lifetime (closed). Tree/Scheduler errors propagate; callback construction exceptions become CALLBACK_FAILED.

Template Parameters
WWidget or a publicly derived extension type represented by receiver.
CallbackCopy-constructible callable accepting W& and std::shared_ptr<const PropertyChange<T>> as an lvalue; its return value is ignored.
Parameters
receiverLive receiving node in the property's tree; removal cancels its scoped callback.
callbackOwned callable; widget references must not escape, but the snapshot owner may be retained.
Returns
Subscription token with no initial delivery; tree/scheduler errors, NODE_LIMIT, closed, NO_MEMORY, or CALLBACK_FAILED on registration failure.

◆ set() [1/2]

template<std::equality_comparable T>
std::expected< PropertyUpdate< T >, TreeError > portals::Property< T >::set ( const T & value)
inline

Commit a changed value and invalidate its target before attempting notifications. unexpected means no library-controlled value, revision, queue or invalidation change. A successful changed receipt may contain rejected/cancelled notifications. Never retry set as a way to deliver the missing events: equal set is a no-op. Consumers can read snapshot to resync. Tree affinity/session/lifetime/frame failures propagate; revision overflow is IDENTITY_EXHAUSTED. Allocation or T comparison/copy failures occur before commit.

Parameters
valueBorrowed candidate compared first and copied directly into the snapshot only if changed; T must support copying.
Returns
Receipt for this operation's immutable revision and per-observer queue acceptance, including partial failure; an unexpected TreeError means no library-controlled commit occurred.

◆ set() [2/2]

template<std::equality_comparable T>
std::expected< PropertyUpdate< T >, TreeError > portals::Property< T >::set ( T && value)
inline

Commit a candidate by moving it directly into the immutable snapshot. Commit and notification semantics match set(const T&). There is no intermediate T. Escaping exceptions are translated. Termination inside a noexcept T move cannot be caught.

Parameters
valueCandidate compared first and moved only for a changed value. After construction it is moved-from, including when later invalidation failure rejects the commit.
Returns
Exact snapshot/notification receipt, or a TreeError without a property commit.

◆ snapshot()

template<std::equality_comparable T>
std::expected< std::shared_ptr< const PropertyChange< T > >, TreeError > portals::Property< T >::snapshot ( ) const
inline

Obtain an independent immutable owner, even after the target node was removed. Access on another thread returns WRONG_THREAD. Transfer requires T to support destruction on the thread releasing the last owner; UI reentry from T destruction requires a live UI context.

Returns
Owning immutable value/revision pair, or WRONG_THREAD without accessing the value.

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