muParserScripting.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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