/* * 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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()) { 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 bool createScalarOperation() { switch (_type) { case SFT_MIN : _operation = new StatisticFunctions::MinFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_MIN_SM : _operation = new StatisticFunctions::MinSmFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_MAX : _operation = new StatisticFunctions::MaxFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_MAX_SM : _operation = new StatisticFunctions::MaxSmFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_VAR : _operation = new StatisticFunctions::VarFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_VAR_SM : _operation = new StatisticFunctions::VarSmFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_RMS : _operation = new StatisticFunctions::RmsFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_RMS_SM : _operation = new StatisticFunctions::RmsSmFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_SKEW : _operation = new StatisticFunctions::SkewFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_SKEW_SM : _operation = new StatisticFunctions::SkewSmFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; case SFT_MEDIAN : _operation = new StatisticFunctions::MedianFunc(_process, _timeIntervalList, dynamic_cast&>(_paramData), _windowtime); return true; default: return false; } return false; } template bool createTab1DOperation() { switch (_type) { case SFT_MIN : _operation = new StatisticFunctions::MinFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MIN_SM : _operation = new StatisticFunctions::MinSmFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MAX : _operation = new StatisticFunctions::MaxFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MAX_SM : _operation = new StatisticFunctions::MaxSmFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_VAR : _operation = new StatisticFunctions::VarFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_VAR_SM : _operation = new StatisticFunctions::VarSmFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_RMS : _operation = new StatisticFunctions::RmsFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_RMS_SM : _operation = new StatisticFunctions::RmsSmFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_SKEW : _operation = new StatisticFunctions::SkewFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_SKEW_SM : _operation = new StatisticFunctions::SkewSmFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MEDIAN : _operation = new StatisticFunctions::MedianFunc, std::vector>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; default: return false; } return false; } template bool createTab2DOperation() { switch (_type) { case SFT_MIN : _operation = new StatisticFunctions::MinFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MIN_SM : _operation = new StatisticFunctions::MinSmFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MAX : _operation = new StatisticFunctions::MaxFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MAX_SM : _operation = new StatisticFunctions::MaxSmFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_VAR : _operation = new StatisticFunctions::VarFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_VAR_SM : _operation = new StatisticFunctions::VarSmFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_RMS : _operation = new StatisticFunctions::RmsFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_RMS_SM : _operation = new StatisticFunctions::RmsSmFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_SKEW : _operation = new StatisticFunctions::SkewFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_SKEW_SM : _operation = new StatisticFunctions::SkewSmFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_paramData), _windowtime); return true; case SFT_MEDIAN : _operation = new StatisticFunctions::MedianFunc, Tab2DData>(_process, _timeIntervalList, dynamic_cast >&>(_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_ */