Inkscape
Vector Graphics Editor
|
#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 |
string | NULL terminated input string to evaluate |
unit | Unit output should be in |
Definition at line 138 of file expression-evaluator.h.
Inkscape::Util::ExpressionEvaluator::ExpressionEvaluator | ( | const char * | string, |
Unit const * | unit = nullptr |
||
) |
Definition at line 50 of file expression-evaluator.cpp.
References current_token, parseNextToken(), Inkscape::Util::TOKEN_END, and Inkscape::Util::EvaluatorToken::type.
|
private |
Definition at line 245 of file expression-evaluator.cpp.
References current_token, parseNextToken(), Inkscape::Util::TOKEN_ANY, and Inkscape::Util::EvaluatorToken::type.
Referenced by evaluate(), evaluateExpression(), evaluateExpTerm(), evaluateFactor(), evaluateSignedFactor(), evaluateTerm(), and isExpected().
|
private |
Definition at line 303 of file expression-evaluator.cpp.
References current_token, and Inkscape::Util::EvaluatorToken::type.
Referenced by parseNextToken().
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).
Inkscape::Util::EvaluatorException | There 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().
|
private |
Definition at line 103 of file expression-evaluator.cpp.
References acceptToken(), Inkscape::Util::EvaluatorQuantity::dimension, evaluateTerm(), resolveUnit(), throwError(), unit, and Inkscape::Util::EvaluatorQuantity::value.
Referenced by evaluate(), and evaluateFactor().
|
private |
Definition at line 169 of file expression-evaluator.cpp.
References acceptToken(), Inkscape::Util::EvaluatorQuantity::dimension, evaluateSignedFactor(), throwError(), and Inkscape::Util::EvaluatorQuantity::value.
Referenced by evaluateTerm().
|
private |
Definition at line 206 of file expression-evaluator.cpp.
References acceptToken(), Inkscape::Util::EvaluatorToken::c, current_token, Inkscape::Util::EvaluatorQuantity::dimension, evaluateExpression(), Inkscape::Util::EvaluatorToken::fl, isExpected(), resolveUnit(), result, Inkscape::Util::EvaluatorToken::size, throwError(), Inkscape::Util::TOKEN_ANY, Inkscape::Util::TOKEN_END, Inkscape::Util::TOKEN_IDENTIFIER, Inkscape::Util::TOKEN_NUM, Inkscape::Util::EvaluatorToken::type, unit, Inkscape::Util::EvaluatorQuantity::value, and Inkscape::Util::EvaluatorToken::value.
Referenced by evaluateSignedFactor().
|
private |
Definition at line 188 of file expression-evaluator.cpp.
References acceptToken(), evaluateFactor(), and result.
Referenced by evaluateExpTerm().
|
private |
Definition at line 144 of file expression-evaluator.cpp.
References acceptToken(), Inkscape::Util::EvaluatorQuantity::dimension, evaluateExpTerm(), and Inkscape::Util::EvaluatorQuantity::value.
Referenced by evaluateExpression().
|
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().
|
private |
Definition at line 309 of file expression-evaluator.cpp.
References acceptToken(), and throwError().
Referenced by evaluate(), and evaluateFactor().
|
staticprivate |
Definition at line 328 of file expression-evaluator.cpp.
References c.
Referenced by getIdentifierSize(), and parseNextToken().
|
private |
Definition at line 317 of file expression-evaluator.cpp.
Referenced by parseNextToken().
|
private |
Definition at line 264 of file expression-evaluator.cpp.
References acceptTokenCount(), Inkscape::Util::EvaluatorToken::c, current_token, Inkscape::Util::EvaluatorToken::fl, getIdentifierSize(), isUnitIdentifierStart(), movePastWhiteSpace(), Inkscape::Util::EvaluatorToken::size, start_of_current_token, string, Inkscape::Util::TOKEN_END, Inkscape::Util::TOKEN_IDENTIFIER, Inkscape::Util::TOKEN_NUM, Inkscape::Util::EvaluatorToken::type, and Inkscape::Util::EvaluatorToken::value.
Referenced by acceptToken(), and ExpressionEvaluator().
|
staticprivate |
Definition at line 365 of file expression-evaluator.cpp.
References Inkscape::Util::Quantity::convert(), Inkscape::Util::UnitTable::get(), Inkscape::Util::Unit::isAbsolute(), result, and unit.
Referenced by evaluate(), evaluateExpression(), and evaluateFactor().
|
private |
Definition at line 388 of file expression-evaluator.cpp.
References msg, and start_of_current_token.
Referenced by evaluateExpression(), evaluateExpTerm(), evaluateFactor(), and isExpected().
|
private |
Definition at line 149 of file expression-evaluator.h.
Referenced by acceptToken(), acceptTokenCount(), evaluateFactor(), ExpressionEvaluator(), and parseNextToken().
|
private |
Definition at line 150 of file expression-evaluator.h.
Referenced by parseNextToken(), and throwError().
|
private |
Definition at line 146 of file expression-evaluator.h.
Referenced by parseNextToken().
|
private |
Definition at line 147 of file expression-evaluator.h.
Referenced by evaluate(), evaluateExpression(), evaluateFactor(), and resolveUnit().