/** * ParamData.cc * * Created on: 17 oct. 2012 * Author: AKKA IS */ #include "ParamData.hh" #include #include #include using namespace log4cxx; namespace AMDA { namespace Parameters { LoggerPtr ParamData::_logger(Logger::getLogger("AMDA-Kernel.ParamData")); ParamData::ParamData() : _minSampling(0.0) { } ParamData::~ParamData() { } } /* namespace Parameters */ } /* namespace AMDA */ const NotANumber notANumber; const ElemNull elemNull; #define GENARATED_SCALAIRE_IMPL(type, val) void operator <<(type &a, NotANumber /*b*/) {\ a = (type)val;\ }\ void operator <<(type &a, ElemNull /*b*/) {\ a = (type)0;\ } GENARATED_SCALAIRE_IMPL(short, SHRT_MIN) GENARATED_SCALAIRE_IMPL(float, NAN) GENARATED_SCALAIRE_IMPL(double, NAN) GENARATED_SCALAIRE_IMPL(long double, NAN) GENARATED_SCALAIRE_IMPL(int, INT_MIN) GENARATED_SCALAIRE_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN) #define GENARATED_VECTOR_IMPL(type, val) void operator <<(std::vector &a, NotANumber /*b*/) {\ for(std::vector::iterator it = a.begin(); it != a.end(); ++it) {\ *it = (type)val;\ }\ }\ void operator <<(std::vector &a, ElemNull /*b*/) {\ for(std::vector::iterator it = a.begin(); it != a.end(); ++it) {\ *it = (type)0;\ }\ } GENARATED_VECTOR_IMPL(short,SHRT_MIN) GENARATED_VECTOR_IMPL(float, NAN) GENARATED_VECTOR_IMPL(double, NAN) GENARATED_VECTOR_IMPL(long double, NAN) GENARATED_VECTOR_IMPL(int, INT_MIN) GENARATED_VECTOR_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN) #define GENARATED_TAB2D_IMPL(type, val) void operator <<(AMDA::Parameters::Tab2DData &a, NotANumber /*b*/) {\ for(int i = 0; i < a.getDim1Size(); ++i) {\ for(int j = 0; j < a.getDim2Size(); ++j) {\ a[i][j] = (type)val;\ }\ }\ }\ void operator <<(AMDA::Parameters::Tab2DData &a, ElemNull /*b*/) {\ for(int i = 0; i < a.getDim1Size(); ++i) {\ for(int j = 0; j < a.getDim2Size(); ++j) {\ a[i][j] = (type)0;\ }\ }\ } GENARATED_TAB2D_IMPL(short,SHRT_MIN) GENARATED_TAB2D_IMPL(float, NAN) GENARATED_TAB2D_IMPL(double, NAN) GENARATED_TAB2D_IMPL(long double, NAN) GENARATED_TAB2D_IMPL(int, INT_MIN) GENARATED_TAB2D_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN) bool isNAN(short pval){ return (pval == SHRT_MIN); } bool isNAN(float pval){ return isnan(pval); } bool isNAN(double pval){ return isnan(pval); } bool isNAN(long double pval){ return isnan(pval); } bool isNAN(int pval){ return (pval == INT_MIN); } bool isNAN(AMDA::Parameters::LogicalData pval){ return (pval == AMDA::Parameters::NaN); } bool isNAN(std::vector pval){ for(auto subval : pval){ if(subval == SHRT_MIN){ return true; } } return false; } bool isNAN(std::vector pval){ for(auto subval : pval){ if(isnan(subval)){ return true; } } return false; } bool isNAN(std::vector pval){ for(auto subval : pval){ if(isnan(subval)){ return true; } } return false; } bool isNAN(std::vector pval){ for(auto subval : pval){ if(isnan(subval)){ return true; } } return false; } bool isNAN(std::vector pval){ for(auto subval : pval){ if(subval == INT_MIN){ return true; } } return false; } bool isNAN(std::vector pval){ for(auto subval : pval){ if(subval == AMDA::Parameters::NaN){ return true; } } return false; } bool isNAN(AMDA::Parameters::Tab2DData pval){ for (int i = 0; i < pval.getDim1Size(); ++i) for (int j = 0; j < pval.getDim2Size(); ++j) if(pval[i][j] == SHRT_MIN) return true; return false; } bool isNAN(AMDA::Parameters::Tab2DData pval){ for (int i = 0; i < pval.getDim1Size(); ++i) for (int j = 0; j < pval.getDim2Size(); ++j) if(isnan(pval[i][j])) return true; return false; } bool isNAN(AMDA::Parameters::Tab2DData pval){ for (int i = 0; i < pval.getDim1Size(); ++i) for (int j = 0; j < pval.getDim2Size(); ++j) if(isnan(pval[i][j])) return true; return false; } bool isNAN(AMDA::Parameters::Tab2DData pval){ for (int i = 0; i < pval.getDim1Size(); ++i) for (int j = 0; j < pval.getDim2Size(); ++j) if(isnan(pval[i][j])) return true; return false; } bool isNAN(AMDA::Parameters::Tab2DData pval){ for (int i = 0; i < pval.getDim1Size(); ++i) for (int j = 0; j < pval.getDim2Size(); ++j) if(pval[i][j] == INT_MIN) return true; return false; } bool isNAN(AMDA::Parameters::Tab2DData pval){ for (int i = 0; i < pval.getDim1Size(); ++i) for (int j = 0; j < pval.getDim2Size(); ++j) if(pval[i][j] == AMDA::Parameters::NaN) return true; return false; } bool isApproximatelyEqual(double a, double b) { return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * 0.0001); }