StatisticFunctionsCreator.hh 14.5 KB
/*
 * StatisticFunctionsCreator.hh
 *
 *  Created on: Jun 21, 2018
 *      Author: benjamin
 */

#ifndef STATISTICFUNCTIONSCREATOR_HH_
#define STATISTICFUNCTIONSCREATOR_HH_


#include "DicError.hh"
#include "AMDA_exception.hh"

#include "ParamData.hh"
#include "VisitorOfParamData.hh"

#include "MinFunc.hh"
#include "MaxFunc.hh"
#include "VarFunc.hh"
#include "RmsFunc.hh"
#include "SkewFunc.hh"
#include "MedianFunc.hh"

namespace AMDA {
namespace Parameters {

/**
 * @class StatisticFunctionsCreator
 * @brief Creator of the Operation related to the simple functions to apply.
 * @details Implement the interface VisitorOfParamData.
 */
class StatisticFunctionsCreator : public VisitorOfParamData {
public:
	typedef enum {
		SFT_MIN,
		SFT_MIN_SM,
		SFT_MAX,
		SFT_MAX_SM,
		SFT_VAR,
		SFT_VAR_SM,
		SFT_RMS,
		SFT_RMS_SM,
		SFT_SKEW,
		SFT_SKEW_SM,
		SFT_MEDIAN
	} StatisticFunctionsType;

	/**
	 * @brief Constructor.
	 */
	StatisticFunctionsCreator(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamData& paramInput, StatisticFunctionsType type, double windowtime)
		: _process(pProcess), _timeIntervalList(pTimeIntervalList), _paramData(paramInput), _type(type), _windowtime(windowtime), _operation(NULL) {

		_paramData.accept(*this);
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireShort *)
	 */
	 void visit(ParamDataScalaireShort *) {
		if (!createScalarOperation<short>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *)
	 */
	void visit(ParamDataScalaireFloat *){
		if (!createScalarOperation<float>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *)
	 */
	void visit(ParamDataScalaireDouble *){
		if (!createScalarOperation<double>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *)
	 */
	void visit(ParamDataScalaireLongDouble *){
		if (!createScalarOperation<long double>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireInt *)
	 */
	void visit(ParamDataScalaireInt *){
		if (!createScalarOperation<int>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataLogicalData *)
	 */
	void visit(ParamDataLogicalData *) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DShort *)
	 */
	 void visit(ParamDataTab1DShort *){
		if (!createTab1DOperation<short>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *)
	 */
	void visit(ParamDataTab1DFloat *) {
		if (!createTab1DOperation<float>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *)
	 */
	void visit(ParamDataTab1DDouble *){
		if (!createTab1DOperation<double>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *)
	 */
	void visit(ParamDataTab1DLongDouble *){
		if (!createTab1DOperation<float>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DInt *)
	 */
	void visit(ParamDataTab1DInt *){
		if (!createTab1DOperation<int>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *)
	 */
	void visit(ParamDataTab1DLogicalData *) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
	 */
	void visit(ParamDataTab2DShort *) {
		if (!createTab2DOperation<short>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
	 */
	void visit(ParamDataTab2DFloat *) {
		if (!createTab2DOperation<float>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
	 */
	void visit(ParamDataTab2DDouble *) {
		if (!createTab2DOperation<double>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
	 */
	void visit(ParamDataTab2DLongDouble *) {
		if (!createTab2DOperation<long double>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
	 */
	void visit(ParamDataTab2DInt *) {
		if (!createTab2DOperation<int>()) {
			BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
	 */
	void visit(ParamDataTab2DLogicalData *) {
		BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("StatisticFunctionsCreator operation not supported"));
	}

	/**
	 * @brief get the simple functions parameterized operation.
	 */
	Operation * getOperation() const {	return _operation;	}

private:
	template <typename Type>
	bool createScalarOperation() {
		switch (_type) {
			case SFT_MIN :
				_operation = new StatisticFunctions::MinFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_MIN_SM :
				_operation = new StatisticFunctions::MinSmFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_MAX :
				_operation = new StatisticFunctions::MaxFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_MAX_SM :
				_operation = new StatisticFunctions::MaxSmFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_VAR :
				_operation = new StatisticFunctions::VarFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_VAR_SM :
				_operation = new StatisticFunctions::VarSmFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_RMS :
				_operation = new StatisticFunctions::RmsFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_RMS_SM :
				_operation = new StatisticFunctions::RmsSmFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_SKEW :
				_operation = new StatisticFunctions::SkewFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_SKEW_SM :
				_operation = new StatisticFunctions::SkewSmFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			case SFT_MEDIAN :
				_operation = new StatisticFunctions::MedianFunc<Type, Type>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Type>&>(_paramData), _windowtime);
				return true;
			default:
				return false;
		}
		return false;
	}

	template <typename Type>
	bool createTab1DOperation() {
		switch (_type) {
			case SFT_MIN :
				_operation = new StatisticFunctions::MinFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MIN_SM :
				_operation = new StatisticFunctions::MinSmFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
                        case SFT_MAX :
				_operation = new StatisticFunctions::MaxFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MAX_SM :
				_operation = new StatisticFunctions::MaxSmFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_VAR :
				_operation = new StatisticFunctions::VarFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_VAR_SM :
				_operation = new StatisticFunctions::VarSmFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_RMS :
				 _operation = new StatisticFunctions::RmsFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_RMS_SM :
				_operation = new StatisticFunctions::RmsSmFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_SKEW :
				_operation = new StatisticFunctions::SkewFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_SKEW_SM :
				_operation = new StatisticFunctions::SkewSmFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MEDIAN :
				_operation = new StatisticFunctions::MedianFunc<std::vector<Type>, std::vector<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<std::vector<Type> >&>(_paramData), _windowtime);
				return true;
			default:
				return false;
		}
		return false;
	}

	template <typename Type>
	bool createTab2DOperation() {
		switch (_type) {
			case SFT_MIN :
				_operation = new StatisticFunctions::MinFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MIN_SM :
				_operation = new StatisticFunctions::MinSmFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MAX :
				_operation = new StatisticFunctions::MaxFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MAX_SM :
				_operation = new StatisticFunctions::MaxSmFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_VAR :
				_operation = new StatisticFunctions::VarFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_VAR_SM :
				_operation = new StatisticFunctions::VarSmFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_RMS :
				_operation = new StatisticFunctions::RmsFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_RMS_SM :
				_operation = new StatisticFunctions::RmsSmFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_SKEW :
				_operation = new StatisticFunctions::SkewFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_SKEW_SM :
				_operation = new StatisticFunctions::SkewSmFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			case SFT_MEDIAN :
				_operation = new StatisticFunctions::MedianFunc<Tab2DData<Type>, Tab2DData<Type>>(_process, _timeIntervalList, dynamic_cast<ParamDataSpec<Tab2DData<Type> >&>(_paramData), _windowtime);
				return true;
			default:
				return false;
		}
		return false;
	}

	Process   &_process;
	TimeIntervalListSPtr _timeIntervalList;
	ParamData &_paramData;
	StatisticFunctionsType _type;
	double _windowtime;
	Operation* _operation;
};

} /* namespace Parameters */
} /* namespace AMDA */
#endif /* STATISTICFUNCTIONSCREATOR_HH_ */