KiCad PCB EDA Suite
Loading...
Searching...
No Matches
EXPRESSION_EVALUATOR Class Reference

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_EVALUATORoperator= (const EXPRESSION_EVALUATOR &aOther)
 
 EXPRESSION_EVALUATOR (EXPRESSION_EVALUATOR &&aOther) noexcept
 
EXPRESSION_EVALUATORoperator= (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::Valuem_variables
 
std::unique_ptr< calc_parser::ERROR_COLLECTORm_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.
 

Detailed Description

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:

  1. Static variable mode: Variables are stored internally and looked up from memory
  2. Callback mode: Variables are resolved dynamically using a user-provided function

Example usage:

// Static variable mode
evaluator.SetVariable("price", 99.99);
evaluator.SetVariable("product", "Widget");
evaluator.SetVariable("qty", 3);
wxString input = "Product: @{upper(${product})} - Total: @{currency(${price} * ${qty})}";
wxString result = evaluator.Evaluate(input);
// Result: "Product: WIDGET - Total: $299.97"
// Callback mode
auto callback = [](const std::string& varName) -> calc_parser::Result<calc_parser::Value> {
if (varName == "current_time") {
return calc_parser::MakeValue<calc_parser::Value>(getCurrentTimestamp());
}
return calc_parser::MakeError<calc_parser::Value>("Variable not found: " + varName);
};
EXPRESSION_EVALUATOR callbackEvaluator(callback);
wxString result2 = callbackEvaluator.Evaluate("Current time: @{${current_time}}");
wxString Evaluate(const wxString &aInput)
Main evaluation function - processes input string and evaluates all} expressions.
void SetVariable(const wxString &aName, double aValue)
Set a numeric variable for use in expressions.
EXPRESSION_EVALUATOR(bool aClearVariablesOnEvaluate=false)
Construct a new Expression Evaluator in static variable mode.
auto MakeValue(T aVal) -> Result< T >
auto MakeError(std::string aMsg) -> Result< T >
wxString result
Test unit parsing edge cases and error handling.

Definition at line 74 of file text_eval_wrapper.h.

Member Typedef Documentation

◆ VariableCallback

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.

Constructor & Destructor Documentation

◆ EXPRESSION_EVALUATOR() [1/6]

EXPRESSION_EVALUATOR::EXPRESSION_EVALUATOR ( bool aClearVariablesOnEvaluate = false)
explicit

Construct a new Expression Evaluator in static variable mode.

Parameters
aClearVariablesOnEvaluateIf 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().

◆ EXPRESSION_EVALUATOR() [2/6]

EXPRESSION_EVALUATOR::EXPRESSION_EVALUATOR ( EDA_UNITS aUnits,
bool aClearVariablesOnEvaluate = false )
explicit

Construct with default units support.

Parameters
aUnitsDefault units for parsing and evaluating expressions
aClearVariablesOnEvaluateIf 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.

◆ EXPRESSION_EVALUATOR() [3/6]

EXPRESSION_EVALUATOR::EXPRESSION_EVALUATOR ( VariableCallback aVariableCallback,
bool aClearVariablesOnEvaluate = false )
explicit

Construct with custom variable resolver callback.

Parameters
aVariableCallbackCustom function for variable resolution
aClearVariablesOnEvaluateIf 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.

◆ EXPRESSION_EVALUATOR() [4/6]

EXPRESSION_EVALUATOR::EXPRESSION_EVALUATOR ( EDA_UNITS aUnits,
VariableCallback aVariableCallback,
bool aClearVariablesOnEvaluate = false )
explicit

Construct with units and custom variable resolver callback.

Parameters
aUnitsDefault units for parsing and evaluating expressions
aVariableCallbackCustom function for variable resolution
aClearVariablesOnEvaluateIf 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.

◆ ~EXPRESSION_EVALUATOR()

◆ EXPRESSION_EVALUATOR() [5/6]

◆ EXPRESSION_EVALUATOR() [6/6]

EXPRESSION_EVALUATOR::EXPRESSION_EVALUATOR ( EXPRESSION_EVALUATOR && aOther)
noexcept

Member Function Documentation

◆ ClearErrors()

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().

◆ ClearVariableCallback()

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().

◆ ClearVariables()

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().

◆ CountExpressions()

size_t EXPRESSION_EVALUATOR::CountExpressions ( const wxString & aInput) const

Count the number of} expressions in input string.

Parameters
aInputInput string to analyze
Returns
Number of} expression blocks found

Definition at line 1345 of file text_eval_wrapper.cpp.

Referenced by ~EXPRESSION_EVALUATOR().

◆ createCombinedCallback()

EXPRESSION_EVALUATOR::VariableCallback EXPRESSION_EVALUATOR::createCombinedCallback ( const std::unordered_map< wxString, double > * aTempNumericVars = nullptr,
const std::unordered_map< wxString, wxString > * aTempStringVars = nullptr ) const
private

Create a callback function that combines all variable sources.

