GGUI::GGExpr class

GGExpr: a value computed from fields and constants.

Stored as a short postfix program: trivially copyable, comparable, no allocation. An expression that overflows MaxOps is invalid (IsValid) and evaluates to 0.

Public static variables

static uint32_t MaxOps constexpr
the most steps an expression has: constants, fields, and operations

Public static functions

static auto Field(FieldID field) -> GGExpr
The value of field field.

Constructors, destructors, conversion operators

GGExpr() defaulted
Empty: not valid.
GGExpr(float constant)
A constant, so health < 1.0f works.

Public functions

auto IsValid() const -> bool
Whether it computes something: not empty, and within MaxOps.
auto Evaluate(const BindingReader& reader, BindTarget target, bool& bValid) const -> float
Its value for target. bValid is false if a field couldn't be read.
auto IsOneField(FieldID& field) const -> bool
True if the expression is exactly one field; field receives it.
template<typename TFn>
void ForEachField(TFn&& fn) const
fn(field) for each field it reads, in order, repeats included.

Friends

auto operator+(const GGExpr& a, const GGExpr& b) -> GGExpr
a plus b.
auto operator-(const GGExpr& a, const GGExpr& b) -> GGExpr
a minus b.
auto operator*(const GGExpr& a, const GGExpr& b) -> GGExpr
a times b.
auto operator/(const GGExpr& a, const GGExpr& b) -> GGExpr
a over b.
auto operator<(const GGExpr& a, const GGExpr& b) -> GGExpr
1 if a is less than b, else 0.
auto operator>(const GGExpr& a, const GGExpr& b) -> GGExpr
1 if a is more than b, else 0.
auto operator<=(const GGExpr& a, const GGExpr& b) -> GGExpr
1 if a is at most b, else 0.
auto operator>=(const GGExpr& a, const GGExpr& b) -> GGExpr
1 if a is at least b, else 0.
auto Min(const GGExpr& a, const GGExpr& b) -> GGExpr
The smaller of a and b.
auto Max(const GGExpr& a, const GGExpr& b) -> GGExpr
The larger of a and b.
auto Clamp(const GGExpr& x, const GGExpr& low, const GGExpr& high) -> GGExpr
x kept between low and high.
auto Normalize(const GGExpr& x, const GGExpr& low, const GGExpr& high) -> GGExpr
Position of x between low and high, as 0..1.
auto Lerp(const GGExpr& a, const GGExpr& b, const GGExpr& t) -> GGExpr
a at t 0, b at t 1, and in between on a line.
auto Select(const GGExpr& condition, const GGExpr& whenTrue, const GGExpr& whenFalse) -> GGExpr
whenTrue if condition is non-zero.
auto operator==(const GGExpr& a, const GGExpr& b) -> bool
Program equality. Bindings with equal expressions and targets are the same binding.