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

Generated by  doxygen 1.6.2