![]() |
OpenSWMM Engine
6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
|
Classes | |
| struct | Expression |
| struct | Token |
Enumerations | |
| enum class | TokenType : int { NUMBER = 0 , VARIABLE = 1 , ADD = 2 , SUB = 3 , MUL = 4 , DIV = 5 , POW = 6 , NEG = 7 , LPAREN = 8 , RPAREN = 9 , FUNC_ABS = 10 , FUNC_SGN = 11 , FUNC_SQRT = 12 , FUNC_LOG = 13 , FUNC_EXP = 14 , FUNC_SIN = 15 , FUNC_COS = 16 , FUNC_TAN = 17 , FUNC_ASIN = 18 , FUNC_ACOS = 19 , FUNC_ATAN = 20 , FUNC_STEP = 21 , FUNC_MIN = 22 , FUNC_MAX = 23 , COMMA = 24 , FUNC_COT = 25 , FUNC_SINH = 26 , FUNC_COSH = 27 , FUNC_TANH = 28 , FUNC_COTH = 29 , FUNC_LOG10 = 30 , FUNC_ACOT = 31 } |
Functions | |
| int | parse (const std::string &expr_str, Expression &result) |
| Parse an infix expression string into a postfix Expression. | |
| double | evaluate (const Expression &expr, const std::function< double(const std::string &)> &var_lookup) |
| Evaluate a compiled expression with named variable lookup. | |
| double | evaluate (const Expression &expr, const double *vars, int n_vars) |
| Evaluate with a flat variable array (by index). | |
| int | bind_variables (Expression &expr, const char *const *name_table, int n_vars) |
| Bind variable names in a compiled expression to integer indices. | |
| int | compute_max_stack_depth (const Expression &expr) |
| Compute the maximum stack depth needed to evaluate an expression. | |
| double | evaluate_fast (const Expression &expr, const double *vars) noexcept |
| Fast evaluate using pre-bound variable indices and stack-free evaluation. | |
|
strong |
| int openswmm::mathexpr::bind_variables | ( | Expression & | expr, |
| const char *const * | name_table, | ||
| int | n_vars | ||
| ) |
Bind variable names in a compiled expression to integer indices.
Resolves each VARIABLE token's var_name to a var_idx using the provided name→index table. After binding, evaluate_fast() can look up variables by index instead of by string comparison.
| expr | Expression to bind (modified in place). |
| name_table | Array of variable names, indexed 0..n_vars-1. |
| n_vars | Number of entries in name_table. |
| int openswmm::mathexpr::compute_max_stack_depth | ( | const Expression & | expr | ) |
Compute the maximum stack depth needed to evaluate an expression.
| expr | Compiled expression. |
| double openswmm::mathexpr::evaluate | ( | const Expression & | expr, |
| const double * | vars, | ||
| int | n_vars | ||
| ) |
Evaluate with a flat variable array (by index).
| expr | Compiled expression. |
| vars | Variable values indexed by var_idx. |
| n_vars | Size of vars array. |
| double openswmm::mathexpr::evaluate | ( | const Expression & | expr, |
| const std::function< double(const std::string &)> & | var_lookup | ||
| ) |
Evaluate a compiled expression with named variable lookup.
| expr | Compiled expression. |
| var_lookup | Function that maps variable name → value. |
|
noexcept |
Fast evaluate using pre-bound variable indices and stack-free evaluation.
Uses a fixed-size stack array on the C stack (no heap allocation) and reads variables via vars[tok.var_idx] (no string comparison). Variables must be pre-bound via bind_variables().
| expr | Compiled expression with bound variable indices. |
| vars | Variable values array. vars[tok.var_idx] is read for each variable. |
| int openswmm::mathexpr::parse | ( | const std::string & | expr_str, |
| Expression & | result | ||
| ) |
Parse an infix expression string into a postfix Expression.
| expr_str | Infix expression (e.g., "x * exp(-k * t)"). |
| result | [out] Compiled postfix expression. |