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