#include <qmutokenparser.h>
Public Member Functions | |
QmuTokenParser (const QString &formula, bool osSeparator, bool fromUser=true) | |
QmuTokenParser class constructor. Make easy initialization math parser. More... | |
virtual | ~QmuTokenParser () Q_DECL_OVERRIDE |
Public Member Functions inherited from qmu::QmuFormulaBase | |
QmuFormulaBase () | |
virtual | ~QmuFormulaBase () Q_DECL_OVERRIDE |
virtual void | InitCharSets () Q_DECL_OVERRIDE |
InitCharSets init character set for parser. More... | |
Public Member Functions inherited from qmu::QmuParser | |
QmuParser () | |
Constructor. More... | |
virtual void | InitFun () Q_DECL_OVERRIDE |
Initialize the default functions. More... | |
virtual void | InitConst () Q_DECL_OVERRIDE |
Initialize constants. More... | |
virtual void | InitOprt () Q_DECL_OVERRIDE |
Initialize operators. More... | |
virtual void | OnDetectVar (const QString &pExpr, int &nStart, int &nEnd) Q_DECL_OVERRIDE |
qreal | Diff (qreal *a_Var, qreal a_fPos, qreal a_fEpsilon=0) const |
Numerically differentiate with regard to a variable. More... | |
Public Member Functions inherited from qmu::QmuParserBase | |
QmuParserBase () | |
Constructor. More... | |
QmuParserBase (const QmuParserBase &a_Parser) | |
Copy constructor. More... | |
QmuParserBase & | operator= (const QmuParserBase &a_Parser) |
Assignement operator. More... | |
virtual | ~QmuParserBase () |
qreal | Eval () const |
Calculate the result. More... | |
qreal * | Eval (int &nStackSize) const |
Evaluate an expression containing comma seperated subexpressions. More... | |
void | Eval (qreal *results, int nBulkSize) const |
int | GetNumResults () const |
Return the number of results on the calculation stack. More... | |
void | SetExpr (const QString &a_sExpr) |
Set the formula. More... | |
void | SetVarFactory (facfun_type a_pFactory, void *pUserData=nullptr) |
Set a function that can create variable pointer for unknown expression variables. More... | |
void | ResetLocale () |
Resets the locale. More... | |
void | EnableOptimizer (bool a_bIsOn=true) |
Enable or disable the formula optimization feature. More... | |
void | EnableBuiltInOprt (bool a_bIsOn=true) |
Enable or disable the built in binary operators. More... | |
bool | HasBuiltInOprt () const |
Query status of built in variables. More... | |
void | AddValIdent (identfun_type a_pCallback) |
Add a value parsing function. More... | |
void | DefineOprt (const QString &a_sName, fun_type2 a_pFun, unsigned a_iPrec=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool a_bAllowOpt=false) |
Define a binary operator. More... | |
void | DefineConst (const QString &a_sName, qreal a_fVal) |
Add a user defined constant. More... | |
void | DefineStrConst (const QString &a_strName, const QString &a_strVal) |
Define a new string constant. More... | |
void | DefineVar (const QString &a_sName, qreal *a_pVar) |
Add a user defined variable. More... | |
void | DefinePostfixOprt (const QString &a_sFun, fun_type1 a_pFun, bool a_bAllowOpt=true) |
Add a user defined operator. More... | |
void | DefineInfixOprt (const QString &a_sName, fun_type1 a_pFun, int a_iPrec=prINFIX, bool a_bAllowOpt=true) |
Add a user defined operator. More... | |
void | ClearVar () |
Clear all user defined variables. More... | |
void | ClearFun () |
Clear all functions. More... | |
void | ClearConst () |
Clear all user defined constants. More... | |
void | ClearInfixOprt () |
Clear the user defined Prefix operators. More... | |
void | ClearPostfixOprt () |
Clear all user defined postfix operators. More... | |
void | ClearOprt () |
Clear all user defined binary operators. More... | |
void | RemoveVar (const QString &a_strVarName) |
Remove a variable from internal storage. More... | |
const varmap_type & | GetUsedVar () const |
Return a map containing the used variables only. More... | |
const varmap_type & | GetVar () const |
Return a map containing the used variables only. More... | |
const valmap_type & | GetConst () const |
Return a map containing all parser constants. More... | |
const QString & | GetExpr () const |
Retrieve the formula. More... | |
const funmap_type & | GetFunDef () const |
Return prototypes of all parser functions. More... | |
QMap< int, QString > | GetTokens () const |
QMap< int, QString > | GetNumbers () const |
void | DefineNameChars (const QString &a_szCharset) |
Define the set of valid characters to be used in names of functions, variables, constants. More... | |
void | DefineOprtChars (const QString &a_szCharset) |
Define the set of valid characters to be used in names of binary operators and postfix operators. More... | |
void | DefineInfixOprtChars (const QString &a_szCharset) |
Define the set of valid characters to be used in names of infix operators. More... | |
const QString & | ValidNameChars () const |
Virtual function that defines the characters allowed in name identifiers. More... | |
const QString & | ValidOprtChars () const |
Virtual function that defines the characters allowed in operator definitions. More... | |
const QString & | ValidInfixOprtChars () const |
Virtual function that defines the characters allowed in infix operator definitions. More... | |
void | SetArgSep (char_type cArgSep) |
Set argument separator. More... | |
QChar | GetArgSep () const |
Get the argument separator character. More... | |
void Q_NORETURN | Error (EErrorCodes a_iErrc, int a_iPos=-1, const QString &a_sTok=QString()) const |
Create an error containing the parse error position. More... | |
template<typename T > | |
void | DefineFun (const QString &a_strName, T a_pFun, bool a_bAllowOpt=true) |
Define a parser function without arguments. More... | |
void | setAllowSubexpressions (bool value) |
QLocale | getLocale () const |
void | setLocale (const QLocale &value) |
QChar | getDecimalPoint () const |
void | setDecimalPoint (const QChar &c) |
QChar | getThousandsSeparator () const |
void | setThousandsSeparator (const QChar &c) |
Static Public Member Functions | |
static bool | IsSingle (const QString &formula) |
IsSingle test formula and return true if it contain only one number. More... | |
Static Public Member Functions inherited from qmu::QmuFormulaBase | |
static void | RemoveAll (QMap< int, QString > &map, const QString &val) |
RemoveAll remove token from token list. More... | |
Static Public Member Functions inherited from qmu::QmuParserBase | |
static void | EnableDebugDump (bool bDumpCmd, bool bDumpStack) |
Enable the dumping of bytecode amd stack content on the console. More... | |
static QString | GetVersion (EParserVersionInfo eInfo=pviFULL) |
Returns the version of muparser. More... | |
static const QStringList & | GetOprtDef () |
Get the default symbols used for the built in operators. More... | |
Private Member Functions | |
QmuTokenParser () | |
Additional Inherited Members | |
Protected Member Functions inherited from qmu::QmuFormulaBase | |
void | SetSepForTr (bool osSeparator, bool fromUser) |
SetSepForTr set separators for translation expression. More... | |
void | SetSepForEval () |
SetSepForEval set separators for eval. Each expression eval in internal (C) locale. More... | |
Protected Member Functions inherited from qmu::QmuParserBase | |
void | Init () |
Initialize user defined functions. More... | |
Static Protected Member Functions inherited from qmu::QmuFormulaBase | |
static qreal * | AddVariable (const QString &a_szName, void *a_pUserData) |
Static Protected Member Functions inherited from qmu::QmuParser | |
static int | IsVal (const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale, const QChar &decimal, const QChar &thousand) |
Default value recognition callback. More... | |
static qreal | Sinh (qreal) |
static qreal | Cosh (qreal) |
static qreal | Tanh (qreal) |
static qreal | ASinh (qreal) |
static qreal | ACosh (qreal) |
static qreal | ATanh (qreal) |
static qreal | DegreeToRadian (qreal) |
static qreal | RadianToDegree (qreal) |
static qreal | SinD (qreal) |
static qreal | CosD (qreal) |
static qreal | TanD (qreal) |
static qreal | ASinD (qreal) |
static qreal | ACosD (qreal) |
static qreal | ATanD (qreal) |
static qreal | Log2 (qreal) |
static qreal | Log10 (qreal) |
static qreal | Abs (qreal) |
static qreal | Rint (qreal) |
static qreal | Sign (qreal) |
static qreal | FMod (qreal, qreal) |
static qreal | UnaryMinus (qreal v) |
Callback for the unary minus operator. More... | |
static qreal | Sum (const qreal *, int) |
Callback for adding multiple values. More... | |
static qreal | Avg (const qreal *, int) |
Callback for averaging multiple values. More... | |
static qreal | Min (const qreal *, int) |
Callback for determining the minimum value out of a vector. More... | |
static qreal | Max (const qreal *, int) |
Callback for determining the maximum value out of a vector. More... | |
Protected Attributes inherited from qmu::QmuParserBase | |
QLocale | m_locale |
The locale used by the parser. More... | |
QChar | m_decimalPoint |
QChar | m_thousandsSeparator |
Static Protected Attributes inherited from qmu::QmuParserBase | |
static const QStringList | c_DefaultOprt |
Identifiers for built in binary operators. More... | |
static bool | g_DbgDumpCmdCode = false |
static bool | g_DbgDumpStack = false |
Definition at line 34 of file qmutokenparser.h.
qmu::QmuTokenParser::QmuTokenParser | ( | const QString & | formula, |
bool | osSeparator, | ||
bool | fromUser = true |
||
) |
QmuTokenParser class constructor. Make easy initialization math parser.
This constructor hide initialization variables, operators, character sets. Use this constuctor to get tokens from formula. All formulas must be converted to external look. Example:
QmuTokenParser *cal = new QmuTokenParser(formula, osSeparator, false); tokens = cal->GetTokens(); numbers = cal->GetNumbers(); delete cal;
formula | string with formula. |
fromUser | true if we parse formula from user |
Definition at line 57 of file qmutokenparser.cpp.
References qmu::QmuFormulaBase::AddVariable(), qmu::QmuParserBase::Eval(), qmu::QmuFormulaBase::InitCharSets(), qmu::QmuParserBase::setAllowSubexpressions(), qmu::QmuParserBase::SetExpr(), qmu::QmuFormulaBase::SetSepForTr(), and qmu::QmuParserBase::SetVarFactory().
|
virtual |
Definition at line 72 of file qmutokenparser.cpp.
|
private |
Definition at line 35 of file qmutokenparser.cpp.
References qmu::QmuFormulaBase::InitCharSets(), and qmu::QmuParserBase::setAllowSubexpressions().
Referenced by IsSingle().
|
static |
IsSingle test formula and return true if it contain only one number.
Work only with expressions in internal (C) locale.
formula | expression for test |
Definition at line 84 of file qmutokenparser.cpp.
References qmu::QmuFormulaBase::AddVariable(), QmuTokenParser(), and qmu::QmuFormulaBase::RemoveAll().
Referenced by VMeasurements::ClearForExport(), VAbstractSpline::CorrectedSpline(), PatternPieceTool::FindGrainlineGeometry(), PatternPieceTool::FindLabelGeometry(), VSplinePoint::IsMovable(), VToolSpline::IsMovable(), VToolSpline::refreshCtrlPoints(), VToolSplinePath::refreshCtrlPoints(), VSplinePointData::VSplinePointData(), VToolSpline::VToolSpline(), and VToolSplinePath::VToolSplinePath().