Parameters
aTempNumericVarsTemporary numeric variables (optional)
aTempStringVarsTemporary string variables (optional)
Returns
Combined callback for parser

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().

◆ Evaluate() [1/3]

◆ Evaluate() [2/3]

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.

Parameters
aInputInput string to evaluate
aTempNumericVarsTemporary numeric variables
aTempStringVarsTemporary string variables
Returns
Evaluated string

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().

◆ Evaluate() [3/3]

wxString EXPRESSION_EVALUATOR::Evaluate ( const wxString & aInput,
const std::unordered_map< wxString, double > & aTempVariables )

Evaluate with additional temporary variables (doesn't modify stored variables)

Parameters
aInputInput string to evaluate
aTempVariablesTemporary numeric variables for this evaluation only
Returns
Evaluated string

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().

◆ evaluateWithFullParser()

std::pair< std::string, bool > EXPRESSION_EVALUATOR::evaluateWithFullParser ( const std::string & aInput,
VariableCallback aVariableCallback )
private

Full parser evaluation (original behavior) - fails completely on any error.

Parameters
aInputInput string in std::string format
aVariableCallbackCallback function to use for variable resolution
Returns
Pair of (result_string, had_errors)

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().

◆ evaluateWithParser()

std::pair< std::string, bool > EXPRESSION_EVALUATOR::evaluateWithParser ( const std::string & aInput,
VariableCallback aVariableCallback )
private

Parse and evaluate the input string using the expression parser.

Parameters
aInputInput string in std::string format
aVariableCallbackCallback function to use for variable resolution
Returns
Pair of (result_string, had_errors)

Definition at line 1673 of file text_eval_wrapper.cpp.

References evaluateWithFullParser(), evaluateWithPartialErrorRecovery(), and m_lastErrors.

Referenced by Evaluate(), TestExpression(), and ~EXPRESSION_EVALUATOR().

◆ evaluateWithPartialErrorRecovery()

std::pair< std::string, bool > EXPRESSION_EVALUATOR::evaluateWithPartialErrorRecovery ( const std::string & aInput,
VariableCallback aVariableCallback )
private

Parse and evaluate with partial error recovery - malformed expressions left unchanged.

Parameters
aInputInput string in std::string format
aVariableCallbackCallback function to use for variable resolution
Returns
Pair of (result_string, had_errors)

Definition at line 1703 of file text_eval_wrapper.cpp.

References end, evaluateWithFullParser(), m_lastErrors, and result.

Referenced by evaluateWithParser(), and ~EXPRESSION_EVALUATOR().

◆ expandVariablesOutsideExpressions()

wxString EXPRESSION_EVALUATOR::expandVariablesOutsideExpressions ( const wxString & aInput,
const std::unordered_map< wxString, double > & aTempNumericVars,
const std::unordered_map< wxString, wxString > & aTempStringVars ) const
private

Expand ${variable} patterns that are outside} expressions.

Parameters
aInputInput string to process
aTempNumericVarsTemporary numeric variables
aTempStringVarsTemporary string variables
Returns
String with ${variable} patterns outside expressions expanded

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().

◆ ExtractExpressions()

std::vector< wxString > EXPRESSION_EVALUATOR::ExtractExpressions ( const wxString & aInput) const

Extract all} expressions from input without evaluating.

Parameters
aInputInput string to analyze
Returns
Vector of expression strings (content between} markers)

Definition at line 1359 of file text_eval_wrapper.cpp.

References end.

Referenced by ~EXPRESSION_EVALUATOR().

◆ GetClearVariablesOnEvaluate()

bool EXPRESSION_EVALUATOR::GetClearVariablesOnEvaluate ( ) const

Check if automatic variable clearing is enabled.

Returns
true if variables are cleared after each evaluation

Definition at line 1307 of file text_eval_wrapper.cpp.

References m_clearVariablesOnEvaluate.

Referenced by ~EXPRESSION_EVALUATOR().

◆ GetDefaultUnits()

EDA_UNITS EXPRESSION_EVALUATOR::GetDefaultUnits ( ) const

Get the current default units.

Returns
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().

◆ GetErrorCount()

size_t EXPRESSION_EVALUATOR::GetErrorCount ( ) const

Get count of errors from the last evaluation.

Returns
Number of errors that occurred

Definition at line 1272 of file text_eval_wrapper.cpp.

References m_lastErrors.

Referenced by ~EXPRESSION_EVALUATOR().

◆ GetErrors()

std::vector< wxString > EXPRESSION_EVALUATOR::GetErrors ( ) const

Get individual error messages from the last evaluation.

Returns
Vector of error messages

Definition at line 1280 of file text_eval_wrapper.cpp.

References m_lastErrors, result, and stdStringToWxString().

Referenced by ~EXPRESSION_EVALUATOR().

◆ GetErrorSummary()

wxString EXPRESSION_EVALUATOR::GetErrorSummary ( ) const

Get detailed error information from the last evaluation.

Returns
Error summary as wxString, empty if no errors

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().

◆ GetVariable()

