diff --git a/alib2cli/src/ast/params/BindedValueParam.h b/alib2cli/src/ast/params/BindedValueParam.h index 1b7b39aca87e9541a08a9beb67608b27fb9f099a..0fd4a463133a62d92626766f72873a3b12679cde 100644 --- a/alib2cli/src/ast/params/BindedValueParam.h +++ b/alib2cli/src/ast/params/BindedValueParam.h @@ -2,7 +2,7 @@ #define _CLI_BINDED_VALUE_PARAM_H_ #include <ast/Param.h> -#include <abstraction/ImmediateValueAbstraction.hpp> +#include <abstraction/Registry.h> namespace cli { @@ -14,7 +14,7 @@ public: } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > &, Environment & environment ) const override { - return std::make_shared < abstraction::ImmediateValueAbstraction < std::string > > ( environment.getBinding ( m_bind ) ); + return abstraction::Registry::getImmediateAbstraction ( ext::to_string < std::string > ( ), environment.getBinding ( m_bind ) ); } }; diff --git a/alib2cli/src/ast/params/CastParam.h b/alib2cli/src/ast/params/CastParam.h index 0f7c0876dd08dc271fc0d059ccf2227f56994e59..c073a5bed68d92212d4b8a4ae30843e8ace05394 100644 --- a/alib2cli/src/ast/params/CastParam.h +++ b/alib2cli/src/ast/params/CastParam.h @@ -18,12 +18,12 @@ public: bool normalize; - std::shared_ptr < abstraction::OperationAbstraction > res = translatedParam->getCastFromResult ( m_type, normalize ); + std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( m_type, translatedParam->getReturnType ( ), normalize ); res->attachInput ( translatedParam, 0 ); res->eval ( ); if ( normalize ) { - std::shared_ptr < abstraction::OperationAbstraction > normalized = res->getNormalizeResult ( ); + std::shared_ptr < abstraction::OperationAbstraction > normalized = abstraction::Registry::getNormalizeAbstraction ( res->getReturnType ( ) ); normalized->attachInput ( res, 0 ); normalized->eval ( ); diff --git a/alib2cli/src/ast/statements/CastStatement.h b/alib2cli/src/ast/statements/CastStatement.h index 864a901c1d122c4b9a8bbdc5ecac73faef02df22..14454beb4680ce2ab4d41f523d2fbc1a8f743452 100644 --- a/alib2cli/src/ast/statements/CastStatement.h +++ b/alib2cli/src/ast/statements/CastStatement.h @@ -16,14 +16,14 @@ public: virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override { std::shared_ptr < abstraction::OperationAbstraction > translatedStatement = m_statement->translateAndEval ( prev, environment ); - bool normalize = false; + bool normalize; - std::shared_ptr < abstraction::OperationAbstraction > res = translatedStatement->getCastFromResult ( m_type, normalize ); + std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getCastAbstraction ( m_type, translatedStatement->getReturnType ( ), normalize ); res->attachInput ( translatedStatement, 0 ); res->eval ( ); if ( normalize ) { - std::shared_ptr < abstraction::OperationAbstraction > normalized = res->getNormalizeResult ( ); + std::shared_ptr < abstraction::OperationAbstraction > normalized = abstraction::Registry::getNormalizeAbstraction ( res->getReturnType ( ) ); normalized->attachInput ( res, 0 ); normalized->eval ( ); diff --git a/alib2cli/src/ast/statements/ResultBindedFileStatement.h b/alib2cli/src/ast/statements/ResultBindedFileStatement.h index f40c471db295cfb93240147805c8850b5ecadd1f..28af7abdb382194ada410b6ab7863f5ec09389c7 100644 --- a/alib2cli/src/ast/statements/ResultBindedFileStatement.h +++ b/alib2cli/src/ast/statements/ResultBindedFileStatement.h @@ -13,7 +13,7 @@ public: } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override { - std::shared_ptr < abstraction::OperationAbstraction > res = prev->getXmlFileWriterFromResult ( environment.getBinding ( m_bind ) ); + std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getXmlFileWriterAbstraction ( prev->getReturnType ( ), environment.getBinding ( m_bind ) ); res->attachInput ( prev, 0 ); res->eval ( ); return res; diff --git a/alib2cli/src/ast/statements/ResultImmediateFileStatement.h b/alib2cli/src/ast/statements/ResultImmediateFileStatement.h index 6a816a1306ee1fcc866f9d119586d7be71eca429..950cf9817fa9eb3cc45c4ab88837f6aa3412b5d0 100644 --- a/alib2cli/src/ast/statements/ResultImmediateFileStatement.h +++ b/alib2cli/src/ast/statements/ResultImmediateFileStatement.h @@ -13,7 +13,7 @@ public: } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override { - std::shared_ptr < abstraction::OperationAbstraction > res = prev->getXmlFileWriterFromResult ( m_name ); + std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getXmlFileWriterAbstraction ( prev->getReturnType ( ), m_name ); res->attachInput ( prev, 0 ); res->eval ( ); return res; diff --git a/alib2cli/src/ast/statements/ResultPrintStatement.h b/alib2cli/src/ast/statements/ResultPrintStatement.h index 18d515331b107e7e6a9a3d856122791b95a7dae4..c4a45f9154a13be9ad24d558c36678356da306a1 100644 --- a/alib2cli/src/ast/statements/ResultPrintStatement.h +++ b/alib2cli/src/ast/statements/ResultPrintStatement.h @@ -11,7 +11,7 @@ public: } virtual std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & ) const override { - std::shared_ptr < abstraction::OperationAbstraction > res = prev->getValuePrinterFromResult ( ); + std::shared_ptr < abstraction::OperationAbstraction > res = abstraction::Registry::getValuePrinterAbstraction ( prev->getReturnType ( ) ); res->attachInput ( prev, 0 ); res->eval ( ); return res; diff --git a/alib2cli/src/ast/statements/SingleStatement.cpp b/alib2cli/src/ast/statements/SingleStatement.cpp index 4804e8791eb6a322580a2d106759894b7239456a..d7ce1f3cb089968304462485a8b4af414fef4d84 100644 --- a/alib2cli/src/ast/statements/SingleStatement.cpp +++ b/alib2cli/src/ast/statements/SingleStatement.cpp @@ -17,8 +17,8 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate } ext::vector < ext::type_index > paramTypes; - for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) { - paramTypes.push_back ( param->type ( ) ); + for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) { + paramTypes.push_back ( param->getReturnTypeIndex ( ) ); } bool downcast = false; @@ -29,7 +29,7 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate unsigned i = 0; for ( const std::shared_ptr < abstraction::OperationAbstraction > & param : params ) { if ( ! algo->attachInput ( param, i ) ) - throw exception::CommonException ( "Can't connect param at " + ext::to_string ( i ) + " of algorithm " + m_name + " with result of type " + ext::to_string ( param->type ( ) ) + "." ); + throw exception::CommonException ( "Can't connect param at " + ext::to_string ( i ) + " of algorithm " + m_name + " with result of type " + param->getReturnType ( ) + "." ); i++; } @@ -37,7 +37,7 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate throw exception::CommonException ( "Eval of algorithm " + m_name + " failed." ); if ( downcast ) { - std::shared_ptr < abstraction::OperationAbstraction > downcaster = algo->getDowncastResult ( ); + std::shared_ptr < abstraction::OperationAbstraction > downcaster = abstraction::Registry::getDowncastAbstraction ( algo->getRuntimeReturnType ( ), algo->getReturnType ( ) ); downcaster->attachInput ( algo, 0 ); downcaster->eval ( ); @@ -45,7 +45,7 @@ std::shared_ptr < abstraction::OperationAbstraction > SingleStatement::translate } if ( normalize ) { - std::shared_ptr < abstraction::OperationAbstraction > normalized = algo->getNormalizeResult ( ); + std::shared_ptr < abstraction::OperationAbstraction > normalized = abstraction::Registry::getNormalizeAbstraction ( algo->getReturnType ( ) ); normalized->attachInput ( algo, 0 ); normalized->eval ( ); diff --git a/alib2common/src/abstraction/AlgorithmAbstraction.hpp b/alib2common/src/abstraction/AlgorithmAbstraction.hpp index 9feeb213062ea0f56c2e844fb41bb3fe1445ace4..a73c0b9a8b0b34e771f3ceb46f4d7b03d31ef326 100644 --- a/alib2common/src/abstraction/AlgorithmAbstraction.hpp +++ b/alib2common/src/abstraction/AlgorithmAbstraction.hpp @@ -111,21 +111,13 @@ public: return sizeof ... ( ParamTypes ); } - virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned index, const std::string & value ) const override { + virtual ext::type_index getParamTypeIndex ( unsigned index ) const override { auto callback = [ & ] ( auto & param ) { - std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( ); - return Registry::getImmediateAbstraction ( std::move ( paramType ), value ); + return ext::type_index ( typeid ( typename std::decay < decltype ( param ) >::type::element_type::return_type ) ); }; - return ext::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback ); + return ext::call_on_nth < ext::type_index > ( inputs, index, callback ); } - virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, ext::deque < sax::Token > tokens ) const override { - auto callback = [ & ] ( auto & param ) { - std::string paramType = ext::to_string < typename std::decay < decltype ( param ) >::type::element_type::return_type > ( ); - return Registry::getXmlParserAbstraction ( std::move ( paramType ), std::move ( tokens ) ); - }; - return ext::call_on_nth < std::shared_ptr < OperationAbstraction > > ( inputs, index, callback ); - } }; template < class ReturnType, class ... ParamTypes > diff --git a/alib2common/src/abstraction/NullaryOperationAbstraction.hpp b/alib2common/src/abstraction/NullaryOperationAbstraction.hpp index 6bd572600252585346e465c8db7d224c2a4cb976..a7eebcf4601910557f001e9d598ff9dd77366a1e 100644 --- a/alib2common/src/abstraction/NullaryOperationAbstraction.hpp +++ b/alib2common/src/abstraction/NullaryOperationAbstraction.hpp @@ -46,13 +46,10 @@ public: return 0; } - virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned, const std::string & ) const override { + virtual ext::type_index getParamTypeIndex ( unsigned ) const override { throw exception::CommonException ( "Nullary algorithm does not have any parameter." ); } - virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned, ext::deque < sax::Token > ) const override { - throw exception::CommonException ( "Nullary algorithm does not have any parameter." ); - } }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/OperationAbstraction.hpp b/alib2common/src/abstraction/OperationAbstraction.hpp index 3f9ad2e667dc76923f1bd2d4c16cc9ec0f0156ce..c3065761a8a9e60fe8a9e0f14dd331b12af75afb 100644 --- a/alib2common/src/abstraction/OperationAbstraction.hpp +++ b/alib2common/src/abstraction/OperationAbstraction.hpp @@ -30,19 +30,24 @@ public: virtual bool inputsAttached ( ) const = 0; virtual bool run ( ) = 0; virtual bool eval ( ) = 0; - virtual ext::type_index type ( ) const = 0; - virtual ext::type_index runtime_type ( ) const = 0; virtual unsigned numberOfParams ( ) const = 0; virtual bool cached ( ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, ext::deque < sax::Token > tokens ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned index, const std::string & data ) const = 0; + virtual ext::type_index getParamTypeIndex ( unsigned index ) const = 0; + virtual ext::type_index getReturnTypeIndex ( ) const = 0; + virtual ext::type_index getRuntimeReturnTypeIndex ( ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getXmlFileWriterFromResult ( const std::string & filename ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getValuePrinterFromResult ( ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getCastFromResult ( const std::string & type, bool & normalize ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getNormalizeResult ( ) const = 0; - virtual std::shared_ptr < OperationAbstraction > getDowncastResult ( ) const = 0; + std::string getParamType ( unsigned index ) const { + return ext::to_string ( getParamTypeIndex ( index ) ); + } + + std::string getReturnType ( ) const { + return ext::to_string ( getReturnTypeIndex ( ) ); + } + + std::string getRuntimeReturnType ( ) const { + return ext::to_string ( getRuntimeReturnTypeIndex ( ) ); + } }; diff --git a/alib2common/src/abstraction/UnaryOperationAbstraction.hpp b/alib2common/src/abstraction/UnaryOperationAbstraction.hpp index 34f072a3537ec05be4fcfcd5c41ae452c217596b..074e7b79eb209410da7a3f7e3d164125e9418b8e 100644 --- a/alib2common/src/abstraction/UnaryOperationAbstraction.hpp +++ b/alib2common/src/abstraction/UnaryOperationAbstraction.hpp @@ -69,21 +69,13 @@ public: return 1; } - virtual std::shared_ptr < OperationAbstraction > getImmediateValueFromParam ( unsigned index, const std::string & value ) const override { + virtual ext::type_index getParamTypeIndex ( unsigned index ) const override { if ( index != 0 ) throw std::out_of_range ( "Invalid input index" ); - std::string paramType = ext::to_string < ParamType > ( ); - return Registry::getImmediateAbstraction ( std::move ( paramType ), value ); + return ext::type_index ( typeid ( ParamType ) ); } - virtual std::shared_ptr < OperationAbstraction > getXmlParserFromParam ( unsigned index, ext::deque < sax::Token > tokens ) const override { - if ( index != 0 ) - throw exception::CommonException ( "Out of range index: " + ext::to_string ( index ) + " max: " + ext::to_string ( numberOfParams ( ) ) + "." ); - - std::string paramType = ext::to_string < ParamType > ( ); - return Registry::getXmlParserAbstraction ( std::move ( paramType ), std::move ( tokens ) ); - } }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/ValueOperationAbstraction.hpp b/alib2common/src/abstraction/ValueOperationAbstraction.hpp index 5f6c50bf5f575e1a5cac0150df89f5c63bb7cd54..d29837b162801c859b43c705dc4b1431512e238c 100644 --- a/alib2common/src/abstraction/ValueOperationAbstraction.hpp +++ b/alib2common/src/abstraction/ValueOperationAbstraction.hpp @@ -44,37 +44,11 @@ public: return * m_data; } - virtual std::shared_ptr < OperationAbstraction > getXmlFileWriterFromResult ( const std::string & filename ) const override { - std::string param = ext::to_string < ReturnType > ( ); - return Registry::getXmlFileWriterAbstraction ( param, filename ); - } - - virtual std::shared_ptr < OperationAbstraction > getValuePrinterFromResult ( ) const override { - std::string param = ext::to_string < ReturnType > ( ); - return Registry::getValuePrinterAbstraction ( param ); - } - - virtual std::shared_ptr < OperationAbstraction > getCastFromResult ( const std::string & target, bool & normalize ) const override { - std::string param = ext::to_string < ReturnType > ( ); - return Registry::getCastAbstraction ( target, param, normalize ); - } - - virtual std::shared_ptr < OperationAbstraction > getNormalizeResult ( ) const override { - std::string param = ext::to_string < ReturnType > ( ); - return Registry::getNormalizeAbstraction ( param ); - } - - virtual std::shared_ptr < OperationAbstraction > getDowncastResult ( ) const override { - std::string base = ext::to_string < ReturnType > ( ); - std::string concrete = ext::to_string ( runtime_type ( ) ); - return Registry::getDowncastAbstraction ( concrete, base ); - } - - virtual ext::type_index type ( ) const override { + virtual ext::type_index getReturnTypeIndex ( ) const override { return ext::type_index ( typeid ( ReturnType ) ); } - virtual ext::type_index runtime_type ( ) const override { + virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override { if ( isReady ( ) ) return ext::type_index ( typeid ( getData ( ) ) ); else diff --git a/alib2common/src/abstraction/VoidOperationAbstraction.hpp b/alib2common/src/abstraction/VoidOperationAbstraction.hpp index 2df106a3a723fdcbd6b930ed4b695bdd2f303999..28c2ff4736506e981bab0ff8d83bdf7890b5f81b 100644 --- a/alib2common/src/abstraction/VoidOperationAbstraction.hpp +++ b/alib2common/src/abstraction/VoidOperationAbstraction.hpp @@ -25,31 +25,11 @@ public: callback ( input->getData ( ) ); } - virtual std::shared_ptr < OperationAbstraction > getXmlFileWriterFromResult ( const std::string & ) const override { - throw exception::CommonException ( "Void algorithm does not have a result." ); - } - - virtual std::shared_ptr < OperationAbstraction > getValuePrinterFromResult ( ) const override { - throw exception::CommonException ( "Void algorithm does not have a result." ); - } - - virtual std::shared_ptr < OperationAbstraction > getCastFromResult ( const std::string &, bool & ) const override { - throw exception::CommonException ( "Void algorithm does not have a result." ); - } - - virtual std::shared_ptr < OperationAbstraction > getNormalizeResult ( ) const override { - throw exception::CommonException ( "Void algorithm does not have a result." ); - } - - virtual std::shared_ptr < OperationAbstraction > getDowncastResult ( ) const override { - throw exception::CommonException ( "Void algorithm does not have a result." ); - } - - virtual ext::type_index type ( ) const override { + virtual ext::type_index getReturnTypeIndex ( ) const override { return ext::type_index ( typeid ( void ) ); } - virtual ext::type_index runtime_type ( ) const override { + virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override { return ext::type_index ( typeid ( void ) ); }