![]() |
OpenSWMM Engine
6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
|
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 | |
| const std::vector< std::string > & | function_names () |
| Return recognized built-in function names in stable token order. | |
| int | parse (const std::string &expr_str, Expression &result) |
| Tokenize an infix expression and construct its postfix representation. | |
| double | evaluate (const Expression &expr, const std::function< double(const std::string &)> &var_lookup) |
| Evaluate postfix tokens with a synchronous named-variable callback. | |
| double | evaluate (const Expression &expr, const double *vars, int n_vars) |
| Evaluate using variable indices stored in a compiled expression. | |
| int | bind_variables (Expression &expr, const char *const *name_table, int n_vars) |
| Bind each variable token to the first matching table entry. | |
| int | compute_max_stack_depth (const Expression &expr) |
| Compute the peak operand-stack occupancy implied by postfix tokens. | |
| double | evaluate_fast (const Expression &expr, const double *vars) noexcept |
| Evaluate the supported postfix subset with a fixed 32-value stack. | |
|
strong |
| int openswmm::mathexpr::bind_variables | ( | Expression & | expr, |
| const char *const * | name_table, | ||
| int | n_vars ) |
Bind each variable token to the first matching table entry.
| [in,out] | expr | Expression whose variable indices are reset to -1 before resolution; variable names and postfix order remain unchanged. |
| [in] | name_table | Borrowed array of n_vars non-null, null-terminated names. Each table name is matched as a case-insensitive prefix of the expression's variable name; ordering determines which prefix wins. |
| [in] | n_vars | Nonnegative number of table entries. |
| int openswmm::mathexpr::compute_max_stack_depth | ( | const Expression & | expr | ) |
Compute the peak operand-stack occupancy implied by postfix tokens.
| [in] | expr | Compiled expression; not modified or validated. |
| double openswmm::mathexpr::evaluate | ( | const Expression & | expr, |
| const double * | vars, | ||
| int | n_vars ) |
Evaluate using variable indices stored in a compiled expression.
| [in] | expr | Well-formed postfix expression; not modified. The first variable token matching each name supplies the index for that name. |
| [in] | vars | Borrowed array of n_vars values, non-null whenever a bound index in [0, n_vars) is read. No pointer is retained. |
| [in] | n_vars | Nonnegative number of available variable values. |
| double openswmm::mathexpr::evaluate | ( | const Expression & | expr, |
| const std::function< double(const std::string &)> & | var_lookup ) |
Evaluate postfix tokens with a synchronous named-variable callback.
| [in] | expr | Well-formed postfix expression with sufficient operands for every operation; the valid flag is not checked by this overload. |
| [in] | var_lookup | Nonempty callback returning a value for each variable name, invoked once per occurrence. It is not retained. |
Division by zero, a negative square-root argument, and nonpositive logarithm arguments produce zero. Other math domain and range behavior follows the standard library. Callback and allocation exceptions propagate.
|
noexcept |
Evaluate the supported postfix subset with a fixed 32-value stack.
| [in] | expr | Well-formed expression with bound variable indices and maximum stack depth <= 32; not modified. |
| [in] | vars | Borrowed array large enough for every nonnegative var_idx; non-null whenever such an index is read. Negative indices contribute zero. |
Performs no heap allocation and retains no arrays. Division by zero, negative square roots and nonpositive natural logarithms produce zero, as in evaluate(). Other math operations follow standard-library floating-point behavior. compute_max_stack_depth() can check the depth.
| const std::vector< std::string > & openswmm::mathexpr::function_names | ( | ) |
Return recognized built-in function names in stable token order.
| int openswmm::mathexpr::parse | ( | const std::string & | expr_str, |
| Expression & | result ) |
Tokenize an infix expression and construct its postfix representation.
| [in] | expr_str | Expression text; built-in function names are case-insensitive and variable names retain their original spelling. |
| [out] | result | Cleared before parsing. On success valid is true; on failure valid is false and postfix may contain a partial expression. |
| std::invalid_argument | A numeric token cannot be converted by stod. |
| std::out_of_range | A numeric token exceeds stod's representable range. |