2014-04-25 14:58:14 +02:00
|
|
|
/***************************************************************************************************
|
|
|
|
**
|
2015-02-27 11:21:09 +01:00
|
|
|
** Copyright (C) 2013 Ingo Berg
|
2014-04-25 14:58:14 +02:00
|
|
|
**
|
|
|
|
** Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
** software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
** without restriction, including without limitation the rights to use, copy, modify,
|
|
|
|
** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
** permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
**
|
|
|
|
** The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
** substantial portions of the Software.
|
|
|
|
**
|
|
|
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
|
|
** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
**
|
|
|
|
******************************************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QMUPARSER_H
|
|
|
|
#define QMUPARSER_H
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <qcompilerdetection.h>
|
|
|
|
#include <QString>
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <locale>
|
|
|
|
|
2014-04-25 14:58:14 +02:00
|
|
|
#include "qmuparser_global.h"
|
|
|
|
#include "qmuparserbase.h"
|
|
|
|
|
2014-04-30 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Definition of the standard floating point parser.
|
|
|
|
*/
|
2014-04-25 14:58:14 +02:00
|
|
|
|
|
|
|
namespace qmu
|
|
|
|
{
|
2014-04-30 07:32:29 +02:00
|
|
|
/** @brief Mathematical expressions parser.
|
|
|
|
*
|
|
|
|
* Standard implementation of the mathematical expressions parser.
|
|
|
|
* Can be used as a reference implementation for subclassing the parser.
|
|
|
|
*
|
|
|
|
* <small>
|
|
|
|
* (C) 2011 Ingo Berg<br>
|
|
|
|
* muparser(at)gmx.de
|
|
|
|
* </small>
|
|
|
|
*/
|
|
|
|
/* final */ class QMUPARSERSHARED_EXPORT QmuParser : public QmuParserBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmuParser();
|
2015-07-03 15:36:54 +02:00
|
|
|
virtual void InitCharSets() Q_DECL_OVERRIDE;
|
|
|
|
virtual void InitFun() Q_DECL_OVERRIDE;
|
|
|
|
virtual void InitConst() Q_DECL_OVERRIDE;
|
|
|
|
virtual void InitOprt() Q_DECL_OVERRIDE;
|
|
|
|
virtual void OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) Q_DECL_OVERRIDE;
|
2014-04-30 07:32:29 +02:00
|
|
|
qreal Diff(qreal *a_Var, qreal a_fPos, qreal a_fEpsilon = 0) const;
|
|
|
|
protected:
|
2017-01-03 10:14:32 +01:00
|
|
|
static int IsVal(const QString &a_szExpr, int *a_iPos, qreal *a_fVal, const QLocale &locale,
|
|
|
|
const QChar &decimal, const QChar &thousand);
|
2014-04-30 07:32:29 +02:00
|
|
|
// hyperbolic functions
|
|
|
|
static qreal Sinh(qreal);
|
|
|
|
static qreal Cosh(qreal);
|
|
|
|
static qreal Tanh(qreal);
|
|
|
|
// arcus hyperbolic functions
|
|
|
|
static qreal ASinh(qreal);
|
|
|
|
static qreal ACosh(qreal);
|
|
|
|
static qreal ATanh(qreal);
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
// functions working with degrees
|
|
|
|
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);
|
|
|
|
|
2014-04-30 07:32:29 +02:00
|
|
|
// Logarithm functions
|
|
|
|
static qreal Log2(qreal); // Logarithm Base 2
|
|
|
|
static qreal Log10(qreal); // Logarithm Base 10
|
|
|
|
// misc
|
|
|
|
static qreal Abs(qreal);
|
|
|
|
static qreal Rint(qreal);
|
2017-09-29 16:47:11 +02:00
|
|
|
static qreal R2CM(qreal);
|
2017-11-13 09:53:27 +01:00
|
|
|
static qreal CSRCm(qreal length, qreal split, qreal arcLength);
|
|
|
|
static qreal CSRInch(qreal length, qreal split, qreal arcLength);
|
2014-04-30 07:32:29 +02:00
|
|
|
static qreal Sign(qreal);
|
2015-05-14 18:19:23 +02:00
|
|
|
static qreal FMod(qreal, qreal);
|
2014-04-30 07:32:29 +02:00
|
|
|
// Prefix operators
|
|
|
|
// !!! Unary Minus is a MUST if you want to use negative signs !!!
|
2014-05-22 14:11:14 +02:00
|
|
|
static qreal UnaryMinus(qreal v);
|
2014-04-30 07:32:29 +02:00
|
|
|
// Functions with variable number of arguments
|
|
|
|
static qreal Sum(const qreal*, int); // sum
|
|
|
|
static qreal Avg(const qreal*, int); // mean value
|
|
|
|
static qreal Min(const qreal*, int); // minimum
|
|
|
|
static qreal Max(const qreal*, int); // maximum
|
2014-05-16 19:00:13 +02:00
|
|
|
};
|
2014-05-06 16:36:42 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief Callback for the unary minus operator.
|
|
|
|
* @param v The value to negate
|
|
|
|
* @return -v
|
|
|
|
*/
|
2014-05-22 14:11:14 +02:00
|
|
|
inline qreal QmuParser::UnaryMinus(qreal v)
|
2014-05-06 16:36:42 +02:00
|
|
|
{
|
|
|
|
return -v;
|
|
|
|
}
|
2014-04-25 14:58:14 +02:00
|
|
|
|
|
|
|
} // namespace qmu
|
|
|
|
|
|
|
|
#endif // QMUPARSER_H
|