muParserScript.h

Go to the documentation of this file.
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 <muParser.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>", bool checkMultilineCode = true);
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 col(const QString &arg);
00063     double tablecol(const QString &arg);
00064     double cell(int row, int col);
00065     double tableCell(int col, int row);
00066     double *addVariable(const char *name);
00067     double *addVariableR(const char *name);
00068     static double *mu_addVariableR(const char *name) { return current->addVariableR(name); }
00069     static double mu_col(const char *arg) { return current->col(arg); }
00070     static double mu_cell(double row, double col) { return current->cell(qRound(row), qRound(col)); }
00071     static double mu_tableCell(double col, double row) { return current->tableCell(qRound(col), qRound(row)); }
00072     static double mu_tablecol(const char *arg) { return current->tablecol(arg); }
00073     static double *mu_addVariable(const char *name, void *){ return current->addVariable(name); }
00074     static double *mu_addVariableR(const char *name, void *) { return current->addVariableR(name); }
00075     static QString compileColArg(const QString& in);
00076 
00077     mu::Parser parser, rparser;
00078     Q3AsciiDict<double> variables, rvariables;
00079     QStringList muCode;
00081     bool d_warn_multiline_code;
00082 
00083   public:
00084     static muParserScript *current;
00085 };
00086 
00087 #endif

Generated on Fri Nov 7 03:36:51 2008 for QtiPlot by  doxygen 1.5.6