Commit 6c10bed0 authored by Wendy Merks-Swolfs's avatar Wendy Merks-Swolfs

Extension of GenericField interface with function which does take the GEntity object into account.

parent 57d766c0
Pipeline #2878 failed with stage
in 14 minutes and 44 seconds
......@@ -3020,21 +3020,38 @@ GenericField::~GenericField(){};
double GenericField::operator()(double x, double y, double z, GEntity *ge)
{
std::vector<double> sizes(cbs.size());
std::vector<ptrfunction>::iterator itcbs = cbs.begin();
std::vector<void *>::iterator itdata = user_data.begin();
for(std::vector<double>::iterator it = sizes.begin(); it != sizes.end();
it++, itdata++, itcbs++) {
bool ok = (*itcbs)(x, y, z, (*itdata), (*it));
if(!ok) {
std::vector<double> sizes(cbs_with_data.size() + cbs_extended_with_data.size());
std::vector<double>::iterator it = sizes.begin();
// Go over all callback functions
for(std::vector<std::pair<ptrfunction, void*>>::iterator itcbs = cbs_with_data.begin();
itcbs != cbs_with_data.end(); itcbs++, it++){
bool ok = (itcbs->first)(x, y, z, itcbs->second, (*it));
if (!ok){
Msg::Warning("GenericField::ERROR from callback ");
}
}
// Go over all extended callback functions
for (std::vector<std::pair<ptrfunctionextended, void*>>::iterator itcbs = cbs_extended_with_data.begin();
itcbs != cbs_extended_with_data.end(); itcbs++, it++){
bool ok = (itcbs->first)(x, y, z, ge, itcbs->second, (*it));
if (!ok){
Msg::Warning("GenericField::ERROR from callback ");
}
}
// Take minimum value
return (*std::min_element(sizes.begin(), sizes.end()));
}
void GenericField::setCallbackWithData(ptrfunction fct, void *data)
{
user_data.push_back(data);
cbs.push_back(fct);
cbs_with_data.push_back(std::make_pair(fct, data));
}
void GenericField::setCallbackWithData(ptrfunctionextended fct, void *data)
{
cbs_extended_with_data.push_back(std::make_pair(fct, data));
}
......@@ -452,6 +452,8 @@ public:
// callback prototypes:
// this callback is called with a void* previously given to the GenericField !
typedef bool (*ptrfunction)(double, double, double, void *, double &);
// this callback also takes the GEntity object into account
typedef bool (*ptrfunctionextended)(double, double, double, void*, void*, double&);
GenericField();
~GenericField();
......@@ -461,10 +463,11 @@ public:
// sets the callbacks
void setCallbackWithData(ptrfunction fct, void *data);
void setCallbackWithData(ptrfunctionextended fct, void *data);
private:
std::vector<ptrfunction> cbs; // the callbacks
std::vector<void *> user_data; // the data to be sent to the callbacks
std::vector<std::pair<ptrfunction, void*>> cbs_with_data; // the callbacks with the data to be sent to them
std::vector<std::pair<ptrfunctionextended, void*>> cbs_extended_with_data; // the extended callbacks with the data to be sent to them
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment