|
Krita Source Code Documentation
|
#include <EnhancedPathFormula.h>
Public Types | |
| enum | Error { ErrorNone , ErrorValue , ErrorParse , ErrorCompile , ErrorName } |
| The possible error code returned by error() More... | |
| enum | Function { FunctionUnknown , FunctionAbs , FunctionSqrt , FunctionSin , FunctionCos , FunctionTan , FunctionAtan , FunctionAtan2 , FunctionMin , FunctionMax , FunctionIf } |
| predefined functions More... | |
Public Member Functions | |
| EnhancedPathFormula (const QString &text, EnhancedPathShape *parent) | |
| Constructs a new formula from the specified string representation. | |
| Error | error () const |
| Returns the last occurred error. | |
| qreal | evaluate () |
| QString | toString () const |
| returns string representation of the formula | |
| ~EnhancedPathFormula () | |
| Destroys the formula. | |
Private Member Functions | |
| bool | compile (const TokenList &tokens) |
| Compiles the formula tokens into byte code. | |
| void | debugOpcodes () |
| Prints byte code. | |
| void | debugTokens (const TokenList &tokens) |
| Prints token list. | |
| qreal | evaluateFunction (Function function, const QList< qreal > &arguments) const |
| TokenList | scan (const QString &formula) const |
| Separates the given formula text into tokens. | |
Private Attributes | |
| QList< Opcode > | m_codes |
| the compiled byte code | |
| bool | m_compiled |
| flag that shows if function was compiled | |
| QList< QVariant > | m_constants |
| constant values | |
| Error | m_error |
| the last occurred error | |
| EnhancedPathShape * | m_parent |
| QString | m_text |
| the formula text representation | |
| bool | m_valid |
| flag that shows if function is valid, i.e the function was compiled successfully | |
Definition at line 99 of file EnhancedPathFormula.h.
The possible error code returned by error()
| Enumerator | |
|---|---|
| ErrorNone | no error |
| ErrorValue | error when converting value |
| ErrorParse | parsing error |
| ErrorCompile | compiling error |
| ErrorName | invalid function name value |
Definition at line 121 of file EnhancedPathFormula.h.
predefined functions
| Enumerator | |
|---|---|
| FunctionUnknown | |
| FunctionAbs | |
| FunctionSqrt | |
| FunctionSin | |
| FunctionCos | |
| FunctionTan | |
| FunctionAtan | |
| FunctionAtan2 | |
| FunctionMin | |
| FunctionMax | |
| FunctionIf | |
Definition at line 103 of file EnhancedPathFormula.h.
| EnhancedPathFormula::EnhancedPathFormula | ( | const QString & | text, |
| EnhancedPathShape * | parent ) |
Constructs a new formula from the specified string representation.
Definition at line 99 of file EnhancedPathFormula.cpp.
References m_parent.
| EnhancedPathFormula::~EnhancedPathFormula | ( | ) |
|
private |
Compiles the formula tokens into byte code.
Definition at line 426 of file EnhancedPathFormula.cpp.
References Opcode::Add, FormulaToken::asNumber(), FormulaToken::asOperator(), Opcode::Div, Opcode::Function, FormulaToken::isOperator(), FormulaTokenStack::itemCount(), Opcode::Load, m_codes, m_constants, m_text, m_valid, Opcode::Mul, Opcode::Neg, FormulaToken::OperatorAdd, FormulaToken::OperatorComma, FormulaToken::OperatorDiv, FormulaToken::OperatorInvalid, FormulaToken::OperatorLeftPar, FormulaToken::OperatorMul, FormulaToken::OperatorRightPar, FormulaToken::OperatorSub, opPrecedence(), FormulaTokenStack::pop(), FormulaTokenStack::push(), Opcode::Ref, Opcode::Sub, FormulaToken::text(), FormulaTokenStack::top(), FormulaToken::type(), FormulaToken::TypeFunction, FormulaToken::TypeNumber, FormulaToken::TypeOperator, FormulaToken::TypeReference, and FormulaToken::TypeUnknown.
|
private |
Prints byte code.
Definition at line 828 of file EnhancedPathFormula.cpp.
References Opcode::Add, Opcode::Div, Opcode::Function, Opcode::index, Opcode::Load, m_codes, Opcode::Mul, Opcode::Neg, Opcode::Ref, Opcode::Sub, and Opcode::type.
Prints token list.
Definition at line 817 of file EnhancedPathFormula.cpp.
|
inline |
Returns the last occurred error.
Definition at line 144 of file EnhancedPathFormula.h.
References m_error.
| qreal EnhancedPathFormula::evaluate | ( | ) |
Evaluates the formula using the given path as possible input.
| path | the path to use as input |
prepare function arguments
Definition at line 113 of file EnhancedPathFormula.cpp.
References Opcode::Add, compile(), debugOpcodes(), Opcode::Div, ErrorCompile, ErrorNone, ErrorParse, ErrorValue, evaluateFunction(), EnhancedPathShape::evaluateReference(), Opcode::Function, FunctionUnknown, Opcode::index, Opcode::Load, m_codes, m_compiled, m_constants, m_error, m_parent, m_text, m_valid, matchFunction(), Opcode::Mul, Opcode::Neg, Opcode::Nop, Opcode::Ref, scan(), Opcode::Sub, Opcode::type, and value().
|
private |
Evaluates a predefined function.
| function | the identifier of the function to evaluate |
| arguments | the functions arguments |
Definition at line 247 of file EnhancedPathFormula.cpp.
References FunctionAbs, FunctionAtan, FunctionAtan2, FunctionCos, FunctionIf, FunctionMax, FunctionMin, FunctionSin, FunctionSqrt, and FunctionTan.
|
private |
Separates the given formula text into tokens.
Definition at line 292 of file EnhancedPathFormula.cpp.
References isIdentifier(), matchOperator(), FormulaToken::OperatorInvalid, FormulaToken::TypeFunction, FormulaToken::TypeNumber, FormulaToken::TypeOperator, and FormulaToken::TypeReference.
| QString EnhancedPathFormula::toString | ( | ) | const |
returns string representation of the formula
Definition at line 649 of file EnhancedPathFormula.cpp.
References m_text.
the compiled byte code
Definition at line 176 of file EnhancedPathFormula.h.
|
private |
flag that shows if function was compiled
Definition at line 172 of file EnhancedPathFormula.h.
|
private |
constant values
Definition at line 175 of file EnhancedPathFormula.h.
|
private |
the last occurred error
Definition at line 173 of file EnhancedPathFormula.h.
|
private |
Definition at line 177 of file EnhancedPathFormula.h.
|
private |
the formula text representation
Definition at line 174 of file EnhancedPathFormula.h.
|
private |
flag that shows if function is valid, i.e the function was compiled successfully
Definition at line 171 of file EnhancedPathFormula.h.