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

NUMERIC_EVALUATOR compatible wrapper around EXPRESSION_EVALUATOR. More...

#include <text_eval_wrapper.h>

Public Member Functions

 NUMERIC_EVALUATOR_COMPAT (EDA_UNITS aUnits)
 Constructor with default units.
 
 ~NUMERIC_EVALUATOR_COMPAT ()
 Destructor.
 
void Clear ()
 Clear parser state but retain variables.
 
void SetDefaultUnits (EDA_UNITS aUnits)
 Set default units for evaluation.
 
void LocaleChanged ()
 Handle locale changes (for decimal separator)
 
bool IsValid () const
 Check if the last evaluation was successful.
 
wxString Result () const
 Get the result of the last evaluation.
 
bool Process (const wxString &aString)
 Process and evaluate an expression.
 
wxString OriginalText () const
 Get the original input text.
 
void SetVar (const wxString &aString, double aValue)
 Set a variable value.
 
double GetVar (const wxString &aString)
 Get a variable value.
 
void RemoveVar (const wxString &aString)
 Remove a single variable.
 
void ClearVar ()
 Remove all variables.
 

Private Attributes

EXPRESSION_EVALUATOR m_evaluator
 
wxString m_lastInput
 
wxString m_lastResult
 
bool m_lastValid
 

Detailed Description

NUMERIC_EVALUATOR compatible wrapper around EXPRESSION_EVALUATOR.

This class provides a drop-in replacement for NUMERIC_EVALUATOR that uses the new EXPRESSION_EVALUATOR backend. It maintains the same API to allow seamless migration of existing code.

The key difference is that expressions are automatically wrapped in...} syntax before evaluation.

Example usage:

// Old NUMERIC_EVALUATOR code:
eval.Process("1 + 2");
wxString result = eval.Result(); // "3"
// New compatible code:
eval.Process("1 + 2");
wxString result = eval.Result(); // "3"
NUMERIC_EVALUATOR_COMPAT(EDA_UNITS aUnits)
Constructor with default units.
wxString result
Test unit parsing edge cases and error handling.

Definition at line 438 of file text_eval_wrapper.h.

Constructor & Destructor Documentation

◆ NUMERIC_EVALUATOR_COMPAT()

NUMERIC_EVALUATOR_COMPAT::NUMERIC_EVALUATOR_COMPAT ( EDA_UNITS aUnits)
explicit

Constructor with default units.

Parameters
aUnitsDefault units for the evaluator

Definition at line 1913 of file text_eval_wrapper.cpp.

References m_evaluator, and m_lastValid.

◆ ~NUMERIC_EVALUATOR_COMPAT()

NUMERIC_EVALUATOR_COMPAT::~NUMERIC_EVALUATOR_COMPAT ( )
default

Member Function Documentation

◆ Clear()

void NUMERIC_EVALUATOR_COMPAT::Clear ( )

Clear parser state but retain variables.

Resets the parser state for processing a new expression. User-defined variables are retained.

Definition at line 1920 of file text_eval_wrapper.cpp.

References m_evaluator, m_lastInput, m_lastResult, and m_lastValid.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ ClearVar()

void NUMERIC_EVALUATOR_COMPAT::ClearVar ( )

Remove all variables.

Definition at line 2064 of file text_eval_wrapper.cpp.

References m_evaluator.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ GetVar()

double NUMERIC_EVALUATOR_COMPAT::GetVar ( const wxString & aString)

Get a variable value.

Parameters
aStringVariable name
Returns
Variable value, or 0.0 if not defined

Definition at line 2043 of file text_eval_wrapper.cpp.

References m_evaluator, and result.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ IsValid()

bool NUMERIC_EVALUATOR_COMPAT::IsValid ( ) const

Check if the last evaluation was successful.

Returns
True if last Process() call was successful

Definition at line 1938 of file text_eval_wrapper.cpp.

References m_lastValid.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ LocaleChanged()

void NUMERIC_EVALUATOR_COMPAT::LocaleChanged ( )

Handle locale changes (for decimal separator)

This is a no-op in the EXPRESSION_EVALUATOR implementation since it handles locale properly internally.

Definition at line 1933 of file text_eval_wrapper.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ OriginalText()

wxString NUMERIC_EVALUATOR_COMPAT::OriginalText ( ) const

Get the original input text.

Returns
The last input string passed to Process()

Definition at line 2033 of file text_eval_wrapper.cpp.

References m_lastInput.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ Process()

bool NUMERIC_EVALUATOR_COMPAT::Process ( const wxString & aString)

Process and evaluate an expression.

Parameters
aStringExpression to evaluate
Returns
True if evaluation was successful

Definition at line 1948 of file text_eval_wrapper.cpp.

References m_evaluator, m_lastInput, m_lastResult, and m_lastValid.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ RemoveVar()

void NUMERIC_EVALUATOR_COMPAT::RemoveVar ( const wxString & aString)

Remove a single variable.

Parameters
aStringVariable name to remove

Definition at line 2059 of file text_eval_wrapper.cpp.

References m_evaluator.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ Result()

wxString NUMERIC_EVALUATOR_COMPAT::Result ( ) const

Get the result of the last evaluation.

Returns
Result string, or empty if invalid

Definition at line 1943 of file text_eval_wrapper.cpp.

References m_lastResult.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

◆ SetDefaultUnits()

void NUMERIC_EVALUATOR_COMPAT::SetDefaultUnits ( EDA_UNITS aUnits)

Set default units for evaluation.

Parameters
aUnitsThe default units to use

Definition at line 1928 of file text_eval_wrapper.cpp.

References m_evaluator.

Referenced by ~NUMERIC_EVALUATOR_COMPAT().

◆ SetVar()

void NUMERIC_EVALUATOR_COMPAT::SetVar ( const wxString & aString,
double aValue )

Set a variable value.

Parameters
aStringVariable name
aValueVariable value

Definition at line 2038 of file text_eval_wrapper.cpp.

References m_evaluator.

Referenced by BOOST_AUTO_TEST_CASE(), and ~NUMERIC_EVALUATOR_COMPAT().

Member Data Documentation

◆ m_evaluator

EXPRESSION_EVALUATOR NUMERIC_EVALUATOR_COMPAT::m_evaluator
private

◆ m_lastInput

wxString NUMERIC_EVALUATOR_COMPAT::m_lastInput
private

Definition at line 442 of file text_eval_wrapper.h.

Referenced by Clear(), OriginalText(), and Process().

◆ m_lastResult

wxString NUMERIC_EVALUATOR_COMPAT::m_lastResult
private

Definition at line 443 of file text_eval_wrapper.h.

Referenced by Clear(), Process(), and Result().

◆ m_lastValid

bool NUMERIC_EVALUATOR_COMPAT::m_lastValid
private

Definition at line 444 of file text_eval_wrapper.h.

Referenced by Clear(), IsValid(), NUMERIC_EVALUATOR_COMPAT(), and Process().


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