|
Cogs.Core
|
Provides a context for evaluation of expressions. More...
#include <Expressions.h>
Public Member Functions | |
| ExpressionContext (const ExpressionContext &other)=delete | |
| ExpressionContext & | operator= (const ExpressionContext &other)=delete |
| void | inherit (ExpressionContext *other) |
| ExpressionVariable & | add (std::string_view name, double value) |
| double | eval (std::string_view expression, double defaultValue) |
| Expression * | compile (std::string_view expression, std::string_view variable) |
| void | free (Expression *expression) |
| double | update (const Expression *expression, double defaultValue) |
| float | update (const Expression *expression, float defaultValue) |
| int | update (const Expression *expression, int defaultValue) |
| size_t | update (const Expression *expression, size_t defaultValue) |
| std::span< const ExpressionVariable > | getValues () const |
| std::span< ExpressionVariable > | getValues () |
| ExpressionContext * | getParent () |
| void | link (ExpressionContext *source, std::string_view sourceName, std::string_view destName) |
| void | clear () |
Public Attributes | |
| const size_t | kMaxVariables = 1024 |
| Simple bound on variables to avoid resizing storage and invalidating pointers. | |
Private Member Functions | |
| void | reserve () |
Private Attributes | |
| ExpressionContext * | parent |
| std::unordered_map< size_t, Expression > | expressions |
| std::vector< ExpressionVariable > | values |
| te_scope | scope |
| std::vector< te_variable > | variables |
Provides a context for evaluation of expressions.
Named variables can be added to the expression context to be available for expressions to use.
The context only evaluates a single variable or expression at a time, there is no automatic updates of dependent values.
Expression contexts may inherit variable state from other contexts, making all named variables of the parent context available during evaluation.
Definition at line 53 of file Expressions.h.
| Cogs::Core::ExpressionContext::ExpressionContext | ( | ) |
Definition at line 17 of file Expressions.cpp.
| Cogs::Core::ExpressionVariable & Cogs::Core::ExpressionContext::add | ( | std::string_view | name, |
| double | value | ||
| ) |
Definition at line 94 of file Expressions.cpp.
| void Cogs::Core::ExpressionContext::clear | ( | ) |
Definition at line 194 of file Expressions.cpp.
| Cogs::Core::Expression * Cogs::Core::ExpressionContext::compile | ( | std::string_view | expression, |
| std::string_view | variable | ||
| ) |
Definition at line 56 of file Expressions.cpp.
| double Cogs::Core::ExpressionContext::eval | ( | std::string_view | expression, |
| double | defaultValue | ||
| ) |
Definition at line 41 of file Expressions.cpp.
| void Cogs::Core::ExpressionContext::free | ( | Expression * | expression | ) |
Definition at line 89 of file Expressions.cpp.
|
inline |
Definition at line 79 of file Expressions.h.
| std::span< Cogs::Core::ExpressionVariable > Cogs::Core::ExpressionContext::getValues | ( | ) |
Definition at line 212 of file Expressions.cpp.
| std::span< const Cogs::Core::ExpressionVariable > Cogs::Core::ExpressionContext::getValues | ( | ) | const |
Definition at line 207 of file Expressions.cpp.
| void Cogs::Core::ExpressionContext::inherit | ( | ExpressionContext * | other | ) |
Definition at line 29 of file Expressions.cpp.
| void Cogs::Core::ExpressionContext::link | ( | ExpressionContext * | source, |
| std::string_view | sourceName, | ||
| std::string_view | destName | ||
| ) |
Definition at line 157 of file Expressions.cpp.
|
private |
Definition at line 23 of file Expressions.cpp.
| double Cogs::Core::ExpressionContext::update | ( | const Expression * | expression, |
| double | defaultValue | ||
| ) |
Definition at line 123 of file Expressions.cpp.
| float Cogs::Core::ExpressionContext::update | ( | const Expression * | expression, |
| float | defaultValue | ||
| ) |
Definition at line 136 of file Expressions.cpp.
| int Cogs::Core::ExpressionContext::update | ( | const Expression * | expression, |
| int | defaultValue | ||
| ) |
Definition at line 141 of file Expressions.cpp.
| size_t Cogs::Core::ExpressionContext::update | ( | const Expression * | expression, |
| size_t | defaultValue | ||
| ) |
Definition at line 146 of file Expressions.cpp.
|
private |
Definition at line 90 of file Expressions.h.
| const size_t Cogs::Core::ExpressionContext::kMaxVariables = 1024 |
Simple bound on variables to avoid resizing storage and invalidating pointers.
Definition at line 56 of file Expressions.h.
|
private |
Definition at line 88 of file Expressions.h.
|
private |
Definition at line 93 of file Expressions.h.
|
private |
Definition at line 91 of file Expressions.h.
|
private |
Definition at line 94 of file Expressions.h.