KiCad PCB EDA Suite
|
High-level wrapper for evaluating mathematical and string expressions in wxString format. More...
#include <text_eval_wrapper.h>
Public Types | |
using | VariableCallback = std::function<calc_parser::Result<calc_parser::Value>(const std::string& aVariableName)> |
Public Member Functions | |
EXPRESSION_EVALUATOR (bool aClearVariablesOnEvaluate=false) | |
Construct a new Expression Evaluator in static variable mode. | |
EXPRESSION_EVALUATOR (EDA_UNITS aUnits, bool aClearVariablesOnEvaluate=false) | |
Construct with default units support. | |
EXPRESSION_EVALUATOR (VariableCallback aVariableCallback, bool aClearVariablesOnEvaluate=false) | |
Construct with custom variable resolver callback. | |
EXPRESSION_EVALUATOR (EDA_UNITS aUnits, VariableCallback aVariableCallback, bool aClearVariablesOnEvaluate=false) | |
Construct with units and custom variable resolver callback. | |
~EXPRESSION_EVALUATOR () | |
Destructor. | |
EXPRESSION_EVALUATOR (const EXPRESSION_EVALUATOR &aOther) | |
EXPRESSION_EVALUATOR & | operator= (const EXPRESSION_EVALUATOR &aOther) |
EXPRESSION_EVALUATOR (EXPRESSION_EVALUATOR &&aOther) noexcept | |
EXPRESSION_EVALUATOR & | operator= (EXPRESSION_EVALUATOR &&aOther) noexcept |
void | SetVariableCallback (VariableCallback aCallback) |
Set a custom variable resolver callback. | |
void | ClearVariableCallback () |
Clear the custom variable resolver callback. | |
bool | HasVariableCallback () const |
Check if a custom variable callback is set. | |
void | SetDefaultUnits (EDA_UNITS aUnits) |
Set the default units for expressions. | |
EDA_UNITS | GetDefaultUnits () const |
Get the current default units. | |
void | SetVariable (const wxString &aName, double aValue) |
Set a numeric variable for use in expressions. | |
void | SetVariable (const wxString &aName, const wxString &aValue) |
Set a string variable for use in expressions. | |
void | SetVariable (const std::string &aName, const std::string &aValue) |
Set a variable using std::string (convenience overload) | |
bool | RemoveVariable (const wxString &aName) |
Remove a variable from the evaluator. | |
void | ClearVariables () |
Clear all stored variables. | |
bool | HasVariable (const wxString &aName) const |
Check if a variable exists in stored variables. | |
wxString | GetVariable (const wxString &aName) const |
Get the current value of a stored variable. | |
std::vector< wxString > | GetVariableNames () const |
Get all stored variable names currently defined. | |
void | SetVariables (const std::unordered_map< wxString, double > &aVariables) |
Set multiple variables at once from a map. | |
void | SetVariables (const std::unordered_map< wxString, wxString > &aVariables) |
Set multiple string variables at once from a map. | |
Private Attributes | |
std::unordered_map< std::string, calc_parser::Value > | m_variables |
std::unique_ptr< calc_parser::ERROR_COLLECTOR > | m_lastErrors |
bool | m_clearVariablesOnEvaluate |
VariableCallback | m_customCallback |
bool | m_useCustomCallback |
EDA_UNITS | m_defaultUnits |
wxString | Evaluate (const wxString &aInput) |
Main evaluation function - processes input string and evaluates all} expressions. | |
wxString | Evaluate (const wxString &aInput, const std::unordered_map< wxString, double > &aTempVariables) |
Evaluate with additional temporary variables (doesn't modify stored variables) | |
wxString | Evaluate (const wxString &aInput, const std::unordered_map< wxString, double > &aTempNumericVars, const std::unordered_map< wxString, wxString > &aTempStringVars) |
Evaluate with mixed temporary variables. | |
bool | HasErrors () const |
Check if the last evaluation had errors. | |
size_t | GetErrorCount () const |
Get count of errors from the last evaluation. | |
wxString | GetErrorSummary () const |
Get detailed error information from the last evaluation. | |
std::vector< wxString > | GetErrors () const |
Get individual error messages from the last evaluation. | |
void | ClearErrors () |
Clear any stored error information. | |
void | SetClearVariablesOnEvaluate (bool aEnable) |
Enable or disable automatic variable clearing after evaluation. | |
bool | GetClearVariablesOnEvaluate () const |
Check if automatic variable clearing is enabled. | |
bool | TestExpression (const wxString &aExpression) |
Test if an expression can be parsed without evaluating it. | |
size_t | CountExpressions (const wxString &aInput) const |
Count the number of} expressions in input string. | |
std::vector< wxString > | ExtractExpressions (const wxString &aInput) const |
Extract all} expressions from input without evaluating. | |
std::string | wxStringToStdString (const wxString &aWxStr) const |
Convert wxString to std::string using UTF-8 encoding. | |
wxString | stdStringToWxString (const std::string &aStdStr) const |
Convert std::string to wxString using UTF-8 encoding. | |
VariableCallback | createCombinedCallback (const std::unordered_map< wxString, double > *aTempNumericVars=nullptr, const std::unordered_map< wxString, wxString > *aTempStringVars=nullptr) const |
Create a callback function that combines all variable sources. | |
std::pair< std::string, bool > | evaluateWithParser (const std::string &aInput, VariableCallback aVariableCallback) |
Parse and evaluate the input string using the expression parser. | |
std::pair< std::string, bool > | evaluateWithPartialErrorRecovery (const std::string &aInput, VariableCallback aVariableCallback) |
Parse and evaluate with partial error recovery - malformed expressions left unchanged. | |
std::pair< std::string, bool > | evaluateWithFullParser (const std::string &aInput, VariableCallback aVariableCallback) |
Full parser evaluation (original behavior) - fails completely on any error. | |
wxString | expandVariablesOutsideExpressions (const wxString &aInput, const std::unordered_map< wxString, double > &aTempNumericVars, const std::unordered_map< wxString, wxString > &aTempStringVars) const |
Expand ${variable} patterns that are outside} expressions. | |
High-level wrapper for evaluating mathematical and string expressions in wxString format.
This class provides a simple interface for evaluating expressions containing} syntax within wxString objects. It supports both map-based variable lookup and flexible callback-based variable resolution for dynamic data access.
The evaluator can work in two modes:
Example usage:
Definition at line 74 of file text_eval_wrapper.h.
using EXPRESSION_EVALUATOR::VariableCallback = std::function<calc_parser::Result<calc_parser::Value>(const std::string& aVariableName)> |
Definition at line 78 of file text_eval_wrapper.h.
|
explicit |
Construct a new Expression Evaluator in static variable mode.
aClearVariablesOnEvaluate | If true, variables are cleared after each evaluation |
Definition at line 1004 of file text_eval_wrapper.cpp.
References m_clearVariablesOnEvaluate, m_defaultUnits, m_lastErrors, m_useCustomCallback, and MM.
Referenced by EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), operator=(), operator=(), and ~EXPRESSION_EVALUATOR().
|
explicit |
Construct with default units support.
aUnits | Default units for parsing and evaluating expressions |
aClearVariablesOnEvaluate | If true, variables are cleared after each evaluation |
Definition at line 1022 of file text_eval_wrapper.cpp.
References m_clearVariablesOnEvaluate, m_defaultUnits, m_lastErrors, and m_useCustomCallback.
|
explicit |
Construct with custom variable resolver callback.
aVariableCallback | Custom function for variable resolution |
aClearVariablesOnEvaluate | If true, local variables are cleared after evaluation |
Definition at line 1012 of file text_eval_wrapper.cpp.
References m_clearVariablesOnEvaluate, m_customCallback, m_defaultUnits, m_lastErrors, m_useCustomCallback, MM, and move.
|
explicit |
Construct with units and custom variable resolver callback.
aUnits | Default units for parsing and evaluating expressions |
aVariableCallback | Custom function for variable resolution |
aClearVariablesOnEvaluate | If true, local variables are cleared after evaluation |
Definition at line 1030 of file text_eval_wrapper.cpp.
References m_clearVariablesOnEvaluate, m_customCallback, m_defaultUnits, m_lastErrors, m_useCustomCallback, and move.
|
default |
Destructor.
References ClearErrors(), ClearVariableCallback(), ClearVariables(), CountExpressions(), createCombinedCallback(), evaluateWithFullParser(), evaluateWithParser(), evaluateWithPartialErrorRecovery(), expandVariablesOutsideExpressions(), EXPRESSION_EVALUATOR(), ExtractExpressions(), GetClearVariablesOnEvaluate(), GetDefaultUnits(), GetErrorCount(), GetErrors(), GetErrorSummary(), GetVariable(), GetVariableNames(), HasErrors(), HasVariable(), HasVariableCallback(), operator=(), RemoveVariable(), SetClearVariablesOnEvaluate(), SetDefaultUnits(), SetVariable(), SetVariableCallback(), SetVariables(), stdStringToWxString(), TestExpression(), and wxStringToStdString().
EXPRESSION_EVALUATOR::EXPRESSION_EVALUATOR | ( | const EXPRESSION_EVALUATOR & | aOther | ) |
Definition at line 1042 of file text_eval_wrapper.cpp.
References EXPRESSION_EVALUATOR(), calc_parser::ERROR_COLLECTOR::GetErrors(), m_clearVariablesOnEvaluate, m_customCallback, m_defaultUnits, m_lastErrors, m_useCustomCallback, and m_variables.
|
noexcept |
Definition at line 1078 of file text_eval_wrapper.cpp.
References EXPRESSION_EVALUATOR(), m_clearVariablesOnEvaluate, m_customCallback, m_defaultUnits, m_lastErrors, m_useCustomCallback, and m_variables.
void EXPRESSION_EVALUATOR::ClearErrors | ( | ) |
Clear any stored error information.
Definition at line 1296 of file text_eval_wrapper.cpp.
References m_lastErrors.
Referenced by Evaluate(), and ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::ClearVariableCallback | ( | ) |
Clear the custom variable resolver callback.
After calling this, the evaluator will use stored variables only.
Definition at line 1108 of file text_eval_wrapper.cpp.
References m_customCallback, and m_useCustomCallback.
Referenced by ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::ClearVariables | ( | ) |
Clear all stored variables.
This does not affect callback-based variable resolution.
Definition at line 1153 of file text_eval_wrapper.cpp.
References m_variables.
Referenced by BOOST_AUTO_TEST_CASE(), Evaluate(), and ~EXPRESSION_EVALUATOR().
size_t EXPRESSION_EVALUATOR::CountExpressions | ( | const wxString & | aInput | ) | const |
Count the number of} expressions in input string.
aInput | Input string to analyze |
Definition at line 1345 of file text_eval_wrapper.cpp.
Referenced by ~EXPRESSION_EVALUATOR().
|
private |
Create a callback function that combines all variable sources.
aTempNumericVars | Temporary numeric variables (optional) |
aTempStringVars | Temporary string variables (optional) |
Definition at line 1554 of file text_eval_wrapper.cpp.
References ExpandTextVars(), m_customCallback, m_useCustomCallback, m_variables, calc_parser::MakeError(), calc_parser::MakeValue(), resolver, result, stdStringToWxString(), and wxStringToStdString().
Referenced by Evaluate(), and ~EXPRESSION_EVALUATOR().
wxString EXPRESSION_EVALUATOR::Evaluate | ( | const wxString & | aInput | ) |
Main evaluation function - processes input string and evaluates all} expressions.
aInput | Input string potentially containing} expressions |
Variables are resolved using the callback (if set) or stored variables.
Definition at line 1210 of file text_eval_wrapper.cpp.
References Evaluate().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), Evaluate(), Evaluate(), EDA_TEXT::EvaluateText(), GRPrintText(), GRTextWidth(), PLOTTER::PlotText(), PDF_PLOTTER::Text(), and PLOTTER::Text().
wxString EXPRESSION_EVALUATOR::Evaluate | ( | const wxString & | aInput, |
const std::unordered_map< wxString, double > & | aTempNumericVars, | ||
const std::unordered_map< wxString, wxString > & | aTempStringVars ) |
Evaluate with mixed temporary variables.
aInput | Input string to evaluate |
aTempNumericVars | Temporary numeric variables |
aTempStringVars | Temporary string variables |
Priority order: callback > temp string vars > temp numeric vars > stored variables
Definition at line 1224 of file text_eval_wrapper.cpp.
References ClearErrors(), ClearVariables(), createCombinedCallback(), evaluateWithParser(), expandVariablesOutsideExpressions(), m_clearVariablesOnEvaluate, m_lastErrors, result, stdStringToWxString(), and wxStringToStdString().
wxString EXPRESSION_EVALUATOR::Evaluate | ( | const wxString & | aInput, |
const std::unordered_map< wxString, double > & | aTempVariables ) |
Evaluate with additional temporary variables (doesn't modify stored variables)
aInput | Input string to evaluate |
aTempVariables | Temporary numeric variables for this evaluation only |
Temporary variables have lower priority than callback resolution but higher priority than stored variables.
Definition at line 1217 of file text_eval_wrapper.cpp.
References Evaluate().
|
private |
Full parser evaluation (original behavior) - fails completely on any error.
aInput | Input string in std::string format |
aVariableCallback | Callback function to use for variable resolution |
Definition at line 1803 of file text_eval_wrapper.cpp.
References ENDS, calc_parser::g_errorCollector, m_defaultUnits, m_lastErrors, calc_parser::DOC_PROCESSOR::Process(), and result.
Referenced by evaluateWithParser(), evaluateWithPartialErrorRecovery(), and ~EXPRESSION_EVALUATOR().
|
private |
Parse and evaluate the input string using the expression parser.
aInput | Input string in std::string format |
aVariableCallback | Callback function to use for variable resolution |
Definition at line 1673 of file text_eval_wrapper.cpp.
References evaluateWithFullParser(), evaluateWithPartialErrorRecovery(), and m_lastErrors.
Referenced by Evaluate(), TestExpression(), and ~EXPRESSION_EVALUATOR().
|
private |
Parse and evaluate with partial error recovery - malformed expressions left unchanged.
aInput | Input string in std::string format |
aVariableCallback | Callback function to use for variable resolution |
Definition at line 1703 of file text_eval_wrapper.cpp.
References end, evaluateWithFullParser(), m_lastErrors, and result.
Referenced by evaluateWithParser(), and ~EXPRESSION_EVALUATOR().
|
private |
Expand ${variable} patterns that are outside} expressions.
aInput | Input string to process |
aTempNumericVars | Temporary numeric variables |
aTempStringVars | Temporary string variables |
Definition at line 1393 of file text_eval_wrapper.cpp.
References text_eval_units::UnitRegistry::getAllUnitStrings(), m_lastErrors, m_variables, result, stdStringToWxString(), and wxStringToStdString().
Referenced by Evaluate(), and ~EXPRESSION_EVALUATOR().
std::vector< wxString > EXPRESSION_EVALUATOR::ExtractExpressions | ( | const wxString & | aInput | ) | const |
Extract all} expressions from input without evaluating.
aInput | Input string to analyze |
Definition at line 1359 of file text_eval_wrapper.cpp.
References end.
Referenced by ~EXPRESSION_EVALUATOR().
bool EXPRESSION_EVALUATOR::GetClearVariablesOnEvaluate | ( | ) | const |
Check if automatic variable clearing is enabled.
Definition at line 1307 of file text_eval_wrapper.cpp.
References m_clearVariablesOnEvaluate.
Referenced by ~EXPRESSION_EVALUATOR().
EDA_UNITS EXPRESSION_EVALUATOR::GetDefaultUnits | ( | ) | const |
Get the current default units.
Definition at line 1124 of file text_eval_wrapper.cpp.
References m_defaultUnits.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
size_t EXPRESSION_EVALUATOR::GetErrorCount | ( | ) | const |
Get count of errors from the last evaluation.
Definition at line 1272 of file text_eval_wrapper.cpp.
References m_lastErrors.
Referenced by ~EXPRESSION_EVALUATOR().
std::vector< wxString > EXPRESSION_EVALUATOR::GetErrors | ( | ) | const |
Get individual error messages from the last evaluation.
Definition at line 1280 of file text_eval_wrapper.cpp.
References m_lastErrors, result, and stdStringToWxString().
Referenced by ~EXPRESSION_EVALUATOR().
wxString EXPRESSION_EVALUATOR::GetErrorSummary | ( | ) | const |
Get detailed error information from the last evaluation.
Definition at line 1264 of file text_eval_wrapper.cpp.
References m_lastErrors, and stdStringToWxString().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
wxString EXPRESSION_EVALUATOR::GetVariable | ( | const wxString & | aName | ) | const |
Get the current value of a stored variable.
aName | Variable name |
Note: This only returns stored variables, not callback-resolved variables.
Definition at line 1164 of file text_eval_wrapper.cpp.
References std::abs(), m_variables, name, stdStringToWxString(), and wxStringToStdString().
Referenced by ~EXPRESSION_EVALUATOR().
std::vector< wxString > EXPRESSION_EVALUATOR::GetVariableNames | ( | ) | const |
Get all stored variable names currently defined.
Note: This only returns stored variables, not callback-available variables.
Definition at line 1187 of file text_eval_wrapper.cpp.
References m_variables, name, and stdStringToWxString().
Referenced by ~EXPRESSION_EVALUATOR().
bool EXPRESSION_EVALUATOR::HasErrors | ( | ) | const |
Check if the last evaluation had errors.
Definition at line 1259 of file text_eval_wrapper.cpp.
References m_lastErrors.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
bool EXPRESSION_EVALUATOR::HasVariable | ( | const wxString & | aName | ) | const |
Check if a variable exists in stored variables.
aName | Variable name to check |
Note: This only checks stored variables, not callback-resolved variables.
Definition at line 1158 of file text_eval_wrapper.cpp.
References m_variables, name, and wxStringToStdString().
Referenced by BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
bool EXPRESSION_EVALUATOR::HasVariableCallback | ( | ) | const |
Check if a custom variable callback is set.
Definition at line 1114 of file text_eval_wrapper.cpp.
References m_customCallback, and m_useCustomCallback.
Referenced by BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
EXPRESSION_EVALUATOR & EXPRESSION_EVALUATOR::operator= | ( | const EXPRESSION_EVALUATOR & | aOther | ) |
Definition at line 1058 of file text_eval_wrapper.cpp.
References EXPRESSION_EVALUATOR(), calc_parser::ERROR_COLLECTOR::GetErrors(), m_clearVariablesOnEvaluate, m_customCallback, m_defaultUnits, m_lastErrors, m_useCustomCallback, and m_variables.
Referenced by ~EXPRESSION_EVALUATOR().
|
noexcept |
Definition at line 1088 of file text_eval_wrapper.cpp.
References EXPRESSION_EVALUATOR(), m_clearVariablesOnEvaluate, m_customCallback, m_defaultUnits, m_lastErrors, m_useCustomCallback, and m_variables.
bool EXPRESSION_EVALUATOR::RemoveVariable | ( | const wxString & | aName | ) |
Remove a variable from the evaluator.
aName | Variable name to remove |
Definition at line 1147 of file text_eval_wrapper.cpp.
References m_variables, name, and wxStringToStdString().
Referenced by BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::SetClearVariablesOnEvaluate | ( | bool | aEnable | ) |
Enable or disable automatic variable clearing after evaluation.
aEnable | If true, stored variables are cleared after each Evaluate() call |
Note: This only affects stored variables, not callback behavior.
Definition at line 1302 of file text_eval_wrapper.cpp.
References m_clearVariablesOnEvaluate.
Referenced by ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::SetDefaultUnits | ( | EDA_UNITS | aUnits | ) |
Set the default units for expressions.
aUnits | The units to use as default (mm, mil, inch, etc.) |
When expressions contain numeric values with unit suffixes (e.g., "1mm", "25mil"), they will be converted to the default units for calculation.
Definition at line 1119 of file text_eval_wrapper.cpp.
References m_defaultUnits.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::SetVariable | ( | const std::string & | aName, |
const std::string & | aValue ) |
Set a variable using std::string (convenience overload)
aName | Variable name |
aValue | String value |
Definition at line 1142 of file text_eval_wrapper.cpp.
References m_variables.
void EXPRESSION_EVALUATOR::SetVariable | ( | const wxString & | aName, |
const wxString & | aValue ) |
Set a string variable for use in expressions.
aName | Variable name (used as ${name} in expressions) |
aValue | String value |
This has no effect when using callback mode, unless the callback chooses to fall back to stored variables.
Definition at line 1135 of file text_eval_wrapper.cpp.
References m_variables, name, and wxStringToStdString().
void EXPRESSION_EVALUATOR::SetVariable | ( | const wxString & | aName, |
double | aValue ) |
Set a numeric variable for use in expressions.
aName | Variable name (used as ${name} in expressions) |
aValue | Numeric value |
This has no effect when using callback mode, unless the callback chooses to fall back to stored variables.
Definition at line 1129 of file text_eval_wrapper.cpp.
References m_variables, name, and wxStringToStdString().
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), SetVariables(), SetVariables(), and ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::SetVariableCallback | ( | VariableCallback | aCallback | ) |
Set a custom variable resolver callback.
aCallback | Function to call for variable resolution |
When set, this callback takes precedence over stored variables. The callback receives variable names and should return Result<Value>. Set to nullptr or call ClearVariableCallback() to disable callback mode.
Definition at line 1102 of file text_eval_wrapper.cpp.
References m_customCallback, and m_useCustomCallback.
Referenced by ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::SetVariables | ( | const std::unordered_map< wxString, double > & | aVariables | ) |
Set multiple variables at once from a map.
aVariables | Map of variable names to numeric values |
Definition at line 1198 of file text_eval_wrapper.cpp.
References name, and SetVariable().
Referenced by ~EXPRESSION_EVALUATOR().
void EXPRESSION_EVALUATOR::SetVariables | ( | const std::unordered_map< wxString, wxString > & | aVariables | ) |
Set multiple string variables at once from a map.
aVariables | Map of variable names to string values |
Definition at line 1204 of file text_eval_wrapper.cpp.
References name, and SetVariable().
|
private |
Convert std::string to wxString using UTF-8 encoding.
aStdStr | std::string to convert |
Definition at line 1388 of file text_eval_wrapper.cpp.
Referenced by createCombinedCallback(), Evaluate(), expandVariablesOutsideExpressions(), GetErrors(), GetErrorSummary(), GetVariable(), GetVariableNames(), and ~EXPRESSION_EVALUATOR().
bool EXPRESSION_EVALUATOR::TestExpression | ( | const wxString & | aExpression | ) |
Test if an expression can be parsed without evaluating it.
aExpression | Single expression to test (without} wrapper) |
This creates a temporary evaluator to test syntax only.
Definition at line 1312 of file text_eval_wrapper.cpp.
References evaluateWithParser(), m_lastErrors, calc_parser::MakeError(), result, and wxStringToStdString().
Referenced by ~EXPRESSION_EVALUATOR().
|
private |
Convert wxString to std::string using UTF-8 encoding.
aWxStr | wxString to convert |
Definition at line 1383 of file text_eval_wrapper.cpp.
Referenced by createCombinedCallback(), Evaluate(), expandVariablesOutsideExpressions(), GetVariable(), HasVariable(), RemoveVariable(), SetVariable(), SetVariable(), TestExpression(), and ~EXPRESSION_EVALUATOR().
|
private |
Definition at line 83 of file text_eval_wrapper.h.
Referenced by Evaluate(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), GetClearVariablesOnEvaluate(), operator=(), operator=(), and SetClearVariablesOnEvaluate().
|
private |
Definition at line 84 of file text_eval_wrapper.h.
Referenced by ClearVariableCallback(), createCombinedCallback(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), HasVariableCallback(), operator=(), operator=(), and SetVariableCallback().
|
private |
Definition at line 86 of file text_eval_wrapper.h.
Referenced by evaluateWithFullParser(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), GetDefaultUnits(), operator=(), operator=(), and SetDefaultUnits().
|
mutableprivate |
Definition at line 82 of file text_eval_wrapper.h.
Referenced by ClearErrors(), Evaluate(), evaluateWithFullParser(), evaluateWithParser(), evaluateWithPartialErrorRecovery(), expandVariablesOutsideExpressions(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), GetErrorCount(), GetErrors(), GetErrorSummary(), HasErrors(), operator=(), operator=(), and TestExpression().
|
private |
Definition at line 85 of file text_eval_wrapper.h.
Referenced by ClearVariableCallback(), createCombinedCallback(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), HasVariableCallback(), operator=(), operator=(), and SetVariableCallback().
|
private |
Definition at line 81 of file text_eval_wrapper.h.
Referenced by ClearVariables(), createCombinedCallback(), expandVariablesOutsideExpressions(), EXPRESSION_EVALUATOR(), EXPRESSION_EVALUATOR(), GetVariable(), GetVariableNames(), HasVariable(), operator=(), operator=(), RemoveVariable(), SetVariable(), SetVariable(), and SetVariable().