当前位置: 首页>>代码示例>>C++>>正文


C++ MyParser类代码示例

本文整理汇总了C++中MyParser的典型用法代码示例。如果您正苦于以下问题:C++ MyParser类的具体用法?C++ MyParser怎么用?C++ MyParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MyParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: transformValue

double ScaleDraw::transformValue(double value) const
{
    if (!formula_string.isEmpty())
    {
        double lbl=0.0;
        try
        {
            MyParser parser;
            if (formula_string.contains("x"))
                parser.DefineVar("x", &value);
            else if (formula_string.contains("y"))
                parser.DefineVar("y", &value);

            parser.SetExpr(formula_string.ascii());
            lbl=parser.Eval();
        }
        catch(mu::ParserError &)
        {
            return 0;
        }

        return lbl;
    }
    else
        return value;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:26,代码来源:ScaleDraw.cpp

示例2: text

void DoubleSpinBox::interpretText()
{
	bool ok = false;
	QString s = text();
	double value = locale().toDouble(s, &ok);
	if (ok && value == d_value)
		return;

	if (!ok){
		MyParser parser;
		parser.setLocale(QLocale());
		parser.addGSLConstants();
		try {
			parser.SetExpr(s.toAscii().constData());
			value = parser.Eval();
		} catch (mu::ParserError &e){
			lineEdit()->setText(textFromValue(d_value));
			return;
		}
	}

	if (setValue(value))
        emit valueChanged(d_value);
    else
        lineEdit()->setText(textFromValue(d_value));
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:26,代码来源:DoubleSpinBox.cpp

示例3: Filter

Integration::Integration(const QString& formula, const QString& var, ApplicationWindow *parent, Graph *g, double start, double end)
: Filter(parent, g),
d_formula(formula),
d_variable(var)
{
	d_init_err = false;
	d_n = 0;
	d_from = start;
	d_to = end;
	if (d_to == d_from)
		d_init_err = true;

	MyParser parser;
	double x = 0.0;
	parser.DefineVar(d_variable.ascii(), &x);
	parser.SetExpr(d_formula.ascii());
	try {
		parser.Eval();
	} catch(mu::ParserError &e) {
		QMessageBox::critical(parent, tr("QtiPlot - Input error"), QString::fromStdString(e.GetMsg()));
		d_init_err = true;
	}

	setObjectName(tr("Integration"));
	d_integrand = AnalyticalFunction;
	d_method = 1;
    d_max_iterations = 20;
    d_sort_data = false;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:29,代码来源:Integration.cpp

示例4: valid

/** Checks to see if this axis has valid parameters
*
*/
bool AxisDetails::valid()
{
  if (m_cmbAxisType->currentIndex() == ScaleDraw::Numeric)
  {
    if (m_chkShowFormula->isChecked())
    {
      QString formula = m_txtFormula->text().lower();
      try
      {
        double value = 1.0;
        MyParser parser;
        if (formula.contains("x"))
        {
          parser.DefineVar("x", &value);
        }
        else if (formula.contains("y"))
        {
          parser.DefineVar("y", &value);
        }
        parser.SetExpr(formula.ascii());
        parser.Eval();
      }
      catch(mu::ParserError &e)
      {
        QMessageBox::critical(this, tr("MantidPlot - Formula input error"), QString::fromStdString(e.GetMsg())+"\n"+tr("Valid variables are 'x' for Top/Bottom axes and 'y' for Left/Right axes!"));
        return false;
      }
    }
  }
  Table *w = m_app->table(m_cmbColName->currentText());
  return m_initialised && m_graph && !((m_cmbAxisType->currentIndex() == ScaleDraw::Text || m_cmbAxisType->currentIndex() == ScaleDraw::ColHeader) && !w);
}
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:35,代码来源:AxisDetails.cpp

示例5: main

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MyParser b;
    b.start();

//    return a.exec();
}
开发者ID:01iv3r,项目名称:OpenPilot,代码行数:8,代码来源:main.cpp

示例6: calculateFitCurveData

void NonLinearFit::calculateFitCurveData(double *X, double *Y)
{
	MyParser parser;
	for (int i=0; i<d_p; i++)
		parser.DefineVar(d_param_names[i].ascii(), &d_results[i]);

	QMapIterator<QString, double> i(d_constants);
 	while (i.hasNext()) {
     	i.next();
		parser.DefineConst(i.key().ascii(), i.value());
 	}

	double x;
	parser.DefineVar("x", &x);
	parser.SetExpr(d_formula.ascii());

	if (d_gen_function){
		double X0 = d_x[0];
		double step = (d_x[d_n - 1] - X0)/(d_points - 1);
		for (int i=0; i<d_points; i++){
		    x = X0 + i*step;
			X[i] = x;
			Y[i] = parser.EvalRemoveSingularity(&x, false);
		}
	} else {
		for (int i=0; i<d_points; i++) {
		    x = d_x[i];
			X[i] = x;
			Y[i] = parser.EvalRemoveSingularity(&x, false);
		}
	}
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:32,代码来源:NonLinearFit.cpp

示例7: catch

double UserFunction2D::operator()(double x, double y) {
  if (d_formula.isEmpty())
    return 0.0;

  MyParser parser;
  double result = 0.0;
  try {
    parser.DefineVar("x", &x);
    parser.DefineVar("y", &y);

    parser.SetExpr((const std::string)d_formula.toAscii().constData());
    result = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(nullptr, "MantidPlot - Input function error",
                          QString::fromStdString(e.GetMsg()));
  }
  return result;
}
开发者ID:DanNixon,项目名称:mantid,代码行数:18,代码来源:UserFunction.cpp

示例8: transformValue

double ScaleDraw::transformValue(double value) const
{
	if (!d_formula.isEmpty()){
		double lbl=0.0;
		try{
			MyParser parser;
			if (d_formula.contains("x", Qt::CaseInsensitive))
				parser.DefineVar("x", &value);
			else if (d_formula.contains("y", Qt::CaseInsensitive))
				parser.DefineVar("y", &value);

			parser.SetExpr(d_formula.lower().ascii());
			lbl = parser.Eval();
        }
        catch(mu::ParserError &){
			return 0;
        }
		return lbl;
    } else
        return value;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:21,代码来源:ScaleDraw.cpp

示例9: trapezf

double Integration::trapezf(int n)
{
    MyParser parser;
	double x = d_from;
	parser.DefineVar(d_variable.ascii(), &x);
	parser.SetExpr(d_formula.ascii());

    static double s;
    if (n == 1){
		x = d_from;
		double aux = parser.Eval();
		x = d_to;
        return (s = 0.5*(d_to - d_from)*(aux + parser.Eval()));
    } else {
        int it = 1;
        for(int j=1; j < n-1; j++)
            it<<=1;

        double tnm = it;
        double del = (d_to - d_from)/tnm;
        x = d_from + 0.5*del;
        double sum = 0.0;
        for(int j=1; j <= it; j++, x += del)
            sum += parser.Eval();

        s = 0.5*(s + (d_to - d_from)*sum/tnm);
        return s;
    }
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:29,代码来源:Integration.cpp

示例10: gsl_vector_get

void NonLinearFit::removeDataSingularities()
{
	MyParser parser;
	for (int i = 0; i < d_p; i++){
		double param = gsl_vector_get(d_param_init, i);
		parser.DefineVar(d_param_names[i].ascii(), &param);
	}

	QMapIterator<QString, double> it(d_constants);
 	while (it.hasNext()) {
     	it.next();
		parser.DefineConst(it.key().ascii(), it.value());
 	}

	double xvar;
	parser.DefineVar("x", &xvar);
	parser.SetExpr(d_formula.ascii());

    for (int i = 0; i < d_n; i++){
    	xvar = d_x[i];
    	try {
			parser.EvalRemoveSingularity(&xvar);
    	} catch(MyParser::Pole){
			QApplication::restoreOverrideCursor();
			QMessageBox::critical((ApplicationWindow *)parent(), QObject::tr("QtiPlot"),
			QObject::tr("Ignored data point at x = %1.").arg(xvar));

    		removePole(i);
    	}
    }
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:31,代码来源:NonLinearFit.cpp

示例11: tr

bool NonLinearFit::setFormula(const QString& s, bool guess)
{
	if (s.isEmpty()){
		QMessageBox::critical((ApplicationWindow *)parent(),  tr("QtiPlot - Input function error"),
				tr("Please enter a valid non-empty expression! Operation aborted!"));
		d_init_err = true;
		return false;
	}

	if (d_formula == s)
		return true;

	if (guess)
		setParametersList(guessParameters(s));
	if (!d_p){
		QMessageBox::critical((ApplicationWindow *)parent(), tr("QtiPlot - Fit Error"),
				tr("There are no parameters specified for this fit operation. Please define a list of parameters first!"));
		d_init_err = true;
		return false;
	}

	try {
		double *param = new double[d_p];
		MyParser parser;
		double xvar;
		parser.DefineVar("x", &xvar);
		for (int k = 0; k < (int)d_p; k++){
			param[k] = gsl_vector_get(d_param_init, k);
			parser.DefineVar(d_param_names[k].ascii(), &param[k]);
		}

		QMapIterator<QString, double> i(d_constants);
 		while (i.hasNext()) {
     		i.next();
			parser.DefineConst(i.key().ascii(), i.value());
 		}

		parser.SetExpr(s.ascii());
		parser.Eval() ;
		delete[] param;
	} catch(mu::ParserError &e){
		QMessageBox::critical((ApplicationWindow *)parent(),  tr("QtiPlot - Input function error"), QString::fromStdString(e.GetMsg()));
		d_init_err = true;
		return false;
	}

	d_init_err = false;
	d_formula = s;
	return true;
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:50,代码来源:NonLinearFit.cpp

示例12: eval

double NonLinearFit::eval(double *par, double x)
{
	MyParser parser;
	for (int i=0; i<d_p; i++)
		parser.DefineVar(d_param_names[i].ascii(), &par[i]);

	QMapIterator<QString, double> i(d_constants);
 	while (i.hasNext()) {
     	i.next();
		parser.DefineConst(i.key().ascii(), i.value());
 	}

	parser.DefineVar("x", &x);
	parser.SetExpr(d_formula.ascii());
    return parser.EvalRemoveSingularity(&x, false);
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:16,代码来源:NonLinearFit.cpp

示例13: user_d

double user_d(const gsl_vector * x, void *params) {
    int n = ((struct FitData *)params)->n;
    int p = ((struct FitData *)params)->p;
    double *X = ((struct FitData *)params)->X;
    double *Y = ((struct FitData *)params)->Y;
    double *sigma = ((struct FitData *)params)->sigma;

	NonLinearFit *fitter = (NonLinearFit *)((struct FitData *) params)->fitter;
	const char *function = fitter->formula().ascii();
	QStringList parNames = fitter->parameterNames();

    double val=0;
    MyParser parser;
    try {
        double *parameters = new double[p];
        double xvar;
        parser.DefineVar("x", &xvar);
        for (int i=0; i < p; i++) {
            parameters[i]=gsl_vector_get(x,i);
            parser.DefineVar(parNames[i].ascii(), &parameters[i]);
        }

		QMapIterator<QString, double> i(fitter->constants());
 		while (i.hasNext()){
     		i.next();
			parser.DefineConst(i.key().ascii(), i.value());
 		}

        parser.SetExpr(function);
        for (int j = 0; j < n; j++) {
            xvar = X[j];
			double s = 1.0/sqrt(sigma[j]);
            try {
				double t = (parser.EvalRemoveSingularity(&xvar) - Y[j])/s;
				val += t*t;
			} catch (MyParser::Pole) {
				return GSL_POSINF; //weird, I know. blame gsl.
			}
        }
        delete[] parameters;
    } catch (mu::ParserError &e) {
        QMessageBox::critical(0,"QtiPlot - Input function error",QString::fromStdString(e.GetMsg()));
        return GSL_EINVAL;
    }
    return val;
}
开发者ID:kuzavas,项目名称:qtiplot,代码行数:46,代码来源:fit_gsl.cpp

示例14: user_df

int user_df(const gsl_vector *x, void *params, gsl_matrix *J) {
    int n = ((struct FitData *)params)->n;
    int p = ((struct FitData *)params)->p;
    double *X = ((struct FitData *)params)->X;
    double *sigma = ((struct FitData *)params)->sigma;

	NonLinearFit *fitter = (NonLinearFit *)((struct FitData *) params)->fitter;
	const char *function = fitter->formula().ascii();
	QStringList parNames = fitter->parameterNames();

	try {
        double *param = new double[p];
        MyParser parser;
        double xvar;
        parser.DefineVar("x", &xvar);
        for (int k=0; k<p; k++) {
            param[k] = gsl_vector_get(x,k);
            parser.DefineVar(parNames[k].ascii(), &param[k]);
        }

		QMapIterator<QString, double> i(fitter->constants());
 		while (i.hasNext()){
     		i.next();
			parser.DefineConst(i.key().ascii(), i.value());
 		}

        parser.SetExpr(function);
        for (int i = 0; i < n; i++) {
            xvar = X[i];
			double s = 1.0/sqrt(sigma[i]);
            for (int j = 0; j < p; j++)
	        try {
				gsl_matrix_set (J, i, j, 1.0/s*parser.DiffRemoveSingularity(&xvar, &param[j], param[j]));
			} catch (MyParser::Pole) {
				return GSL_ESING;
			}
        }
        delete[] param;
    } catch (mu::ParserError &) {
        return GSL_EINVAL;
    }
    return GSL_SUCCESS;
}
开发者ID:kuzavas,项目名称:qtiplot,代码行数:43,代码来源:fit_gsl.cpp

示例15: catch

void FunctionDialog::acceptPolar() {
  QString from = boxPolarFrom->text().toLower();
  QString to = boxPolarTo->text().toLower();
  QString points = boxPolarPoints->text().toLower();

  double start, end;
  try {
    MyParser parser;
    parser.SetExpr(from.toAscii().constData());
    start = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - Start limit error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarFrom->setFocus();
    return;
  }

  try {
    MyParser parser;
    parser.SetExpr(to.toAscii().constData());
    end = parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - End limit error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarTo->setFocus();
    return;
  }

  if (start >= end) {
    QMessageBox::critical(
        0, tr("MantidPlot - Input error"),
        tr("Please enter parameter limits that satisfy: from < end!"));
    boxPolarTo->setFocus();
    return;
  }

  QString rformula = boxPolarRadius->currentText();
  QString tformula = boxPolarTheta->currentText();
  bool error = false;

  try {
    MyParser parser;
    double parameter = start;
    ;
    parser.DefineVar((boxPolarParameter->text()).toAscii().constData(),
                     &parameter);
    parser.SetExpr(rformula.toAscii().constData());
    parser.Eval();
    // cppcheck-suppress unreadVariable
    parameter = end;
    parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - Input function error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarRadius->setFocus();
    error = true;
  }
  try {
    MyParser parser;
    double parameter = start;
    ;
    parser.DefineVar((boxPolarParameter->text()).toAscii().constData(),
                     &parameter);
    parser.SetExpr(tformula.toAscii().constData());
    parser.Eval();
    // cppcheck-suppress unreadVariable
    parameter = end;
    parser.Eval();
  } catch (mu::ParserError &e) {
    QMessageBox::critical(0, tr("MantidPlot - Input function error"),
                          QString::fromStdString(e.GetMsg()));
    boxPolarTheta->setFocus();
    error = true;
  }
  // Collecting all the information
  int type = boxType->currentIndex();
  QStringList formulas;
  formulas += rformula;
  formulas += tformula;
  if (!error) {
    d_app->updateFunctionLists(type, formulas);

    if (!graph)
      d_app->newFunctionPlot(formulas, start, end, boxPolarPoints->value(),
                             boxPolarParameter->text(), type);
    else {
      if (curveID >= 0)
        graph->modifyFunctionCurve(curveID, type, formulas,
                                   boxPolarParameter->text(), start, end,
                                   boxPolarPoints->value());
      else
        graph->addFunction(formulas, start, end, boxPolarPoints->value(),
                           boxPolarParameter->text(), type);
    }
  }
}
开发者ID:liyulun,项目名称:mantid,代码行数:96,代码来源:FunctionDialog.cpp


注:本文中的MyParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。