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