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

better error checking

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