Skip to content
Snippets Groups Projects
Commit 887c3c58 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

Field : add generic templated Action callback

parent 4f569dc0
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,22 @@ ...@@ -35,6 +35,22 @@
#include "ANN/ANN.h" #include "ANN/ANN.h"
#endif #endif
template<class t>
class FieldCallbackGeneric : public FieldCallback {
t * _field;
void (t::*_callback)();
public :
void run()
{
(_field->*_callback)();
}
FieldCallbackGeneric( t *field, void (t::*callback)(), const std::string description) : FieldCallback(description)
{
_field = field;
_callback = callback;
}
};
Field::~Field() Field::~Field()
{ {
for(std::map<std::string, FieldOption*>::iterator it = options.begin(); for(std::map<std::string, FieldOption*>::iterator it = options.begin();
...@@ -1019,13 +1035,15 @@ class MathEvalField : public Field ...@@ -1019,13 +1035,15 @@ class MathEvalField : public Field
} }
}; };
public: public:
void myAction(){
printf("doing sthg \n");
}
MathEvalField() MathEvalField()
{ {
options["F"] = new FieldOptionString options["F"] = new FieldOptionString
(f, "Mathematical function to evaluate.", &update_needed); (f, "Mathematical function to evaluate.", &update_needed);
f = "F2 + Sin(z)"; f = "F2 + Sin(z)";
callbacks["test"] = new testAction(this, "description blabla \n"); callbacks["test"] = new FieldCallbackGeneric<MathEvalField>(this, &MathEvalField::myAction, "description blabla");
//callbacks["test"] = new FieldCallbackGeneric<MathEvalField>(this, MathEvalField::myFunc, "description")
} }
double operator() (double x, double y, double z, GEntity *ge=0) double operator() (double x, double y, double z, GEntity *ge=0)
{ {
...@@ -1037,9 +1055,6 @@ class MathEvalField : public Field ...@@ -1037,9 +1055,6 @@ class MathEvalField : public Field
} }
return expr.evaluate(x, y, z); return expr.evaluate(x, y, z);
} }
void myAction(){
printf("doing sthg \n");
}
const char *getName() const char *getName()
{ {
return "MathEval"; return "MathEval";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment