QtiPlot 0.9.7.3
|
00001 /*************************************************************************** 00002 File : muParserScript.h 00003 Project : QtiPlot 00004 -------------------------------------------------------------------- 00005 00006 Copyright : (C) 2006 by Ion Vasilief, Knut Franke 00007 Email (use @ for *) : ion_vasilief*yahoo.fr, knut.franke*gmx.de 00008 Description : Evaluate mathematical expressions using muParser 00009 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 * This program is distributed in the hope that it will be useful, * 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00022 * GNU General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU General Public License * 00025 * along with this program; if not, write to the Free Software * 00026 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 00027 * Boston, MA 02110-1301 USA * 00028 * * 00029 ***************************************************************************/ 00030 #ifndef MUPARSER_SCRIPT_H 00031 #define MUPARSER_SCRIPT_H 00032 00033 #include "ScriptingEnv.h" 00034 #include "Script.h" 00035 00036 #include <MyParser.h> 00037 #include "math.h" 00038 #include <gsl/gsl_sf.h> 00039 #include <q3asciidict.h> 00040 00042 class muParserScript: public Script 00043 { 00044 Q_OBJECT 00045 00046 public: 00047 muParserScript(ScriptingEnv *env, const QString &code, QObject *context=0, const QString &name="<input>"); 00048 00049 public slots: 00050 bool compile(bool asFunction=true); 00051 QVariant eval(); 00052 double evalSingleLine(); 00053 QString evalSingleLineToString(const QLocale& locale, char f, int prec); 00054 bool exec(); 00055 bool setQObject(QObject *val, const char *name); 00056 bool setInt(int val, const char* name); 00057 bool setDouble(double val, const char* name); 00058 double* defineVariable(const char *name, double val = 0.0); 00059 int codeLines(){return muCode.size();}; 00060 00061 private: 00062 double avg(const QString &arg, int start = 0, int end = -1); 00063 double sum(const QString &arg, int start = 0, int end = -1); 00064 double min(const QString &arg, int start = 0, int end = -1); 00065 double max(const QString &arg, int start = 0, int end = -1); 00066 double col(const QString &arg); 00067 double tablecol(const QString &arg); 00068 double cell(int row, int col); 00069 double tableCell(int col, int row); 00070 double *addVariable(const char *name); 00071 double *addVariableR(const char *name); 00072 static double *mu_addVariableR(const char *name) { return current->addVariableR(name); } 00073 static double mu_avg(const char *arg, double start = 1, double end = -1) {return current->avg(arg, qRound(start - 1), qRound(end - 1));} 00074 static double mu_sum(const char *arg, double start = 1, double end = -1) {return current->sum(arg, qRound(start - 1), qRound(end - 1));} 00075 static double mu_min(const char *arg, double start = 1, double end = -1) {return current->min(arg, qRound(start - 1), qRound(end - 1));} 00076 static double mu_max(const char *arg, double start = 1, double end = -1) {return current->max(arg, qRound(start - 1), qRound(end - 1));} 00077 static double mu_col(const char *arg) { return current->col(arg); } 00078 static double mu_cell(double row, double col) { return current->cell(qRound(row), qRound(col)); } 00079 static double mu_tableCell(double col, double row) { return current->tableCell(qRound(col), qRound(row)); } 00080 static double mu_tablecol(const char *arg) { return current->tablecol(arg); } 00081 static double *mu_addVariable(const char *name, void *){ return current->addVariable(name); } 00082 static double *mu_addVariableR(const char *name, void *) { return current->addVariableR(name); } 00083 static QString compileColArg(const QString& in); 00084 00085 MyParser parser, rparser; 00086 Q3AsciiDict<double> variables, rvariables; 00087 QStringList muCode; 00088 00089 public: 00090 static muParserScript *current; 00091 }; 00092 00093 #endif