muParserScripting.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : muParserScripting.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_SCRIPTING_H
00034 #define MUPARSER_SCRIPTING_H
00035 
00036 #include "ScriptingEnv.h"
00037 #include "Script.h"
00038 #include "muParserScript.h"
00039 
00040 #include <muParser.h>
00041 #include "math.h"
00042 #include <gsl/gsl_sf.h>
00043 #include <q3asciidict.h>
00044 
00046 class muParserScripting: public ScriptingEnv
00047 {
00048   Q_OBJECT
00049 
00050   public:
00051     static const char *langName;
00052     muParserScripting(ApplicationWindow *parent) : ScriptingEnv(parent, langName) { d_initialized=true; }
00053     static ScriptingEnv *constructor(ApplicationWindow *parent) { return new muParserScripting(parent); }
00054 
00055     bool isRunning() const { return true; }
00056     Script *newScript(const QString &code, QObject *context, const QString &name="<input>")
00057     {
00058       return new muParserScript(this, code, context, name);
00059     }
00060 
00061     // we do not support global variables
00062     bool setQObject(QObject*, const char*) { return false; }
00063     bool setInt(int, const char*) { return false; }
00064     bool setDouble(double, const char*) { return false; }
00065     
00066     const QStringList mathFunctions() const;
00067     const QString mathFunctionDoc (const QString &name) const;
00068 
00069     struct mathFunction
00070     {
00071       char *name;
00072       int numargs;
00073       double (*fun1)(double);
00074       double (*fun2)(double,double);
00075       double (*fun3)(double,double,double);
00076       char *description;
00077     };
00078     static const mathFunction math_functions[];
00079 
00080   private:
00081     static double ceil(double x)
00082       { return ceil(x); }
00083     static double floor(double x)
00084       { return floor(x); }
00085     static double mod(double x, double y)
00086       { return fmod(x,y); }
00087     static double mypow(double x, double y)
00088       { return pow(x,y); }
00089     static double bessel_J0(double x)
00090       { return gsl_sf_bessel_J0 (x); }
00091     static double bessel_J1(double x)
00092       { return gsl_sf_bessel_J1 (x); }
00093     static double bessel_Jn(double x, double n)
00094       { return gsl_sf_bessel_Jn ((int)n, x); }
00095     static double bessel_Yn(double x, double n)
00096       { return gsl_sf_bessel_Yn ((int)n, x); }
00097     static double bessel_Jn_zero(double n, double s)
00098       { return gsl_sf_bessel_zero_Jnu(n, (unsigned int) s); }
00099     static double bessel_Y0(double x)
00100       { return gsl_sf_bessel_Y0 (x); }
00101     static double bessel_Y1(double x)
00102       { return gsl_sf_bessel_Y1 (x); }
00103     static double beta(double a, double b)
00104       { return gsl_sf_beta (a,b); }
00105     static double erf(double x)
00106       { return gsl_sf_erf (x); }
00107     static double erfc(double x)
00108       { return gsl_sf_erfc (x); }
00109     static double erf_Z(double x)
00110       { return gsl_sf_erf_Z (x); }
00111     static double erf_Q(double x)
00112       { return gsl_sf_erf_Q (x); }
00113     static double gamma(double x)
00114       { return gsl_sf_gamma (x); }
00115     static double lngamma(double x)
00116       { return gsl_sf_lngamma (x); }
00117     static double hazard(double x)
00118       { return gsl_sf_hazard (x); }
00119      static double lambert_W0(double x)
00120        { return gsl_sf_lambert_W0(x); }
00121      static double lambert_Wm1(double x)
00122        { return gsl_sf_lambert_Wm1(x); }
00123 };
00124 
00125 class EmptySourceError : public mu::ParserError
00126 {
00127     public:
00128         EmptySourceError() {}
00129 };
00130 
00131 #endif

Generated on Thu Feb 7 13:59:27 2008 for QtiPlot by  doxygen 1.5.4