9#include <unordered_map>
27 int sequenceNumber = 0;
36 std::string expressionString;
38 te_expr * expression =
nullptr;
56 const size_t kMaxVariables = 1024;
66 float eval(std::string_view expression,
float defaultValue);
67 double eval(std::string_view expression,
double defaultValue);
68 int eval(std::string_view expression,
int defaultValue);
70 Expression * compile(std::string_view expression, std::string_view variable);
73 double update(
const Expression * expression,
double defaultValue);
74 float update(
const Expression * expression,
float defaultValue);
75 int update(
const Expression * expression,
int defaultValue);
76 size_t update(
const Expression * expression,
size_t defaultValue);
78 std::span<const ExpressionVariable> getValues()
const;
79 std::span<ExpressionVariable> getValues();
83 void link(
ExpressionContext * source, std::string_view sourceName, std::string_view destName);
92 std::unordered_map<size_t, Expression> expressions;
93 std::vector<ExpressionVariable> values;
96 std::vector<te_variable> variables;
103 expressionContext(expressionContext),
105 expression(expression)
109 const std::string_view name;
110 const std::string_view expression;
119 expressionContext(expressionContext),
122 this->expression = expressionContext->compile(expression, name);
127 if (expression && expressionContext) {
128 expressionContext->free(expression);
134 this->expressionContext = expressionValue.expressionContext;
135 this->expression = expressionContext->compile(expressionValue.expression, expressionValue.name);
137 hasValue = expression ==
nullptr;
142 operator T()
const {
return getValue(); }
147 value = expression ? get(T()) : T();
153 T get(T defaultValue)
const
155 return expressionContext->update(expression, defaultValue);
161 bool hasValue =
false;
Contains all Cogs related functionality.
Provides a context for evaluation of expressions.
Defines a single named expression variable.
Defines a string expression, to be parsed and evaluated by an expression context.
Stores the parsed output of a key/value pair.