Seamly2D
Code documentation
qmu::QmuFormulaBase Class Reference

#include <qmuformulabase.h>

Inheritance diagram for qmu::QmuFormulaBase:
Collaboration diagram for qmu::QmuFormulaBase:

Public Member Functions

 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...
 
QmuParserBaseoperator= (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_typeGetUsedVar () const
 Return a map containing the used variables only. More...
 
const varmap_typeGetVar () const
 Return a map containing the used variables only. More...
 
const valmap_typeGetConst () const
 Return a map containing all parser constants. More...
 
const QString & GetExpr () const
 Retrieve the formula. More...
 
const funmap_typeGetFunDef () 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 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...
 

Protected Member Functions

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

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...
 

Additional Inherited Members

- 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
 

Detailed Description

Definition at line 36 of file qmuformulabase.h.

Constructor & Destructor Documentation

◆ QmuFormulaBase()

qmu::QmuFormulaBase::QmuFormulaBase ( )

Definition at line 37 of file qmuformulabase.cpp.

◆ ~QmuFormulaBase()

qmu::QmuFormulaBase::~QmuFormulaBase ( )
virtual

Definition at line 43 of file qmuformulabase.cpp.

Member Function Documentation

◆ AddVariable()

qreal * qmu::QmuFormulaBase::AddVariable ( const QString &  a_szName,
void *  a_pUserData 
)
staticprotected

◆ InitCharSets()

void qmu::QmuFormulaBase::InitCharSets ( )
virtual

InitCharSets init character set for parser.

QMuParser require setting character set for legal characters. Because we try make our expresion language independent we set all posible unique characters from all alphabets.

Reimplemented from qmu::QmuParser.

Definition at line 55 of file qmuformulabase.cpp.

References qmu::QmuParserBase::DefineInfixOprtChars(), qmu::QmuParserBase::DefineNameChars(), qmu::QmuParserBase::DefineOprtChars(), INIT_LOCALE_VARIABLES, and qmu::QmuParserBase::m_locale.

Referenced by Calculator::Calculator(), and qmu::QmuTokenParser::QmuTokenParser().

◆ RemoveAll()

void qmu::QmuFormulaBase::RemoveAll ( QMap< int, QString > &  map,
const QString &  val 
)
static

RemoveAll remove token from token list.

Standard Qt class QMap doesn't have method RemoveAll. Example: remove "-" from tokens list if exist. If don't do that unary minus operation will broken.

Parameters
mapmap with tokens
valtoken that need delete

Definition at line 145 of file qmuformulabase.cpp.

Referenced by Calculator::EvalFormula(), and qmu::QmuTokenParser::IsSingle().

◆ SetSepForEval()

void qmu::QmuFormulaBase::SetSepForEval ( )
protected

SetSepForEval set separators for eval. Each expression eval in internal (C) locale.

Definition at line 128 of file qmuformulabase.cpp.

References qmu::QmuParserBase::SetArgSep(), qmu::QmuParserBase::setDecimalPoint(), and qmu::QmuParserBase::setThousandsSeparator().

Referenced by Calculator::Calculator(), Calculator::EvalFormula(), and SetSepForTr().

◆ SetSepForTr()

void qmu::QmuFormulaBase::SetSepForTr ( bool  osSeparator,
bool  fromUser 
)
protected

SetSepForTr set separators for translation expression.

Parameters
fromUsertrue if expression come from user (from dialog).

Definition at line 106 of file qmuformulabase.cpp.

References qmu::QmuParserBase::SetArgSep(), qmu::QmuParserBase::setDecimalPoint(), qmu::QmuParserBase::setLocale(), SetSepForEval(), and qmu::QmuParserBase::setThousandsSeparator().

Referenced by qmu::QmuTokenParser::QmuTokenParser().


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