Expression evaluation

PUEL calculators and unit-expression solvers.

class Calculator
#include <calculator.h>

Evaluates PUEL expressions and returns PUQ results.

Public Functions

Calculator() = default
CalculatorAtom eval(const std::string &expression)

Public Static Attributes

static exs::Solver<CalculatorAtom> solver
class CalculatorAtom : public snt::exs::AtomBase<CalculatorAtom, Quantity>
#include <calculator_atom.h>

EXS atom that evaluates a PUQ quantity expression.

Public Functions

CalculatorAtom(const CalculatorAtom &a) = default
inline CalculatorAtom(Quantity v)
virtual std::string to_string() override

Get a string representation of an atom

void math_add(CalculatorAtom *other) override

Add another quantity atom, including its units and uncertainty.

Parameters:

other – Quantity atom to add; dimensions must be compatible.

void math_subtract(CalculatorAtom *other) override
virtual void math_negate() override

Negate value of this value

void math_multiply(CalculatorAtom *other) override
void math_divide(CalculatorAtom *other) override

Public Static Functions

static Quantity from_string(std::string &s, exs::BaseSettings *set = nullptr)
class UnitAtom : public snt::exs::AtomBase<UnitAtom, Measurement>
#include <unit_atom.h>

EXS atom that resolves a unit expression to a PUQ measurement.

Public Functions

UnitAtom(const UnitAtom&) = default
inline UnitAtom(Measurement v)
virtual std::string to_string() override

Get a string representation of an atom

void math_power(ExponentVariant &e)
void math_power(UnitAtom *other) override
void math_multiply(UnitAtom *other) override
void math_divide(UnitAtom *other) override

Public Static Functions

static Measurement from_string(const std::string &s, exs::BaseSettings *set = nullptr)
class UnitSolver
#include <unit_solver.h>

Calcuates unit atoms from unit expressions

In order to speed up calculations of units this class is caching input unit expression strings and stores already calculated unit atoms in a cache map. This should avoid repeated calculations of the same inputs.

Public Functions

UnitSolver() = default

Default constructor

UnitAtom eval(const std::string &expression)

Solve unit expression

Parameters:

expression – Unit expression that will be solved

Returns:

Solved unit atom

Public Static Attributes

static exs::Solver<UnitAtom> solver

static instance of an unit solver

static std::unordered_map<std::string, UnitAtom> cache

list of previously calculated atoms