ParamData.cc 4.72 KB
/**
 * ParamData.cc
 *
 *  Created on: 17 oct. 2012
 *      Author: AKKA IS
 */

#include "ParamData.hh"

#include <string.h>
#include <stdlib.h>
#include <iostream>

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<type> &a, NotANumber /*b*/) {\
for(std::vector<type>::iterator it = a.begin(); it != a.end(); ++it) {\
	*it = (type)val;\
}\
}\
void operator <<(std::vector<type> &a, ElemNull /*b*/) {\
for(std::vector<type>::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<type> &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<type> &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<short> pval){
	for(auto subval : pval){
			if(subval == SHRT_MIN){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<float> pval){
	for(auto subval : pval){
			if(isnan(subval)){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<double> pval){
	for(auto subval : pval){
			if(isnan(subval)){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<long double> pval){
	for(auto subval : pval){
			if(isnan(subval)){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<int> pval){
	for(auto subval : pval){
		if(subval == INT_MIN){
			return true;
		}
	}
	return false;
}

bool isNAN(std::vector<AMDA::Parameters::LogicalData> pval){
	for(auto subval : pval){
			if(subval == AMDA::Parameters::NaN){
				return true;
			}
		}
		return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<short> 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<float> 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<double> 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<long double> 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<int> 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<AMDA::Parameters::LogicalData> 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);
}