wxString EXPRESSION_EVALUATOR::GetVariable ( const wxString & aName) const

Get the current value of a stored variable.

Parameters
aNameVariable name
Returns
Variable value as wxString, or empty string if not found

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().

◆ GetVariableNames()

std::vector< wxString > EXPRESSION_EVALUATOR::GetVariableNames ( ) const

Get all stored variable names currently defined.

Returns
Vector of variable names

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().

◆ HasErrors()

◆ HasVariable()

bool EXPRESSION_EVALUATOR::HasVariable ( const wxString & aName) const

Check if a variable exists in stored variables.

Parameters
aNameVariable name to check
Returns
true if variable exists in stored variables, false otherwise

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().

◆ HasVariableCallback()

bool EXPRESSION_EVALUATOR::HasVariableCallback ( ) const

Check if a custom variable callback is set.

Returns
true if custom callback is active

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().

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ RemoveVariable()

bool EXPRESSION_EVALUATOR::RemoveVariable ( const wxString & aName)

Remove a variable from the evaluator.

Parameters
aNameVariable name to remove
Returns
true if variable was found and removed, false otherwise

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().

◆ SetClearVariablesOnEvaluate()

void EXPRESSION_EVALUATOR::SetClearVariablesOnEvaluate ( bool aEnable)

Enable or disable automatic variable clearing after evaluation.

Parameters
aEnableIf 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().

◆ SetDefaultUnits()

void EXPRESSION_EVALUATOR::SetDefaultUnits ( EDA_UNITS aUnits)

Set the default units for expressions.

Parameters
aUnitsThe 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().

◆ SetVariable() [1/3]

void EXPRESSION_EVALUATOR::SetVariable ( const std::string & aName,
const std::string & aValue )

Set a variable using std::string (convenience overload)

Parameters
aNameVariable name
aValueString value

Definition at line 1142 of file text_eval_wrapper.cpp.

References m_variables.

◆ SetVariable() [2/3]

void EXPRESSION_EVALUATOR::SetVariable ( const wxString & aName,
const wxString & aValue )

Set a string variable for use in expressions.

Parameters
aNameVariable name (used as ${name} in expressions)
aValueString 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().

◆ SetVariable() [3/3]

void EXPRESSION_EVALUATOR::SetVariable ( const wxString & aName,
double aValue )

Set a numeric variable for use in expressions.

Parameters
aNameVariable name (used as ${name} in expressions)
aValueNumeric 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().

◆ SetVariableCallback()

void EXPRESSION_EVALUATOR::SetVariableCallback ( VariableCallback aCallback)

Set a custom variable resolver callback.

Parameters
aCallbackFunction 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().

◆ SetVariables() [1/2]

void EXPRESSION_EVALUATOR::SetVariables ( const std::unordered_map< wxString, double > & aVariables)

Set multiple variables at once from a map.

Parameters
aVariablesMap of variable names to numeric values

Definition at line 1198 of file text_eval_wrapper.cpp.

References name, and SetVariable().

Referenced by ~EXPRESSION_EVALUATOR().

◆ SetVariables() [2/2]

void EXPRESSION_EVALUATOR::SetVariables ( const std::unordered_map< wxString, wxString > & aVariables)

Set multiple string variables at once from a map.

Parameters
aVariablesMap of variable names to string values

Definition at line 1204 of file text_eval_wrapper.cpp.

References name, and SetVariable().

◆ stdStringToWxString()

wxString EXPRESSION_EVALUATOR::stdStringToWxString ( const std::string & aStdStr) const
private

Convert std::string to wxString using UTF-8 encoding.

Parameters
aStdStrstd::string to convert
Returns
Converted wxString

Definition at line 1388 of file text_eval_wrapper.cpp.

Referenced by createCombinedCallback(), Evaluate(), expandVariablesOutsideExpressions(), GetErrors(), GetErrorSummary(), GetVariable(), GetVariableNames(), and ~EXPRESSION_EVALUATOR().

◆ TestExpression()

bool EXPRESSION_EVALUATOR::TestExpression ( const wxString & aExpression)

Test if an expression can be parsed without evaluating it.

Parameters
aExpressionSingle expression to test (without} wrapper)
Returns
true if expression is syntactically valid

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().

◆ wxStringToStdString()

std::string EXPRESSION_EVALUATOR::wxStringToStdString ( const wxString & aWxStr) const
private

Convert wxString to std::string using UTF-8 encoding.

Parameters
aWxStrwxString to convert
Returns
Converted std::string

Definition at line 1383 of file text_eval_wrapper.cpp.

Referenced by createCombinedCallback(), Evaluate(), expandVariablesOutsideExpressions(), GetVariable(), HasVariable(), RemoveVariable(), SetVariable(), SetVariable(), TestExpression(), and ~EXPRESSION_EVALUATOR().

Member Data Documentation

◆ m_clearVariablesOnEvaluate

◆ m_customCallback

◆ m_defaultUnits

◆ m_lastErrors

◆ m_useCustomCallback

◆ m_variables


The documentation for this class was generated from the following files: