morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn > Struct Template Reference

An optionally-empty value selected from options served by another action. More...

#include <choice.hpp>

Public Member Functions

constexpr Choice () noexcept=default
 Constructs the empty state.
constexpr Choice (T selected) noexcept(std::is_nothrow_move_constructible_v< T >)
 Engages with selected.
constexpr Choice (std::optional< T > payload) noexcept(std::is_nothrow_move_constructible_v< T >)
 Adopts an optional payload as-is.
constexpr bool hasValue () const noexcept
 Whether a value has been selected.
constexpr const T & operator* () const noexcept
 Unchecked access to the selected value (UB when empty, exactly like std::optional — the unchecked contract is the point).
constexpr bool operator== (const Choice &other) const noexcept=default
 Equality on the payload; empty equals only empty.

Static Public Member Functions

static constexpr std::string_view optionsAction () noexcept
 Type id of the action that serves the options.
static constexpr std::string_view valueField () noexcept
 Result-row field submitted as the value.
static constexpr std::string_view labelField () noexcept
 Result-row field displayed to the user.
static constexpr std::array< std::string_view, sizeof...(DependsOn)> optionsDependsOn () noexcept
 Wire field names of sibling fields whose current values parameterise the options action (a cascading picklist).

Public Attributes

std::optional< T > value
 The payload; std::nullopt means "nothing selected".

Detailed Description

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
struct morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >

An optionally-empty value selected from options served by another action.

Template Parameters
TUnderlying value type submitted on the wire (e.g. std::int64_t for ids, std::string for codes).
OptionsActionType id of the registered action whose result provides the options. Executed with an empty body when DependsOn is empty (the common case); otherwise with a body built from the current values of the named sibling fields.
ValueFieldField of each result row submitted as the value.
LabelFieldField of each result row shown to the user.
DependsOnWire (JSON) field names of sibling fields in the same action whose current values parameterise the options action — a cascading picklist. Empty by default, which makes the options action independent (today's behavior, unchanged).

Definition at line 86 of file choice.hpp.

Constructor & Destructor Documentation

◆ Choice() [1/2]

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::Choice ( T selected)
inlineconstexprnoexcept

Engages with selected.

Parameters
selectedThe selected value.

Definition at line 95 of file choice.hpp.

◆ Choice() [2/2]

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::Choice ( std::optional< T > payload)
inlineconstexprnoexcept

Adopts an optional payload as-is.

Parameters
payloadEngaged or empty payload.

Definition at line 99 of file choice.hpp.

Member Function Documentation

◆ optionsAction()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
constexpr std::string_view morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::optionsAction ( )
inlinestaticnodiscardconstexprnoexcept

Type id of the action that serves the options.

Returns
The action name declared in the field's type.

Definition at line 104 of file choice.hpp.

◆ valueField()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
constexpr std::string_view morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::valueField ( )
inlinestaticnodiscardconstexprnoexcept

Result-row field submitted as the value.

Returns
The field name declared in the field's type.

Definition at line 108 of file choice.hpp.

◆ labelField()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
constexpr std::string_view morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::labelField ( )
inlinestaticnodiscardconstexprnoexcept

Result-row field displayed to the user.

Returns
The field name declared in the field's type.

Definition at line 112 of file choice.hpp.

◆ optionsDependsOn()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
constexpr std::array< std::string_view, sizeof...(DependsOn)> morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::optionsDependsOn ( )
inlinestaticnodiscardconstexprnoexcept

Wire field names of sibling fields whose current values parameterise the options action (a cascading picklist).

Returns
The declared DependsOn names, in declaration order; empty for an independent Choice (the default).

Definition at line 118 of file choice.hpp.

◆ hasValue()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
bool morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::hasValue ( ) const
inlinenodiscardconstexprnoexcept

Whether a value has been selected.

Returns
true if the payload is engaged.

Definition at line 124 of file choice.hpp.

◆ operator*()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
const T & morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::operator* ( ) const
inlinenodiscardconstexprnoexcept

Unchecked access to the selected value (UB when empty, exactly like std::optional — the unchecked contract is the point).

Returns
The selected value — a reference into this Choice, valid only for as long as it is.

Definition at line 131 of file choice.hpp.

◆ operator==()

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
bool morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::operator== ( const Choice< T, OptionsAction, ValueField, LabelField, DependsOn > & other) const
nodiscardconstexprdefaultnoexcept

Equality on the payload; empty equals only empty.

Parameters
otherChoice to compare against.
Returns
true when both are empty or both hold equal values.

Member Data Documentation

◆ value

template<typename T, FixedString OptionsAction, FixedString ValueField = "id", FixedString LabelField = "name", FixedString... DependsOn>
std::optional<T> morph::forms::Choice< T, OptionsAction, ValueField, LabelField, DependsOn >::value

The payload; std::nullopt means "nothing selected".

Definition at line 88 of file choice.hpp.


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