Skip to content
Snippets Groups Projects
Commit 0cc87016 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

better error checking

parent b9c66639
Branches
Tags
No related merge requests found
......@@ -8,8 +8,10 @@
#if defined(HAVE_MATHEX)
mathEvaluator::mathEvaluator(std::vector<std::string> &expressions,
std::vector<std::string> &variables)
const std::vector<std::string> &variables)
{
static std::string lastError;
_expressions.resize(expressions.size());
_variables.resize(variables.size(), 0.);
bool error = false;
......@@ -22,11 +24,14 @@ mathEvaluator::mathEvaluator(std::vector<std::string> &expressions,
_expressions[i]->parse();
}
catch(smlib::mathex::error e) {
Msg::Error(e.what());
std::string pos(_expressions[i]->stopposition(), ' ');
pos.push_back('^');
Msg::Error(expressions[i].c_str());
Msg::Error(pos.c_str());
if(e.what() + expressions[i] != lastError){
lastError = e.what() + expressions[i];
Msg::Error(e.what());
std::string pos(_expressions[i]->stopposition(), ' ');
pos.push_back('^');
Msg::Error(expressions[i].c_str());
Msg::Error(pos.c_str());
}
error = true;
}
}
......@@ -34,6 +39,7 @@ mathEvaluator::mathEvaluator(std::vector<std::string> &expressions,
for(unsigned int i = 0; i < _expressions.size(); i++)
delete(_expressions[i]);
_expressions.clear();
expressions.clear();
}
}
......@@ -43,7 +49,7 @@ mathEvaluator::~mathEvaluator()
delete(_expressions[i]);
}
bool mathEvaluator::eval(std::vector<double> &values, std::vector<double> &res)
bool mathEvaluator::eval(const std::vector<double> &values, std::vector<double> &res)
{
if(values.size() != _variables.size()){
Msg::Error("Given %d value(s) for %d variable(s)", values.size(), _variables.size());
......
......@@ -24,11 +24,11 @@ class mathEvaluator{
// variables. If an error occurs the vector of expressions is
// cleared.
mathEvaluator(std::vector<std::string> &expressions,
std::vector<std::string> &variables);
const std::vector<std::string> &variables);
~mathEvaluator();
// evaluate the expression(s) using the given values and fill the
// result vector. Returns true if the evaluation succeeded.
bool eval(std::vector<double> &values, std::vector<double> &res);
bool eval(const std::vector<double> &values, std::vector<double> &res);
};
#else
......@@ -36,14 +36,14 @@ class mathEvaluator{
class mathEvaluator{
public:
mathEvaluator(std::vector<std::string> &expressions,
std::vector<std::string> &variables)
const std::vector<std::string> &variables)
{
Msg::Error("Gmsh must be compiled with MathEx support to evaluate math "
"expressions");
expressions.clear();
}
~mathEvaluator(){}
bool eval(std::vector<double> &values, std::vector<double> &res)
bool eval(const std::vector<double> &values, std::vector<double> &res)
{
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment