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

Generated on Sun Jun 15 21:32:16 2008 for QtiPlot by  doxygen 1.5.6