QtiPlot  0.9.8.2
muParserScript.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : muParserScript.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5 
6  Copyright : (C) 2006 by Ion Vasilief, Knut Franke
7  Email (use @ for *) : ion_vasilief*yahoo.fr, knut.franke*gmx.de
8  Description : Evaluate mathematical expressions using muParser
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the Free Software *
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27  * Boston, MA 02110-1301 USA *
28  * *
29  ***************************************************************************/
30 #ifndef MUPARSER_SCRIPT_H
31 #define MUPARSER_SCRIPT_H
32 
33 #include "ScriptingEnv.h"
34 #include "Script.h"
35 
36 #include <MyParser.h>
37 #include "math.h"
38 #include <gsl/gsl_sf.h>
39 #include <q3asciidict.h>
40 
42 class muParserScript: public Script
43 {
44  Q_OBJECT
45 
46  public:
47  muParserScript(ScriptingEnv *env, const QString &code, QObject *context=0, const QString &name="<input>");
48 
49  public slots:
50  bool compile(bool asFunction=true);
51  QVariant eval();
52  double evalSingleLine();
53  QString evalSingleLineToString(const QLocale& locale, char f, int prec);
54  bool exec();
55  bool setQObject(QObject *val, const char *name);
56  bool setInt(int val, const char* name);
57  bool setDouble(double val, const char* name);
58  double* defineVariable(const char *name, double val = 0.0);
59  int codeLines(){return muCode.size();};
60 
61  private:
62  double avg(const QString &arg, int start = 0, int end = -1);
63  double sum(const QString &arg, int start = 0, int end = -1);
64  double min(const QString &arg, int start = 0, int end = -1);
65  double max(const QString &arg, int start = 0, int end = -1);
66  double col(const QString &arg);
67  double tablecol(const QString &arg);
68  double cell(int row, int col);
69  double tableCell(int col, int row);
70  double *addVariable(const char *name);
71  double *addVariableR(const char *name);
72  static double *mu_addVariableR(const char *name) { return current->addVariableR(name); }
73  static double mu_avg(const char *arg, double start = 1, double end = -1) {return current->avg(arg, qRound(start - 1), qRound(end - 1));}
74  static double mu_sum(const char *arg, double start = 1, double end = -1) {return current->sum(arg, qRound(start - 1), qRound(end - 1));}
75  static double mu_min(const char *arg, double start = 1, double end = -1) {return current->min(arg, qRound(start - 1), qRound(end - 1));}
76  static double mu_max(const char *arg, double start = 1, double end = -1) {return current->max(arg, qRound(start - 1), qRound(end - 1));}
77  static double mu_col(const char *arg) { return current->col(arg); }
78  static double mu_cell(double row, double col) { return current->cell(qRound(row), qRound(col)); }
79  static double mu_tableCell(double col, double row) { return current->tableCell(qRound(col), qRound(row)); }
80  static double mu_tablecol(const char *arg) { return current->tablecol(arg); }
81  static double *mu_addVariable(const char *name, void *){ return current->addVariable(name); }
82  static double *mu_addVariableR(const char *name, void *) { return current->addVariableR(name); }
83  static QString compileColArg(const QString& in);
84 
86  Q3AsciiDict<double> variables, rvariables;
87  QStringList muCode;
88 
89  public:
91 };
92 
93 #endif
static double mu_sum(const char *arg, double start=1, double end=-1)
Definition: muParserScript.h:74
muParserScript(ScriptingEnv *env, const QString &code, QObject *context=0, const QString &name="<input>")
Definition: muParserScript.cpp:44
double sum(const QString &arg, int start=0, int end=-1)
Definition: muParserScript.cpp:483
QVariant eval()
Definition: muParserScript.cpp:444
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
double max(const QString &arg, int start=0, int end=-1)
Definition: muParserScript.cpp:525
Q3AsciiDict< double > variables
Definition: muParserScript.h:86
const QString code() const
Return the code that will be executed when calling exec() or eval()
Definition: Script.h:61
double min(const QString &arg, int start=0, int end=-1)
Definition: muParserScript.cpp:511
static muParserScript * current
Definition: muParserScript.h:90
static double * mu_addVariableR(const char *name, void *)
Definition: muParserScript.h:82
TODO.
Definition: muParserScript.h:42
double cell(int row, int col)
Definition: muParserScript.cpp:194
const QString name() const
Like QObject::name, but with unicode support.
Definition: Script.h:65
bool compile(bool asFunction=true)
Definition: muParserScript.cpp:349
double col(const QString &arg)
Definition: muParserScript.cpp:76
static double mu_min(const char *arg, double start=1, double end=-1)
Definition: muParserScript.h:75
static double mu_tableCell(double col, double row)
Definition: muParserScript.h:79
A chunk of scripting code. Abstract.
Definition: Script.h:50
double * addVariable(const char *name)
Definition: muParserScript.cpp:228
QObject * context() const
Return the context in which the code is to be executed.
Definition: Script.h:63
static double mu_cell(double row, double col)
Definition: muParserScript.h:78
static QString compileColArg(const QString &in)
Definition: muParserScript.cpp:309
QString evalSingleLineToString(const QLocale &locale, char f, int prec)
Definition: muParserScript.cpp:416
Q3AsciiDict< double > rvariables
Definition: muParserScript.h:86
bool setDouble(double val, const char *name)
Definition: muParserScript.cpp:274
static double mu_tablecol(const char *arg)
Definition: muParserScript.h:80
double * addVariableR(const char *name)
Definition: muParserScript.cpp:239
static double mu_col(const char *arg)
Definition: muParserScript.h:77
QStringList muCode
Definition: muParserScript.h:87
static double mu_avg(const char *arg, double start=1, double end=-1)
Definition: muParserScript.h:73
double * defineVariable(const char *name, double val=0.0)
Definition: muParserScript.cpp:249
static double mu_max(const char *arg, double start=1, double end=-1)
Definition: muParserScript.h:76
bool exec()
Definition: muParserScript.cpp:464
double evalSingleLine()
Definition: muParserScript.cpp:429
Mathematical parser class based on muParser.
Definition: MyParser.h:47
MyParser rparser
Definition: muParserScript.h:85
double avg(const QString &arg, int start=0, int end=-1)
Definition: muParserScript.cpp:497
double tableCell(int col, int row)
Definition: muParserScript.cpp:211
int codeLines()
Definition: muParserScript.h:59
MyParser parser
Definition: muParserScript.h:85
static double * mu_addVariableR(const char *name)
Definition: muParserScript.h:72
bool setInt(int val, const char *name)
Definition: muParserScript.cpp:299
static double * mu_addVariable(const char *name, void *)
Definition: muParserScript.h:81
bool setQObject(QObject *val, const char *name)
Definition: muParserScript.cpp:304
double tablecol(const QString &arg)
Definition: muParserScript.cpp:133