morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::forms::RuleExpr Class Reference

One x-rules entry, or a condition inside one, and its translation into expr/1. More...

#include <rules.hpp>

Public Types

enum class  Kind : std::uint8_t {
  Engaged , NotEngaged , Equals , Greater ,
  GreaterOrEqual , Less , LessOrEqual , RequiredWhen ,
  ExactlyOneOf , AtLeastOneOf , MutuallyExclusive , VisibleWhen ,
  ReadonlyWhen , And , Or , Not ,
  Unknown
}
 The rule kinds. More...

Public Member Functions

Kind kind () const noexcept
 The kind.
std::string_view kindName () const noexcept
 The kind as the schema spells it.
std::span< std::string const > fields () const noexcept
 The fields this node names directly (fields).
bool names (std::string_view field) const noexcept
 Whether this node names field directly. A presentation rule applies to every field it names.
RuleExpr const * when () const noexcept
 The when clause of requiredWhen, visibleWhen and readonlyWhen.
std::span< RuleExpr const > conditions () const noexcept
 The operands of and and or, or the one operand of not.
bool gates () const noexcept
 Whether the rule decides readiness. visibleWhen and readonlyWhen only present.
bool presents (Kind kind, std::string_view field) const noexcept
 Whether the rule is a presentation rule of kind that names field.
detail::engine::Json const & expression () const noexcept
 The translation, as expr/1 JSON: for a gating rule its test, for a presentation rule its when clause. Set on a node parse returned; a child node holds none.
std::span< std::string const > operands () const noexcept
 The wire names the translation reads, by operand index (f0 is the first).
Tri evaluate (RuleLookup const &lookup) const
 Evaluates the translation with the UI document's evaluator.
Tri whenHolds (RuleLookup const &lookup) const
 Evaluates the when clause of a requiredWhen, visibleWhen or readonlyWhen.

Static Public Member Functions

static std::expected< RuleExpr, SchemaError > parse (detail::engine::Json const &node, std::string const &path)
 Reads one rule or condition node and translates it.

Detailed Description

One x-rules entry, or a condition inside one, and its translation into expr/1.

The 16 kinds the emitters write are read; any other kind parses and is Unknown, so an older client never refuses a newer server's form. A rule's operands are numbered f0, f1, … in its translation, and each operand reads as two names: fN.engaged (true, false, or null when its draft does not encode) and fN.value (the encoded value, null unless it is valid). The two are needed because a blank operand and an invalid one are both "no value" to the expression language, and the rules tell them apart: a comparison with a blank operand holds vacuously, one with an invalid operand is Unknown.

Definition at line 191 of file rules.hpp.

Member Enumeration Documentation

◆ Kind

enum class morph::forms::RuleExpr::Kind : std::uint8_t
strong

The rule kinds.

Enumerator
Engaged 

engaged: the field has a value.

NotEngaged 

notEngaged.

Equals 

equals: the field equals the literal value (valueText for wide integers).

Greater 

greater: the first field is greater than the second, when both are engaged.

GreaterOrEqual 

greaterOrEqual.

Less 

less.

LessOrEqual 

lessOrEqual.

RequiredWhen 

requiredWhen: the fields are required while when holds.

ExactlyOneOf 

exactlyOneOf: exactly one field is engaged.

AtLeastOneOf 

atLeastOneOf.

MutuallyExclusive 

mutuallyExclusive: at most one field is engaged.

VisibleWhen 

visibleWhen: presentation; the fields are shown while when holds.

ReadonlyWhen 

readonlyWhen: presentation; the fields are frozen while when holds.

And 

and over conditions.

Or 

or over conditions.

Not 

not of condition.

Unknown 

A kind this engine does not know.

Definition at line 194 of file rules.hpp.

Member Function Documentation

◆ parse()

std::expected< RuleExpr, SchemaError > morph::forms::RuleExpr::parse ( detail::engine::Json const & node,
std::string const & path )
inlinestaticnodiscard

