24#include <unordered_map> 
   78    using VariableCallback = std::function<calc_parser::Result<calc_parser::Value>(
const std::string& aVariableName)>;
 
   81    std::unordered_map<std::string, calc_parser::Value> 
m_variables;
 
   82    mutable std::unique_ptr<calc_parser::ERROR_COLLECTOR> 
m_lastErrors;
 
  108                                 bool aClearVariablesOnEvaluate = 
false );
 
  117                                 bool aClearVariablesOnEvaluate = 
false );
 
  176    void SetVariable( 
const wxString& aName, 
double aValue );
 
  186    void SetVariable( 
const wxString& aName, 
const wxString& aValue );
 
  193    void SetVariable( 
const std::string& aName, 
const std::string& aValue );
 
  225    wxString 
GetVariable( 
const wxString& aName ) 
const;
 
  239    void SetVariables( 
const std::unordered_map<wxString, double>& aVariables );
 
  245    void SetVariables( 
const std::unordered_map<wxString, wxString>& aVariables );
 
  254    wxString 
Evaluate( 
const wxString& aInput );
 
  265    wxString 
Evaluate( 
const wxString& aInput,
 
  266                      const std::unordered_map<wxString, double>& aTempVariables );
 
  277    wxString 
Evaluate( 
const wxString& aInput,
 
  278                      const std::unordered_map<wxString, double>& aTempNumericVars,
 
  279                      const std::unordered_map<wxString, wxString>& aTempStringVars );
 
  369        const std::unordered_map<wxString, double>* aTempNumericVars = 
nullptr,
 
  370        const std::unordered_map<wxString, wxString>* aTempStringVars = 
nullptr ) 
const;
 
  379        const std::string& aInput,
 
  389        const std::string& aInput,
 
  399        const std::string& aInput,
 
  410        const wxString& aInput,
 
  411        const std::unordered_map<wxString, double>& aTempNumericVars,
 
  412        const std::unordered_map<wxString, wxString>& aTempStringVars ) 
const;
 
 
  497    bool Process( 
const wxString& aString );
 
  510    void SetVar( 
const wxString& aString, 
double aValue );
 
  517    double GetVar( 
const wxString& aString );
 
  523    void RemoveVar( 
const wxString& aString );
 
 
double Evaluate(AM_PARAM_EVAL_STACK &aExp)
Evaluate an basic arithmetic expression (infix notation) with precedence The expression is a sequence...
 
High-level wrapper for evaluating mathematical and string expressions in wxString format.
 
EDA_UNITS GetDefaultUnits() const
Get the current default units.
 
bool HasVariableCallback() const
Check if a custom variable callback is set.
 
bool TestExpression(const wxString &aExpression)
Test if an expression can be parsed without evaluating it.
 
bool RemoveVariable(const wxString &aName)
Remove a variable from the evaluator.
 
bool HasErrors() const
Check if the last evaluation had errors.
 
std::pair< std::string, bool > evaluateWithFullParser(const std::string &aInput, VariableCallback aVariableCallback)
Full parser evaluation (original behavior) - fails completely on any error.
 
wxString GetErrorSummary() const
Get detailed error information from the last evaluation.
 
void SetDefaultUnits(EDA_UNITS aUnits)
Set the default units for expressions.
 
bool GetClearVariablesOnEvaluate() const
Check if automatic variable clearing is enabled.
 
std::unordered_map< std::string, calc_parser::Value > m_variables
 
void SetVariables(const std::unordered_map< wxString, double > &aVariables)
Set multiple variables at once from a map.
 
std::pair< std::string, bool > evaluateWithPartialErrorRecovery(const std::string &aInput, VariableCallback aVariableCallback)
Parse and evaluate with partial error recovery - malformed expressions left unchanged.
 
std::string wxStringToStdString(const wxString &aWxStr) const
Convert wxString to std::string using UTF-8 encoding.
 
size_t GetErrorCount() const
Get count of errors from the last evaluation.
 
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::vector< wxString > ExtractExpressions(const wxString &aInput) const
Extract all} expressions from input without evaluating.
 
void ClearErrors()
Clear any stored error information.
 
std::unique_ptr< calc_parser::ERROR_COLLECTOR > m_lastErrors
 
wxString stdStringToWxString(const std::string &aStdStr) const
Convert std::string to wxString using UTF-8 encoding.
 
std::vector< wxString > GetErrors() const
Get individual error messages from the last evaluation.
 
void ClearVariableCallback()
Clear the custom variable resolver callback.
 
void ClearVariables()
Clear all stored variables.
 
bool HasVariable(const wxString &aName) const
Check if a variable exists in stored variables.
 
std::vector< wxString > GetVariableNames() const
Get all stored variable names currently defined.
 
~EXPRESSION_EVALUATOR()
Destructor.
 
EXPRESSION_EVALUATOR & operator=(const EXPRESSION_EVALUATOR &aOther)
 
std::function< calc_parser::Result< calc_parser::Value >(const std::string &aVariableName)> VariableCallback
 
std::pair< std::string, bool > evaluateWithParser(const std::string &aInput, VariableCallback aVariableCallback)
Parse and evaluate the input string using the expression parser.
 
void SetVariable(const wxString &aName, double aValue)
Set a numeric variable for use in expressions.
 
void SetClearVariablesOnEvaluate(bool aEnable)
Enable or disable automatic variable clearing after evaluation.
 
void SetVariableCallback(VariableCallback aCallback)
Set a custom variable resolver callback.
 
wxString GetVariable(const wxString &aName) const
Get the current value of a stored variable.
 
size_t CountExpressions(const wxString &aInput) const
Count the number of} expressions in input string.
 
VariableCallback m_customCallback
 
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.
 
bool m_clearVariablesOnEvaluate
 
EXPRESSION_EVALUATOR(bool aClearVariablesOnEvaluate=false)
Construct a new Expression Evaluator in static variable mode.
 
NUMERIC_EVALUATOR compatible wrapper around EXPRESSION_EVALUATOR.
 
void LocaleChanged()
Handle locale changes (for decimal separator)
 
~NUMERIC_EVALUATOR_COMPAT()
Destructor.
 
void SetDefaultUnits(EDA_UNITS aUnits)
Set default units for evaluation.
 
bool Process(const wxString &aString)
Process and evaluate an expression.
 
wxString Result() const
Get the result of the last evaluation.
 
void RemoveVar(const wxString &aString)
Remove a single variable.
 
void SetVar(const wxString &aString, double aValue)
Set a variable value.
 
void ClearVar()
Remove all variables.
 
EXPRESSION_EVALUATOR m_evaluator
 
double GetVar(const wxString &aString)
Get a variable value.
 
void Clear()
Clear parser state but retain variables.
 
NUMERIC_EVALUATOR_COMPAT(EDA_UNITS aUnits)
Constructor with default units.
 
bool IsValid() const
Check if the last evaluation was successful.
 
wxString OriginalText() const
Get the original input text.