Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Util::ExpressionEvaluator Class Reference

ExpressionEvaluator. More...

#include <expression-evaluator.h>

Public Member Functions

 ExpressionEvaluator (const char *string, Unit const *unit=nullptr)
 
EvaluatorQuantity evaluate ()
 Evaluates the given arithmetic expression, along with an optional dimension analysis, and basic unit conversions.
 

Private Member Functions

EvaluatorQuantity evaluateExpression ()
 
EvaluatorQuantity evaluateTerm ()
 
EvaluatorQuantity evaluateExpTerm ()
 
EvaluatorQuantity evaluateSignedFactor ()
 
EvaluatorQuantity evaluateFactor ()
 
bool acceptToken (TokenType token_type, EvaluatorToken *consumed_token)
 
void parseNextToken ()
 
void acceptTokenCount (int count, TokenType token_type)
 
void isExpected (TokenType token_type, EvaluatorToken *value)
 
void movePastWhiteSpace ()
 
void throwError (const char *msg)
 

Static Private Member Functions

static bool isUnitIdentifierStart (gunichar c)
 
static int getIdentifierSize (const char *s, int start)
 getIdentifierSize: @s: @start:
 
static bool resolveUnit (const char *identifier, EvaluatorQuantity *result, Unit const *unit)
 

Private Attributes

const char * string
 
Unit const * unit
 
EvaluatorToken current_token
 
const char * start_of_current_token
 

Detailed Description

ExpressionEvaluator.

Parameters
stringNULL terminated input string to evaluate
unitUnit output should be in

Definition at line 138 of file expression-evaluator.h.

Constructor & Destructor Documentation

◆ ExpressionEvaluator()

Inkscape::Util::ExpressionEvaluator::ExpressionEvaluator ( const char *  string,
Unit const *  unit = nullptr 
)

Member Function Documentation

◆ acceptToken()

bool Inkscape::Util::ExpressionEvaluator::acceptToken ( TokenType  token_type,
EvaluatorToken consumed_token 
)
private

◆ acceptTokenCount()

void Inkscape::Util::ExpressionEvaluator::acceptTokenCount ( int  count,
TokenType  token_type 
)
private

Definition at line 303 of file expression-evaluator.cpp.

References current_token, and Inkscape::Util::EvaluatorToken::type.

Referenced by parseNextToken().

◆ evaluate()

EvaluatorQuantity Inkscape::Util::ExpressionEvaluator::evaluate ( )

Evaluates the given arithmetic expression, along with an optional dimension analysis, and basic unit conversions.

All units conversions factors are relative to some implicit base-unit. This is also the unit of the returned value.

Returns: An EvaluatorQuantity with a value given in the base unit along with the order of the dimension (e.g. if the base unit is inches, a dimension order of two means in^2).

Returns
Result of evaluation.
Exceptions
Inkscape::Util::EvaluatorExceptionThere was a parse error.

Definition at line 74 of file expression-evaluator.cpp.

References acceptToken(), Inkscape::Util::EvaluatorQuantity::dimension, evaluateExpression(), isExpected(), resolveUnit(), result, Inkscape::Util::TOKEN_END, unit, and Inkscape::Util::EvaluatorQuantity::value.

Referenced by Inkscape::UI::Widget::InkSpinButton::commit_entry(), Inkscape::UI::Widget::MathSpinButton::on_input(), and Inkscape::UI::Widget::SpinButton::on_input().

◆ evaluateExpression()

EvaluatorQuantity Inkscape::Util::ExpressionEvaluator::evaluateExpression ( )
private

◆ evaluateExpTerm()

EvaluatorQuantity Inkscape::Util::ExpressionEvaluator::evaluateExpTerm ( )
private

◆ evaluateFactor()

◆ evaluateSignedFactor()

EvaluatorQuantity Inkscape::Util::ExpressionEvaluator::evaluateSignedFactor ( )
private

Definition at line 188 of file expression-evaluator.cpp.

References acceptToken(), evaluateFactor(), and result.

Referenced by evaluateExpTerm().

◆ evaluateTerm()

EvaluatorQuantity Inkscape::Util::ExpressionEvaluator::evaluateTerm ( )
private

◆ getIdentifierSize()

int Inkscape::Util::ExpressionEvaluator::getIdentifierSize ( const char *  string,
int  start_offset 
)
staticprivate

getIdentifierSize: @s: @start:

Returns: Size of identifier in bytes (not including NULL terminator).

Definition at line 343 of file expression-evaluator.cpp.

References c, isUnitIdentifierStart(), and start.

Referenced by parseNextToken().

◆ isExpected()

void Inkscape::Util::ExpressionEvaluator::isExpected ( TokenType  token_type,
EvaluatorToken value 
)
private

Definition at line 309 of file expression-evaluator.cpp.

References acceptToken(), and throwError().

Referenced by evaluate(), and evaluateFactor().

◆ isUnitIdentifierStart()

bool Inkscape::Util::ExpressionEvaluator::isUnitIdentifierStart ( gunichar  c)
staticprivate

Definition at line 328 of file expression-evaluator.cpp.

References c.

Referenced by getIdentifierSize(), and parseNextToken().

◆ movePastWhiteSpace()

void Inkscape::Util::ExpressionEvaluator::movePastWhiteSpace ( )
private

Definition at line 317 of file expression-evaluator.cpp.

Referenced by parseNextToken().

◆ parseNextToken()

◆ resolveUnit()

bool Inkscape::Util::ExpressionEvaluator::resolveUnit ( const char *  identifier,
EvaluatorQuantity result,
Unit const *  unit 
)
staticprivate

◆ throwError()

void Inkscape::Util::ExpressionEvaluator::throwError ( const char *  msg)
private

Member Data Documentation

◆ current_token

EvaluatorToken Inkscape::Util::ExpressionEvaluator::current_token
private

◆ start_of_current_token

const char* Inkscape::Util::ExpressionEvaluator::start_of_current_token
private

Definition at line 150 of file expression-evaluator.h.

Referenced by parseNextToken(), and throwError().

◆ string

const char* Inkscape::Util::ExpressionEvaluator::string
private

Definition at line 146 of file expression-evaluator.h.

Referenced by parseNextToken().

◆ unit

Unit const* Inkscape::Util::ExpressionEvaluator::unit
private

Definition at line 147 of file expression-evaluator.h.

Referenced by evaluate(), evaluateExpression(), evaluateFactor(), and resolveUnit().


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