KiCad PCB EDA Suite
PCB_EXPR_EVALUATOR Class Reference

#include <pcb_expr_evaluator.h>

Public Member Functions

 PCB_EXPR_EVALUATOR (LIBEVAL::UNIT_RESOLVER *aUnitResolver)
 
 ~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 226 of file pcb_expr_evaluator.h.

Constructor & Destructor Documentation

◆ PCB_EXPR_EVALUATOR()

PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR ( LIBEVAL::UNIT_RESOLVER aUnitResolver)

Definition at line 344 of file pcb_expr_evaluator.cpp.

344 :
345 m_result( 0 ),
346 m_compiler( aUnitResolver ),
347 m_ucode(),
349{
350}
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 353 of file pcb_expr_evaluator.cpp.

354{
355}

Member Function Documentation

◆ Evaluate()

bool PCB_EXPR_EVALUATOR::Evaluate ( const wxString &  aExpr)

Definition at line 358 of file pcb_expr_evaluator.cpp.

359{
360 PCB_EXPR_UCODE ucode;
361 PCB_EXPR_CONTEXT preflightContext( NULL_CONSTRAINT, F_Cu );
362
363 if( !m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ) )
364 return false;
365
366 PCB_EXPR_CONTEXT evaluationContext( NULL_CONSTRAINT, F_Cu );
367 LIBEVAL::VALUE* result = ucode.Run( &evaluationContext );
368
369 if( result->GetType() == LIBEVAL::VT_NUMERIC )
370 m_result = KiROUND( result->AsDouble() );
371
372 return true;
373}
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:46
@ 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:85

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 241 of file pcb_expr_evaluator.h.

241{ 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 233 of file pcb_expr_evaluator.h.

233{ 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 235 of file pcb_expr_evaluator.h.

236 {
237 m_compiler.SetErrorCallback( aCallback );
238 }
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 246 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 248 of file pcb_expr_evaluator.h.

Referenced by GetError(), and IsErrorPending().

◆ m_result

int PCB_EXPR_EVALUATOR::m_result
private

Definition at line 244 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 247 of file pcb_expr_evaluator.h.


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