KiCad PCB EDA Suite
PCB_EXPR_EVALUATOR Class Reference

#include <pcb_expr_evaluator.h>

Public Member Functions

 PCB_EXPR_EVALUATOR ()
 
 ~PCB_EXPR_EVALUATOR ()
 
bool Evaluate (const wxString &aExpr)
 
int Result () const
 
void SetErrorCallback (std::function< void(const wxString &aMessage, int aOffset)> aCallback)
 
bool IsErrorPending () const
 
const LIBEVAL::ERROR_STATUSGetError () const
 

Private Attributes

int m_result
 
PCB_EXPR_COMPILER m_compiler
 
PCB_EXPR_UCODE m_ucode
 
LIBEVAL::ERROR_STATUS m_errorStatus
 

Detailed Description

Definition at line 206 of file pcb_expr_evaluator.h.

Constructor & Destructor Documentation

◆ PCB_EXPR_EVALUATOR()

PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR ( )

Definition at line 1217 of file pcb_expr_evaluator.cpp.

1217 :
1218 m_result( 0 ),
1219 m_compiler(),
1220 m_ucode(),
1222{
1223}
PCB_EXPR_COMPILER m_compiler
PCB_EXPR_UCODE m_ucode
LIBEVAL::ERROR_STATUS m_errorStatus

◆ ~PCB_EXPR_EVALUATOR()

PCB_EXPR_EVALUATOR::~PCB_EXPR_EVALUATOR ( )

Definition at line 1226 of file pcb_expr_evaluator.cpp.

1227{
1228}

Member Function Documentation

◆ Evaluate()

bool PCB_EXPR_EVALUATOR::Evaluate ( const wxString &  aExpr)

Definition at line 1231 of file pcb_expr_evaluator.cpp.

1232{
1233 PCB_EXPR_UCODE ucode;
1234 PCB_EXPR_CONTEXT preflightContext( NULL_CONSTRAINT, F_Cu );
1235
1236 if( !m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ) )
1237 return false;
1238
1239 PCB_EXPR_CONTEXT evaluationContext( NULL_CONSTRAINT, F_Cu );
1240 LIBEVAL::VALUE* result = ucode.Run( &evaluationContext );
1241
1242 if( result->GetType() == LIBEVAL::VT_NUMERIC )
1243 m_result = KiROUND( result->AsDouble() );
1244
1245 return true;
1246}
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
VALUE * Run(CONTEXT *ctx)
virtual double AsDouble() const
VAR_TYPE_T GetType() const
@ NULL_CONSTRAINT
Definition: drc_rule.h:45
@ F_Cu
Definition: layer_ids.h:64
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80

References LIBEVAL::VALUE::AsDouble(), LIBEVAL::COMPILER::Compile(), F_Cu, LIBEVAL::VALUE::GetType(), KiROUND(), m_compiler, m_result, NULL_CONSTRAINT, LIBEVAL::UCODE::Run(), and LIBEVAL::VT_NUMERIC.

Referenced by DRC_RULES_PARSER::parseValueWithUnits().

◆ GetError()

const LIBEVAL::ERROR_STATUS & PCB_EXPR_EVALUATOR::GetError ( ) const
inline

Definition at line 221 of file pcb_expr_evaluator.h.

221{ return m_errorStatus; }

References m_errorStatus.

◆ IsErrorPending()

bool PCB_EXPR_EVALUATOR::IsErrorPending ( ) const
inline

◆ Result()

int PCB_EXPR_EVALUATOR::Result ( ) const
inline

Definition at line 213 of file pcb_expr_evaluator.h.

213{ return m_result; }

References m_result.

Referenced by DRC_RULES_PARSER::parseValueWithUnits().

◆ SetErrorCallback()

void PCB_EXPR_EVALUATOR::SetErrorCallback ( std::function< void(const wxString &aMessage, int aOffset)>  aCallback)
inline

Definition at line 215 of file pcb_expr_evaluator.h.

216 {
217 m_compiler.SetErrorCallback( aCallback );
218 }
void SetErrorCallback(std::function< void(const wxString &aMessage, int aOffset)> aCallback)

References m_compiler, and LIBEVAL::COMPILER::SetErrorCallback().

Referenced by DRC_RULES_PARSER::parseValueWithUnits().

Member Data Documentation

◆ m_compiler

PCB_EXPR_COMPILER PCB_EXPR_EVALUATOR::m_compiler
private

Definition at line 226 of file pcb_expr_evaluator.h.

Referenced by Evaluate(), and SetErrorCallback().

◆ m_errorStatus

LIBEVAL::ERROR_STATUS PCB_EXPR_EVALUATOR::m_errorStatus
private

Definition at line 228 of file pcb_expr_evaluator.h.

Referenced by GetError(), and IsErrorPending().

◆ m_result

int PCB_EXPR_EVALUATOR::m_result
private

Definition at line 224 of file pcb_expr_evaluator.h.

Referenced by Evaluate(), and Result().

◆ m_ucode

PCB_EXPR_UCODE PCB_EXPR_EVALUATOR::m_ucode
private

Definition at line 227 of file pcb_expr_evaluator.h.


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