File indexing completed on 2024-05-12 15:26:59
0001 /*************************************************************************** 0002 File : ExpressionParser.h 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 Copyright : (C) 2014 Alexander Semke (alexander.semke@web.de) 0006 Copyright : (C) 2020 Stefan Gerlach (stefan.gerlach@uni.kn) 0007 Description : c++ wrapper for the bison generated parser. 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU General Public License as published by * 0015 * the Free Software Foundation; either version 2 of the License, or * 0016 * (at your option) any later version. * 0017 * * 0018 * This program is distributed in the hope that it will be useful, * 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0021 * GNU General Public License for more details. * 0022 * * 0023 * You should have received a copy of the GNU General Public License * 0024 * along with this program; if not, write to the Free Software * 0025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0026 * Boston, MA 02110-1301 USA * 0027 * * 0028 ***************************************************************************/ 0029 0030 #ifndef EXPRESSIONPARSER_H 0031 #define EXPRESSIONPARSER_H 0032 0033 #include "backend/lib/Range.h" 0034 #include "backend/worksheet/plots/cartesian/XYEquationCurve.h" 0035 #include <QVector> 0036 0037 class QStringList; 0038 0039 class ExpressionParser { 0040 0041 public: 0042 static ExpressionParser* getInstance(); 0043 static int functionArgumentCount(const QString& functionName); 0044 static QString functionArgumentString(const QString& functionName, const XYEquationCurve::EquationType); 0045 0046 bool isValid(const QString& expr, const QStringList& vars); 0047 QStringList getParameter(const QString& expr, const QStringList& vars); 0048 bool evaluateCartesian( const QString& expr, const QString& min, const QString& max, 0049 int count, QVector<double>* xVector, QVector<double>* yVector, 0050 const QStringList& paramNames, const QVector<double>& paramValues); 0051 bool evaluateCartesian(const QString& expr, const QString& min, const QString& max, 0052 int count, QVector<double>* xVector, QVector<double>* yVector); 0053 bool evaluateCartesian(const QString& expr, QVector<double>* xVector, QVector<double>* yVector); 0054 bool evaluateCartesian(const QString& expr, QVector<double>* xVector, QVector<double>* yVector, 0055 const QStringList& paramNames, const QVector<double>& paramValues); 0056 bool evaluateCartesian(const QString& expr, const QStringList& vars, const QVector<QVector<double>*>& xVectors, QVector<double>* yVector); 0057 bool evaluatePolar(const QString& expr, const QString& min, const QString& max, 0058 int count, QVector<double>* xVector, QVector<double>* yVector); 0059 bool evaluateParametric(const QString& expr1, const QString& expr2, const QString& min, const QString& max, 0060 int count, QVector<double>* xVector, QVector<double>* yVector); 0061 0062 const QStringList& functions(); 0063 const QStringList& functionsGroups(); 0064 const QStringList& functionsNames(); 0065 const QVector<int>& functionsGroupIndices(); 0066 0067 const QStringList& constants(); 0068 const QStringList& constantsGroups(); 0069 const QStringList& constantsNames(); 0070 const QStringList& constantsValues(); 0071 const QStringList& constantsUnits(); 0072 const QVector<int>& constantsGroupIndices(); 0073 0074 private: 0075 ExpressionParser(); 0076 ~ExpressionParser(); 0077 0078 void initFunctions(); 0079 void initConstants(); 0080 0081 static ExpressionParser* m_instance; 0082 0083 QStringList m_functions; 0084 QStringList m_functionsGroups; 0085 QStringList m_functionsNames; 0086 QVector<int> m_functionsGroupIndex; 0087 0088 QStringList m_constants; 0089 QStringList m_constantsGroups; 0090 QStringList m_constantsNames; 0091 QStringList m_constantsValues; 0092 QStringList m_constantsUnits; 0093 QVector<int> m_constantsGroupIndex; 0094 }; 0095 #endif