#ifndef __RVL_FCN_FO__ #define __RVL_FCN_FO__ #include "local.hh" /** Standard constructions of Function Objects from C-style functions. Each template accepts a type, and a function type for functions returning an object of that type from one to five arguments of the same type. Each number of arguments requires a different template, unfortunately. */ namespace RVL { /** unary test function */ float test1(float x) { return x*x; } /** binary test function */ double test2(double x, double y) { return x*y; } /** common sanity test - if successful, returns length of output, else throws exception */ template int ScalarFOSanity(int na, LocalDataContainer & target, vector const *> & sources) { try { int n=sources.size(); if (n!=na) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"size of sources = "<getSize() != nt) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"input data len of sources "<getSize()<<" not = target data len= "< class ScalarFO1: public LocalFunctionObject { public: virtual void operator()(LocalDataContainer & target, vector const *> & sources) { try { int nt=ScalarFOSanity(1,target,sources); for (int it=0;itgetData()[it]); } catch (RVLException & e) { e<<"\ncalled from ScalarFO1\n"; } } string getName() const { string tmp="ScalarFO1"; return tmp; } }; /** Binary template */ template class ScalarFO2: public LocalFunctionObject { public: virtual void operator()(LocalDataContainer & target, vector const *> & sources) { try { int nt=ScalarFOSanity(2,target,sources); for (int it=0;itgetData()[it], sources.at(1)->getData()[it]); } catch (RVLException & e) { e<<"\ncalled from ScalarFO3\n"; } } string getName() const { string tmp="ScalarFO"; return tmp; } }; /** Ternary template */ template class ScalarFO3: public LocalFunctionObject { public: virtual void operator()(LocalDataContainer & target, vector const *> & sources) { try { int n=sources.size(); if (n!=3) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"size of sources = "<getSize() != nt) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"input data len of sources "<getSize()<<" not = target data len= "<getData()[it], sources.at(1)->getData()[it], sources.at(2)->getData()[it]); } catch (out_of_range) { RVLException e; e<<"Error: ScalarFO::operator()\n"; e<<"dimensional mismatch - most likely in number of args\n"; throw e; } } string getName() const { string tmp="ScalarFO"; return tmp; } }; template class ScalarFO4: public LocalFunctionObject { public: virtual void operator()(LocalDataContainer & target, vector const *> & sources) { try { int n=sources.size(); if (n!=4) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"size of sources = "<getSize() != nt) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"input data len of sources "<getSize()<<" not = target data len= "<getData()[it], sources.at(1)->getData()[it], sources.at(2)->getData()[it], sources.at(3)->getData()[it]); } catch (out_of_range) { RVLException e; e<<"Error: ScalarFO::operator()\n"; e<<"dimensional mismatch - most likely in number of args\n"; throw e; } } string getName() const { string tmp="ScalarFO"; return tmp; } }; template class ScalarFO5: public LocalFunctionObject { public: virtual void operator()(LocalDataContainer & target, vector const *> & sources) { try { int n=sources.size(); if (n!=5) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"size of sources = "<getSize() != nt) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"input data len of sources "<getSize()<<" not = target data len= "<getData()[it], sources.at(1)->getData()[it], sources.at(2)->getData()[it], sources.at(3)->getData()[it], sources.at(4)->getData()[it]); } catch (out_of_range) { RVLException e; e<<"Error: ScalarFO::operator()\n"; e<<"dimensional mismatch - most likely in number of args\n"; throw e; } } string getName() const { string tmp="ScalarFO"; return tmp; } }; template class ScalarFO6: public LocalFunctionObject { public: virtual void operator()(LocalDataContainer & target, vector const *> & sources) { try { int n=sources.size(); if (n!=6) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"size of sources = "<getSize() != nt) { RVLException e; e<<"Error: ScalarFO::operator\n"; e<<"input data len of sources "<getSize()<<" not = target data len= "<getData()[it], sources.at(1)->getData()[it], sources.at(2)->getData()[it], sources.at(3)->getData()[it], sources.at(4)->getData()[it], sources.at(5)->getData()[it]); } catch (out_of_range) { RVLException e; e<<"Error: ScalarFO::operator()\n"; e<<"dimensional mismatch - most likely in number of args\n"; throw e; } } string getName() const { string tmp="ScalarFO"; return tmp; } }; } #endif