RuleBuilder.h header

#include <ew/app/RuleBuilder.h>

Namespace ew::app

BuiltRule struct

struct ew::app::BuiltRule

A rule as the builder holds it, before it becomes an expression.

Members

QString ew::app::expression::BuiltRule::propertyPath

The property being asserted about, as a path on the object the rule applies to.

RuleOperator ew::app::expression::BuiltRule::op =

What is being asserted.

RuleOperand ew::app::expression::BuiltRule::operand

What it is asserted against; ignored when operatorTakesOperand is false.

bool operator==(const BuiltRule &, const BuiltRule &)=default

Two rules are equal when every field matches.

PropertyChoice struct

struct ew::app::PropertyChoice

One property a rule can be written about, as a menu offers it.

Members

QString ew::app::expression::PropertyChoice::path

The path an expression names it by: price, stats.strength, inventory[].weight.

QString ew::app::expression::PropertyChoice::label

What a menu shows: the property's label, and the way in for a nested one.

ew::core::taxonomy::FieldType ew::app::expression::PropertyChoice::type =

The type, which decides which operators are offered.

ew::core::taxonomy::FieldType ew::app::expression::PropertyChoice::elementType =

A List's element type; meaningless for every other type.

bool operator==(const PropertyChoice &, const PropertyChoice &)=default

Two choices are equal when every field matches.

RuleOperand struct

struct ew::app::RuleOperand

The right-hand side of a comparison.

Members

OperandKind ew::app::expression::RuleOperand::kind =

Which of the four kinds this is.

QString ew::app::expression::RuleOperand::literal

The typed value, for OperandKind::Literal.

QString ew::app::expression::RuleOperand::path

The property path, for the other three kinds: money, owner.name, stats.strength.

ew::core::foundation::ContentId ew::app::expression::RuleOperand::objectId

The object named, for OperandKind::NamedObject.

bool operator==(const RuleOperand &, const RuleOperand &)=default

Two operands are equal when every field matches.

Enumerations

enum class OperandKind { Literal, SameObject, Traversed, NamedObject }

What the right-hand side of a comparison is.

enum class RuleOperator { Equals, NotEquals, LessThan, LessOrEqual, GreaterThan, GreaterOrEqual, Contains, NotContains, StartsWith, EndsWith, Matches, LengthAtLeast, LengthAtMost, IsTrue, IsFalse, IsEmpty, IsNotEmpty, CountEquals, CountAtLeast, CountAtMost, ListContains, ListExcludes, AllAbove, AllBelow, AnyAbove, HasKey }

What a rule can assert about a property, in the vocabulary a person picks from.

Offered by the property's TYPE, never in full. A menu that let an author ask whether a number starts with a word, or whether a date is longer than five, is a menu that produces rules which are not wrong so much as meaningless – and the author finds out from a conflict report weeks later. Every one of these compiles to an expression in the shared language (see toExpression), so the builder is a way of WRITING the expression, never a second engine with its own opinions.

Functions

std::optional< BuiltRule > ew::app::expression::fromExpression(const ew::core::project::Project &project, const QString &expression)

The rule expression describes, or std::nullopt when it says something the builder cannot.

The round trip is the feature, not a convenience: an author who drops to the raw editor to write something the menus cannot say must be able to come back, and a builder that silently discarded what it did not understand would eat their rule. Anything this cannot read stays in the raw editor, and the builder says so rather than guessing.

QString ew::app::expression::operatorPhrase(RuleOperator op)

The phrase op reads as in the rule's plain-language readout ("must be less than").

bool ew::app::expression::operatorTakesOperand(RuleOperator op)

Whether op compares against a second operand at all (false for is-true, is-empty, ...).

std::vector< RuleOperator > ew::app::expression::operatorsFor(ew::core::taxonomy::FieldType type, ew::core::taxonomy::FieldType elementType=ew::core::taxonomy::FieldType::Text)

The operators a property of type can meaningfully carry, in the order a menu should offer them. elementType is the List's element type, ignored for every other type.

std::vector< PropertyChoice > ew::app::expression::propertyChoicesFor(const ew::core::project::Project &project, const ew::core::entity::Entity &sample)

The properties a rule about sample can be written over: its own, its blocks' members, and one hop through each reference (including through a list of them, as inventory[].weight).

Read off a real object rather than a category, because that is the only place the answer is complete: a property can arrive from a category chain, from another entity's own properties crossing a boundary, or from the object itself, and asking the taxonomy alone would silently leave out the last two.

One hop, not two: two would enumerate the codex, and the raw editor is there for the rest.

QString ew::app::expression::readout(const ew::core::project::Project &project, const BuiltRule &rule, const QString &subject)

The plain-language readout of rule – "Sue's money must be less than John's money".

Shown above the builder at all times, because a menu of three dropdowns is a shape rather than a sentence, and the mistake it hides is picking the wrong one of two similarly-named properties.

std::optional< RuleOperator > ew::app::expression::ruleOperatorFromToken(QStringView token)

Parses an operator token; std::nullopt when unrecognized.

QString ew::app::expression::toExpression(const ew::core::project::Project &project, const BuiltRule &rule)

The expression rule means, ready to store on a ContinuityRule.

Object references come out in their stored form (by id), so a rule the builder wrote survives renaming exactly as a hand-written one does.

QString ew::app::expression::toToken(RuleOperator op)

The stable serialization token for op ("equals", "starts-with", "all-above").