diff --git a/alib2abstraction/src/abstraction/AlgorithmAbstraction.hpp b/alib2abstraction/src/abstraction/AlgorithmAbstraction.hpp index 5026b83459f9aa4c296881572d267537e316f738..a5ce5f239ac894243e56bd13caa0de74dc4af402 100644 --- a/alib2abstraction/src/abstraction/AlgorithmAbstraction.hpp +++ b/alib2abstraction/src/abstraction/AlgorithmAbstraction.hpp @@ -25,12 +25,6 @@ public: } virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - this->template run_helper < ParamTypes ... > ( m_callback, this->m_params ); return true; } diff --git a/alib2abstraction/src/abstraction/CastAbstraction.hpp b/alib2abstraction/src/abstraction/CastAbstraction.hpp index c1b1a7d2e1e8e6968ea920147dad2fd648c96e14..d9ce57428535e915a9bf90227d8d880aee325f91 100644 --- a/alib2abstraction/src/abstraction/CastAbstraction.hpp +++ b/alib2abstraction/src/abstraction/CastAbstraction.hpp @@ -16,12 +16,6 @@ template < class ReturnType, class ParamType > class CastAbstraction : public UnaryOperationAbstraction < ReturnType, const ParamType & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); this->m_data = ReturnType ( retrieveValue < const ParamType & > ( param.first, param.second ) ); diff --git a/alib2abstraction/src/abstraction/MemberAbstraction.hpp b/alib2abstraction/src/abstraction/MemberAbstraction.hpp index fe743cd8a31eb17093e588df3d27d69b619e923b..05661f5ba5604a4fd0e1c7f41e02b6c28c2c13d1 100644 --- a/alib2abstraction/src/abstraction/MemberAbstraction.hpp +++ b/alib2abstraction/src/abstraction/MemberAbstraction.hpp @@ -26,12 +26,6 @@ public: } virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) + 1 > params = this->m_params; std::shared_ptr < OperationAbstraction > reference = std::make_shared < ReferenceAbstraction < typename std::remove_reference < ObjectType >::type > > ( ); diff --git a/alib2abstraction/src/abstraction/NormalizeAbstraction.hpp b/alib2abstraction/src/abstraction/NormalizeAbstraction.hpp index 63cc53532a72e6600b626cee2a9dfc47f51c85b7..71f3649450bb6c221190e4b30326123aaf1afbeb 100644 --- a/alib2abstraction/src/abstraction/NormalizeAbstraction.hpp +++ b/alib2abstraction/src/abstraction/NormalizeAbstraction.hpp @@ -18,12 +18,6 @@ template < class ReturnType, class ParamType > class NormalizeAbstraction : public UnaryOperationAbstraction < ReturnType, ParamType && > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & rawParam = std::get < 0 > ( this->m_params ); ParamType && param = retrieveValue < ParamType && > ( rawParam.first, rawParam.second ); ReturnType res = factory::NormalizeFactory::normalize ( std::move ( param ) ); diff --git a/alib2abstraction/src/abstraction/OperationAbstraction.hpp b/alib2abstraction/src/abstraction/OperationAbstraction.hpp index d4868846c278417b94eb882a296ceea04aa200c6..64b73fa94459190a404bbff156da5c21ac4c05ba 100644 --- a/alib2abstraction/src/abstraction/OperationAbstraction.hpp +++ b/alib2abstraction/src/abstraction/OperationAbstraction.hpp @@ -15,6 +15,9 @@ namespace abstraction { class OperationAbstraction : public std::enable_shared_from_this < OperationAbstraction > { +protected: + virtual bool run ( ) = 0; + public: virtual bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, unsigned index, bool move, bool checkInput ) = 0; virtual bool detachInput ( unsigned index ) = 0; @@ -24,7 +27,6 @@ public: virtual bool inputsReady ( ) const = 0; virtual bool inputsAttached ( ) const = 0; - virtual bool run ( ) = 0; virtual bool eval ( ) = 0; virtual unsigned numberOfParams ( ) const = 0; virtual bool cached ( ) const = 0; diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.hpp b/alib2abstraction/src/abstraction/PackingAbstraction.hpp index cf45b9060c06d2d12cdb8497929a97be0a02d640..9f9ab75764aa88095ec36e167c5281aaa1bd6863 100644 --- a/alib2abstraction/src/abstraction/PackingAbstraction.hpp +++ b/alib2abstraction/src/abstraction/PackingAbstraction.hpp @@ -83,13 +83,7 @@ public: } virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - - return m_abstractions [ m_resultId ]->run ( ); + return m_abstractions [ m_resultId ]->eval ( ); } virtual bool eval ( ) override { @@ -99,7 +93,7 @@ public: if ( this->cached ( ) ) return true; - return m_abstractions [ m_resultId ]->eval ( ); + return this->run ( ); } virtual unsigned numberOfParams ( ) const override { diff --git a/alib2abstraction/src/abstraction/ReferenceAbstraction.hpp b/alib2abstraction/src/abstraction/ReferenceAbstraction.hpp index 0fadebed6b3a9a07d72a35e850098afec53024d0..7103c96158385043594ea9a9768d3f64c1b7139d 100644 --- a/alib2abstraction/src/abstraction/ReferenceAbstraction.hpp +++ b/alib2abstraction/src/abstraction/ReferenceAbstraction.hpp @@ -16,12 +16,6 @@ template < class Type > class ReferenceAbstraction : public UnaryOperationAbstraction < Type *, Type & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); this->m_data = & retrieveValue < Type & > ( param.first, param.second ); diff --git a/alib2abstraction/src/abstraction/SetAbstraction.hpp b/alib2abstraction/src/abstraction/SetAbstraction.hpp index 98dfc3b0322f50dc1e76f87d45f454e3514ec491..e749433002c9a611b9f7dff36b72e084c01f431b 100644 --- a/alib2abstraction/src/abstraction/SetAbstraction.hpp +++ b/alib2abstraction/src/abstraction/SetAbstraction.hpp @@ -18,12 +18,6 @@ template < class ParamType > class SetAbstraction : public AnyaryOperationAbstraction < ext::set < ParamType >, ParamType > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - ext::set < ParamType > theSet; for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : this->m_params ) { theSet.insert ( abstraction::retrieveValue < ParamType > ( param.first, param.second ) ); diff --git a/alib2abstraction/src/abstraction/ValuePrinterAbstraction.hpp b/alib2abstraction/src/abstraction/ValuePrinterAbstraction.hpp index 4e2b74fe0796763d0b53aadbebc92abae91de4ad..665258ed2b090201d9857fc6758477104d4d9a7e 100644 --- a/alib2abstraction/src/abstraction/ValuePrinterAbstraction.hpp +++ b/alib2abstraction/src/abstraction/ValuePrinterAbstraction.hpp @@ -22,12 +22,6 @@ public: } virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); m_ostream << retrieveValue < const ParamType & > ( param.first, param.second ) << std::endl; return true; diff --git a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp index 28311daad4e24dfa55095cc67b8dcce07540f7f7..b32bfb3ad7094109363c7090769a86c472031d3e 100644 --- a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp +++ b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp @@ -18,7 +18,7 @@ class BaseWrapperAbstraction : public OperationAbstraction { protected: std::function < std::shared_ptr < OperationAbstraction > ( ParamTypes ... ) > m_WrapperFinder; - std::optional < std::shared_ptr < OperationAbstraction > > m_data; + std::shared_ptr < OperationAbstraction > m_abstraction; ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > m_params; public: @@ -93,7 +93,7 @@ public: } virtual bool isReady ( ) const override { - return ( bool ) m_data && m_data.value ( )->isReady ( ); + return ( bool ) m_abstraction && m_abstraction->isReady ( ); } virtual bool cached ( ) const override { @@ -106,10 +106,18 @@ public: virtual std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( ) override { if ( this->isReady ( ) ) - return this->m_data.value ( )->getProxyAbstraction ( ); + return this->m_abstraction->getProxyAbstraction ( ); else throw std::domain_error ( "Proxy abstraction not avaiable before evaluation." ); } + + void attachInputsToAbstraction ( ) { + for ( unsigned index = 0; index < sizeof ... ( ParamTypes ); ++ index ) + if ( ! this->m_abstraction->attachInput ( this->m_params [ index ].first, index, this->m_params [ index ].second, true ) ) + throw std::invalid_argument ( "Can't connect param " + this->m_abstraction->getParamType ( index ) + " at " + ext::to_string ( index ) + " of wrapped algorithm with result of type " + this->m_params [ index ].first->getReturnType ( ) + "." ); + + } + }; template < class ReturnType, class ... ParamTypes > @@ -119,17 +127,14 @@ public: } virtual bool run ( ) override { - if ( ! this->m_data ) - this->m_data = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); + this->m_abstraction = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); - std::shared_ptr < OperationAbstraction > & abstraction = this->m_data.value ( ); - if ( abstraction->getReturnTypeIndex ( ) != this->getReturnTypeIndex ( ) ) + if ( this->m_abstraction->getReturnTypeIndex ( ) != this->getReturnTypeIndex ( ) ) throw std::domain_error ( "Expected and provided types do not match" ); - for ( unsigned index = 0; index < sizeof ... ( ParamTypes ); ++ index ) - abstraction->attachInput ( this->m_params [ index ].first, index, this->m_params [ index ].second, true ); + this->attachInputsToAbstraction ( ); - return abstraction->run ( ); + return this->m_abstraction->eval ( ); } virtual ext::type_index getReturnTypeIndex ( ) const override { @@ -152,14 +157,11 @@ public: } virtual bool run ( ) override { - if ( ! this->m_data ) - this->m_data = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); + this->m_abstraction = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); - std::shared_ptr < OperationAbstraction > & abstraction = this->m_data.value ( ); - for ( unsigned index = 0; index < sizeof ... ( ParamTypes ); ++ index ) - abstraction->attachInput ( this->m_params [ index ].first, index, this->m_params [ index ].second, true ); + this->attachInputsToAbstraction ( ); - return abstraction->run ( ); + return this->m_abstraction->eval ( ); } virtual ext::type_index getReturnTypeIndex ( ) const override { @@ -168,7 +170,7 @@ public: virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override { if ( this->isReady ( ) ) - return this->m_data.value ( )->getProxyAbstraction ( )->getRuntimeReturnTypeIndex ( ); + return this->m_abstraction->getProxyAbstraction ( )->getRuntimeReturnTypeIndex ( ); else throw std::domain_error ( "Runtime type unknown before evaluation." ); } diff --git a/alib2raw/src/abstraction/RawReaderAbstraction.hpp b/alib2raw/src/abstraction/RawReaderAbstraction.hpp index bcce1b0da45164ea5b59a033a09ff9a1164b849d..dbfb0a470ea6e3723750d38add10e481943afc9a 100644 --- a/alib2raw/src/abstraction/RawReaderAbstraction.hpp +++ b/alib2raw/src/abstraction/RawReaderAbstraction.hpp @@ -17,9 +17,6 @@ template < class ReturnType > class RawReaderAbstraction : public UnaryOperationAbstraction < ReturnType, std::string && > { public: virtual bool run ( ) override { - if ( this->isReady ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); ReturnType res = factory::RawDataFactory::fromString ( abstraction::retrieveValue < std::string && > ( param.first, param.second ) ); this->m_data = std::move ( res ); diff --git a/alib2raw/src/abstraction/RawWriterAbstraction.hpp b/alib2raw/src/abstraction/RawWriterAbstraction.hpp index 0f322dd53b91718186bc111de152d8ec84b5c594..768c62de8f4bc8b0658ebf7950a3c9ef120b3ad6 100644 --- a/alib2raw/src/abstraction/RawWriterAbstraction.hpp +++ b/alib2raw/src/abstraction/RawWriterAbstraction.hpp @@ -17,9 +17,6 @@ template < class ParamType > class RawWriterAbstraction : public UnaryOperationAbstraction < std::string, const ParamType & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); this->m_data = factory::RawDataFactory::toString ( abstraction::retrieveValue < const ParamType & > ( param.first, param.second ) ); return true; diff --git a/alib2str/src/abstraction/StringReaderAbstraction.hpp b/alib2str/src/abstraction/StringReaderAbstraction.hpp index 8fa35e4ddaa4f9f47d01a6cb84a766572d74e083..a37910068ad91be1bd51d69ec56f50abfe601abb 100644 --- a/alib2str/src/abstraction/StringReaderAbstraction.hpp +++ b/alib2str/src/abstraction/StringReaderAbstraction.hpp @@ -17,9 +17,6 @@ template < class ReturnType > class StringReaderAbstraction : public UnaryOperationAbstraction < ReturnType, std::string && > { public: virtual bool run ( ) override { - if ( this->isReady ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); ReturnType res = factory::StringDataFactory::fromString ( abstraction::retrieveValue < std::string && > ( param.first, param.second ) ); this->m_data = std::move ( res ); diff --git a/alib2str/src/abstraction/StringWriterAbstraction.hpp b/alib2str/src/abstraction/StringWriterAbstraction.hpp index 77a7198b41a39a9d092b0f52e71e928e40557a51..6ea7f82ec6b95354d1baf5f63532ec259a2d10a1 100644 --- a/alib2str/src/abstraction/StringWriterAbstraction.hpp +++ b/alib2str/src/abstraction/StringWriterAbstraction.hpp @@ -17,9 +17,6 @@ template < class ParamType > class StringWriterAbstraction : public UnaryOperationAbstraction < std::string, const ParamType & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); this->m_data = factory::StringDataFactory::toString ( abstraction::retrieveValue < const ParamType & > ( param.first, param.second ) ); return true; diff --git a/alib2xml/src/abstraction/XmlComposerAbstraction.hpp b/alib2xml/src/abstraction/XmlComposerAbstraction.hpp index 28699eedc36d8b04296a8d613852918e60316b62..4871cc25c5aecae4b43981efd7a2c25a8d449be9 100644 --- a/alib2xml/src/abstraction/XmlComposerAbstraction.hpp +++ b/alib2xml/src/abstraction/XmlComposerAbstraction.hpp @@ -17,9 +17,6 @@ template < class ParamType > class XmlComposerAbstraction : public UnaryOperationAbstraction < ext::deque < sax::Token >, const ParamType & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); this->m_data = factory::XmlDataFactory::toTokens ( abstraction::retrieveValue < const ParamType & > ( param.first, param.second ) ); return true; diff --git a/alib2xml/src/abstraction/XmlParserAbstraction.hpp b/alib2xml/src/abstraction/XmlParserAbstraction.hpp index d01bdac8d61404cf65da4e5872542e4de49d9aef..14748eb0134c4613b84181c54257411b8f40f2a3 100644 --- a/alib2xml/src/abstraction/XmlParserAbstraction.hpp +++ b/alib2xml/src/abstraction/XmlParserAbstraction.hpp @@ -19,9 +19,6 @@ class XmlParserAbstraction : public UnaryOperationAbstraction < ReturnType, ext: public: virtual bool run ( ) override { - if ( this->isReady ( ) ) - return true; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); ReturnType res = factory::XmlDataFactory::fromTokens ( abstraction::retrieveValue < ext::deque < sax::Token > && > ( param.first, param.second ) ); this->m_data = std::move ( res ); diff --git a/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp b/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp index f3e0a35b3376ecae5136858afe25c3600b55cab9..2da5fa59f6d1954c48daeefe9f8b08217a049175 100644 --- a/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp +++ b/alib2xml/src/abstraction/XmlTokensComposerAbstraction.hpp @@ -16,9 +16,6 @@ namespace abstraction { class XmlTokensComposerAbstraction : public BinaryOperationAbstraction < void, const ext::deque < sax::Token > &, const std::string & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param2 = std::get < 0 > ( this->m_params ); std::pair < std::shared_ptr < OperationAbstraction >, bool > & param1 = std::get < 1 > ( this->m_params ); sax::SaxComposeInterface::composeFile ( abstraction::retrieveValue < const std::string & > ( param1.first, param1.second ), abstraction::retrieveValue < const ext::deque < sax::Token > & > ( param2.first, param2.second ) ); diff --git a/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp b/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp index 5aa5e16aa2a0e38d17edd1ed00916b84a500c0f1..25c879dc60ef27d32413c83b3ea5aef43d9ec1b1 100644 --- a/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp +++ b/alib2xml/src/abstraction/XmlTokensParserAbstraction.hpp @@ -16,9 +16,6 @@ namespace abstraction { class XmlTokensParserAbstraction : public UnaryOperationAbstraction < ext::deque < sax::Token >, const std::string & > { public: virtual bool run ( ) override { - if ( ! this->inputsReady ( ) ) - return false; - std::pair < std::shared_ptr < OperationAbstraction >, bool > & param = std::get < 0 > ( this->m_params ); this->m_data = sax::SaxParseInterface::parseFile ( abstraction::retrieveValue < const std::string & > ( param.first, param.second ) ); return true;