morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::ui::author::Handle< T > Class Template Reference

An expression of a document, typed by the C++ value it evaluates to (spec 5 §11). More...

#include <author.hpp>

Public Types

using ValueType = T
 The C++ type of the value.

Public Member Functions

 Handle ()=default
 An absent handle.
template<typename L>
requires detail::Literal<std::remove_cvref_t<L>> && (detail::assignable<detail::LiteralT<L>, T>())
 Handle (L const &literal)
 A constant.
template<typename U>
requires (!std::same_as<U, T>) && (detail::assignable<U, T>())
 Handle (Handle< U > const &other)
 A handle of another value type that can stand for this one.
bool present () const noexcept
 Whether the handle holds an expression.
Json const & json () const
 The expression's JSON.
template<typename Class, typename Member>
requires std::same_as<T, Any> || std::same_as<detail::UnwrappedT<T>, Class>
Handle< Member > at (Member Class::*member) const
 A field of the value, by member pointer: a renamed field is a compile error.
Handle< Any > at (std::string_view field) const
 A field of the value, by name.
Handle orElse (Handle const &fallback) const
 The value, or a fallback when it is null.

Static Public Member Functions

static Handle raw (Json json)
 A handle over an expression's JSON, for a form no builder spells.

Detailed Description

template<typename T = Any>
class morph::ui::author::Handle< T >

An expression of a document, typed by the C++ value it evaluates to (spec 5 §11).

A handle is a JSON expression tree. Operators build calls of the expr/1 library: a + b is add, a < b is lt, a && b is and, !a is not; at reads a field by member pointer, and orElse is coalesce. A default-constructed handle is absent: a builder leaves out the key it would fill.

Template Parameters
TThe C++ type of the value, Any when the screen cannot know it.

Definition at line 648 of file author.hpp.

Member Typedef Documentation

◆ ValueType

template<typename T = Any>
using morph::ui::author::Handle< T >::ValueType = T

The C++ type of the value.

Definition at line 651 of file author.hpp.

Constructor & Destructor Documentation

◆ Handle() [1/2]

template<typename T = Any>
template<typename L>
requires detail::Literal<std::remove_cvref_t<L>> && (detail::assignable<detail::LiteralT<L>, T>())
morph::ui::author::Handle< T >::Handle ( L const & literal)
inline

A constant.

Template Parameters
LThe constant's C++ type, which must be able to stand for T.
Parameters
literalThe constant.

Definition at line 661 of file author.hpp.

◆ Handle() [2/2]

template<typename T = Any>
template<typename U>
requires (!std::same_as<U, T>) && (detail::assignable<U, T>())
morph::ui::author::Handle< T >::Handle ( Handle< U > const & other)
inline

A handle of another value type that can stand for this one.

Template Parameters
UThe other value type.
Parameters
otherThe handle.

Definition at line 669 of file author.hpp.

Member Function Documentation

◆ raw()

template<typename T = Any>
Handle morph::ui::author::Handle< T >::raw ( Json json)
inlinestaticnodiscard

A handle over an expression's JSON, for a form no builder spells.

Parameters
jsonThe expression.
Returns
The handle.

Definition at line 675 of file author.hpp.

◆ present()

template<typename T = Any>
bool morph::ui::author::Handle< T >::present ( ) const
inlinenodiscardnoexcept

Whether the handle holds an expression.

Returns
False for a default-constructed handle.

Definition at line 683 of file author.hpp.

◆ json()

template<typename T = Any>
Json const & morph::ui::author::Handle< T >::json ( ) const
inlinenodiscard

The expression's JSON.

Returns
The JSON.
Exceptions
AuthoringErrorwhen the handle is absent.

Definition at line 688 of file author.hpp.

◆ at() [1/2]

template<typename T = Any>
template<typename Class, typename Member>
requires std::same_as<T, Any> || std::same_as<detail::UnwrappedT<T>, Class>
Handle< Member > morph::ui::author::Handle< T >::at ( Member Class::* member) const
inlinenodiscard

A field of the value, by member pointer: a renamed field is a compile error.

Template Parameters
ClassThe class of the member, the value's type.
MemberThe member's type.
Parameters
memberThe member.
Returns
The field read.
Exceptions
AuthoringErrorwhen the handle is not a named read.

Definition at line 703 of file author.hpp.

◆ at() [2/2]

template<typename T = Any>
Handle< Any > morph::ui::author::Handle< T >::at ( std::string_view field) const
inlinenodiscard

A field of the value, by name.

Parameters
fieldThe field, or a dotted path.
Returns
The field read.
Exceptions
AuthoringErrorwhen the handle is not a named read.

Definition at line 711 of file author.hpp.

◆ orElse()

template<typename T = Any>
Handle morph::ui::author::Handle< T >::orElse ( Handle< T > const & fallback) const
inlinenodiscard

The value, or a fallback when it is null.

Parameters
fallbackThe fallback.
Returns
coalesce(this, fallback).

Definition at line 718 of file author.hpp.


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