diff --git a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp index 9ed92590f3bd404b2e838357590bf69c0b8f7c05..f8bf3ed7322f240e5759976fd8f0e02958741b13 100644 --- a/alib2abstraction/src/abstraction/WrapperAbstraction.hpp +++ b/alib2abstraction/src/abstraction/WrapperAbstraction.hpp @@ -15,12 +15,24 @@ namespace abstraction { template < class ... ParamTypes > class BaseWrapperAbstraction : public OperationAbstraction { -protected: std::function < std::shared_ptr < OperationAbstraction > ( ParamTypes ... ) > m_WrapperFinder; std::shared_ptr < OperationAbstraction > m_abstraction; ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > m_params; +protected: + void evalAbstractionFunction ( ) { + m_abstraction = abstraction::apply < ParamTypes ... > ( m_WrapperFinder, m_params ); + } + + std::shared_ptr < OperationAbstraction > & getAbstraction ( ) { + return m_abstraction; + } + + const std::shared_ptr < OperationAbstraction > & getAbstraction ( ) const { + return m_abstraction; + } + public: BaseWrapperAbstraction ( std::function < std::shared_ptr < OperationAbstraction > ( ParamTypes ... ) > wrapperFinder ) : m_WrapperFinder ( std::move ( wrapperFinder ) ) { for ( unsigned i = 0; i < sizeof ... ( ParamTypes ); ++ i ) { @@ -123,14 +135,14 @@ public: } bool run ( ) override { - this->m_abstraction = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); + this->evalAbstractionFunction ( ); - if ( this->m_abstraction->getReturnTypeIndex ( ) != this->getReturnTypeIndex ( ) ) + if ( this->getAbstraction ( )->getReturnTypeIndex ( ) != this->getReturnTypeIndex ( ) ) throw std::domain_error ( "Expected and provided types do not match" ); this->attachInputsToAbstraction ( ); - return this->m_abstraction->eval ( ); + return this->getAbstraction ( )->eval ( ); } ext::type_index getReturnTypeIndex ( ) const override { @@ -150,23 +162,23 @@ public: } bool run ( ) override { - this->m_abstraction = abstraction::apply < ParamTypes ... > ( this->m_WrapperFinder, this->m_params ); + this->evalAbstractionFunction ( ); this->attachInputsToAbstraction ( ); - return this->m_abstraction->eval ( ); + return this->getAbstraction ( )->eval ( ); } ext::type_index getReturnTypeIndex ( ) const override { if ( this->cached ( ) ) - return this->m_abstraction->getProxyAbstraction ( )->getReturnTypeIndex ( ); + return this->getAbstraction ( )->getProxyAbstraction ( )->getReturnTypeIndex ( ); else throw std::domain_error ( "Return type unknown before evaluation." ); } ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const override { if ( this->cached ( ) ) - return this->m_abstraction->getProxyAbstraction ( )->getReturnTypeQualifiers ( ); + return this->getAbstraction ( )->getProxyAbstraction ( )->getReturnTypeQualifiers ( ); else throw std::domain_error ( "Return type qualifiers unknown before evaluation." ); }