Reads one rule or condition node and translates it.

Parameters
nodeThe node.
pathWhere it is, for errors.
Returns
The rule, or why it does not read: a node that is not an object, a missing kind, a malformed fields, a known kind without the operands it needs, or a translation larger than expr/1 admits.

Definition at line 219 of file rules.hpp.

◆ kind()

Kind morph::forms::RuleExpr::kind ( ) const
inlinenodiscardnoexcept

The kind.

Returns
The kind; Unknown for a kind this engine does not know.

Definition at line 241 of file rules.hpp.

◆ kindName()

std::string_view morph::forms::RuleExpr::kindName ( ) const
inlinenodiscardnoexcept

The kind as the schema spells it.

Returns
The kind string.

Definition at line 245 of file rules.hpp.

◆ fields()

std::span< std::string const > morph::forms::RuleExpr::fields ( ) const
inlinenodiscardnoexcept

The fields this node names directly (fields).

Returns
The wire names.

Definition at line 249 of file rules.hpp.

◆ names()

bool morph::forms::RuleExpr::names ( std::string_view field) const
inlinenodiscardnoexcept

Whether this node names field directly. A presentation rule applies to every field it names.

Parameters
fieldThe wire name.
Returns
Whether it is among fields().

Definition at line 254 of file rules.hpp.

◆ when()

RuleExpr const * morph::forms::RuleExpr::when ( ) const
inlinenodiscardnoexcept

The when clause of requiredWhen, visibleWhen and readonlyWhen.

Returns
The clause, or null for any other kind.

Definition at line 260 of file rules.hpp.

◆ conditions()

std::span< RuleExpr const > morph::forms::RuleExpr::conditions ( ) const
inlinenodiscardnoexcept

The operands of and and or, or the one operand of not.

Returns
The child conditions; empty for any other kind.

Definition at line 267 of file rules.hpp.

◆ gates()

bool morph::forms::RuleExpr::gates ( ) const
inlinenodiscardnoexcept

Whether the rule decides readiness. visibleWhen and readonlyWhen only present.

Returns
false for the presentation kinds.

Definition at line 274 of file rules.hpp.

◆ presents()

bool morph::forms::RuleExpr::presents ( Kind kind,
std::string_view field ) const
inlinenodiscardnoexcept

Whether the rule is a presentation rule of kind that names field.

Parameters
kindRequiredWhen, VisibleWhen or ReadonlyWhen.
fieldThe wire name.
Returns
Whether it applies to the field's presentation.

Definition at line 280 of file rules.hpp.

◆ expression()

detail::engine::Json const & morph::forms::RuleExpr::expression ( ) const
inlinenodiscardnoexcept

The translation, as expr/1 JSON: for a gating rule its test, for a presentation rule its when clause. Set on a node parse returned; a child node holds none.

Returns
The expression's JSON.

Definition at line 287 of file rules.hpp.

◆ operands()

std::span< std::string const > morph::forms::RuleExpr::operands ( ) const
inlinenodiscardnoexcept

The wire names the translation reads, by operand index (f0 is the first).

Returns
The operands.

Definition at line 291 of file rules.hpp.

◆ evaluate()

Tri morph::forms::RuleExpr::evaluate ( RuleLookup const & lookup) const
inlinenodiscard

Evaluates the translation with the UI document's evaluator.

For a gating rule this is its test; for visibleWhen, readonlyWhen and the presentation side of requiredWhen use whenHolds.

Parameters
lookupReads each operand.
Returns
The verdict: null is Unknown.

Definition at line 299 of file rules.hpp.

◆ whenHolds()

Tri morph::forms::RuleExpr::whenHolds ( RuleLookup const & lookup) const
inlinenodiscard

Evaluates the when clause of a requiredWhen, visibleWhen or readonlyWhen.

Parameters
lookupReads each operand.
Returns
The clause's verdict; Unknown for any other kind.

Definition at line 310 of file rules.hpp.


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