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

Generated on Mon Oct 15 06:11:42 2007 for QtiPlot by  doxygen 1.5.3