From 7ce5a09f894869ad84ebfc4feab3603219ee60ff Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sun, 22 Dec 2019 17:32:10 +0100 Subject: [PATCH] move LazyValue under PackingAbstraction --- .../src/abstraction/PackingAbstraction.cpp | 29 +++++++ .../src/abstraction/PackingAbstraction.hpp | 79 +++++++++++++------ alib2abstraction/src/abstraction/Value.cpp | 26 ------ alib2abstraction/src/abstraction/Value.hpp | 18 ----- 4 files changed, 85 insertions(+), 67 deletions(-) diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.cpp b/alib2abstraction/src/abstraction/PackingAbstraction.cpp index bd38605bb3..d0c2f59d04 100644 --- a/alib2abstraction/src/abstraction/PackingAbstraction.cpp +++ b/alib2abstraction/src/abstraction/PackingAbstraction.cpp @@ -9,3 +9,32 @@ template class abstraction::PackingAbstraction < 2 >; template class abstraction::PackingAbstraction < 3 >; + +namespace abstraction { + +PackingAbstractionImpl::LazyValue::LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref ) : m_lifeReference ( std::move ( ref ) ) { +} + +std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool, bool ) { + throw std::domain_error ( "Feature not available on lazy value" ); +} + +ext::type_index PackingAbstractionImpl::LazyValue::getTypeIndex ( ) const { + return this->getLifeReference( )->getReturnTypeIndex ( ); +} + +abstraction::ParamQualifiers::ParamQualifierSet PackingAbstractionImpl::LazyValue::getTypeQualifiers ( ) const { + return this->getLifeReference ( )->getReturnTypeQualifiers ( ); +} + +std::shared_ptr < abstraction::Value > PackingAbstractionImpl::LazyValue::getProxyAbstraction ( ) { + if ( cache == nullptr ) + cache = this->getLifeReference ( )->eval ( ); + return cache->getProxyAbstraction ( ); +} + +const std::shared_ptr < abstraction::OperationAbstraction > & PackingAbstractionImpl::LazyValue::getLifeReference ( ) const { + return m_lifeReference; +} + +} /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/PackingAbstraction.hpp b/alib2abstraction/src/abstraction/PackingAbstraction.hpp index 69e021a0a4..776f214813 100644 --- a/alib2abstraction/src/abstraction/PackingAbstraction.hpp +++ b/alib2abstraction/src/abstraction/PackingAbstraction.hpp @@ -16,21 +16,38 @@ namespace abstraction { -template < size_t NumberOfParams > -class PackingAbstraction : public OperationAbstraction { +class PackingAbstractionImpl : public OperationAbstraction { +protected: + class LazyValue : public Value { + std::shared_ptr < Value > cache; + std::shared_ptr < abstraction::OperationAbstraction > m_lifeReference; + + public: + LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref ); + + std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary, bool move ) override; + + ext::type_index getTypeIndex ( ) const override; + + abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override; + + std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) override; + + const std::shared_ptr < abstraction::OperationAbstraction > & getLifeReference ( ) const; + }; + struct ConnectionTarget { size_t targetId; size_t paramPosition; }; - ext::vector < std::shared_ptr < abstraction::LazyValue > > m_abstractions; - ext::array < ext::vector < ConnectionTarget >, NumberOfParams > m_connections; - size_t m_resultId; +private: + ext::vector < std::shared_ptr < LazyValue > > m_abstractions; public: - PackingAbstraction ( ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > abstractions, size_t resultId ) : m_resultId ( resultId ) { + PackingAbstractionImpl ( ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > abstractions ) { for ( std::shared_ptr < abstraction::OperationAbstraction > & abstraction : abstractions ) - m_abstractions.push_back ( std::make_shared < abstraction::LazyValue > ( std::move ( abstraction ) ) ); + m_abstractions.push_back ( std::make_shared < LazyValue > ( std::move ( abstraction ) ) ); } void setInnerConnection ( size_t sourceId, size_t targetId, size_t paramPosition, bool move ) { @@ -41,15 +58,39 @@ public: m_abstractions [ targetId ]->getLifeReference ( )->detachInput ( paramPosition ); } + bool inputsAttached ( ) const override { + for ( const std::shared_ptr < LazyValue > & operation : m_abstractions ) + if ( ! operation->getLifeReference ( )->inputsAttached ( ) ) + return false; + + return true; + } + +protected: + const ext::vector < std::shared_ptr < LazyValue > > & getAbstractions ( ) const { + return m_abstractions; + } + +}; + +template < size_t NumberOfParams > +class PackingAbstraction : public PackingAbstractionImpl { + ext::array < ext::vector < ConnectionTarget >, NumberOfParams > m_connections; + size_t m_resultId; + +public: void setOuterConnection ( size_t sourceId, size_t targetId, size_t paramPosition ) { m_connections [ sourceId ].push_back ( ConnectionTarget { targetId, paramPosition } ); } + PackingAbstraction ( ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > abstractions, size_t resultId ) : PackingAbstractionImpl ( std::move ( abstractions ) ), m_resultId ( resultId ) { + } + private: void attachInput ( const std::shared_ptr < abstraction::Value > & input, size_t index, bool move ) override { try { for ( const ConnectionTarget & target : m_connections [ index ] ) - m_abstractions [ target.targetId ]->getLifeReference ( )->attachInput ( input, target.paramPosition, move ); + getAbstractions ( ) [ target.targetId ]->getLifeReference ( )->attachInput ( input, target.paramPosition, move ); } catch ( ... ) { this->detachInput ( index ); throw; @@ -58,23 +99,15 @@ private: void detachInput ( size_t index ) override { for ( const ConnectionTarget & target : m_connections [ index ] ) - m_abstractions [ target.targetId ]->getLifeReference ( )->detachInput ( target.paramPosition ); + getAbstractions ( ) [ target.targetId ]->getLifeReference ( )->detachInput ( target.paramPosition ); } public: - bool inputsAttached ( ) const override { - for ( const std::shared_ptr < abstraction::LazyValue > & operation : m_abstractions ) - if ( ! operation->getLifeReference ( )->inputsAttached ( ) ) - return false; - - return true; - } - std::shared_ptr < abstraction::Value > eval ( ) override { if ( ! inputsAttached ( ) ) return nullptr; - return m_abstractions [ m_resultId ]->getProxyAbstraction ( ); + return getAbstractions ( ) [ m_resultId ]->getProxyAbstraction ( ); } size_t numberOfParams ( ) const override { @@ -82,23 +115,23 @@ public: } ext::type_index getParamTypeIndex ( size_t index ) const override { - return m_abstractions [ m_connections.at ( index ) [ 0 ].targetId ]->getLifeReference ( )->getParamTypeIndex ( m_connections.at ( index ) [ 0 ].paramPosition ); + return getAbstractions ( ) [ m_connections.at ( index ) [ 0 ].targetId ]->getLifeReference ( )->getParamTypeIndex ( m_connections.at ( index ) [ 0 ].paramPosition ); } abstraction::ParamQualifiers::ParamQualifierSet getParamTypeQualifiers ( size_t index ) const override { - return m_abstractions [ m_connections.at ( index ) [ 0 ].targetId ]->getLifeReference ( )->getParamTypeQualifiers ( m_connections.at ( index ) [ 0 ].paramPosition ); + return getAbstractions ( ) [ m_connections.at ( index ) [ 0 ].targetId ]->getLifeReference ( )->getParamTypeQualifiers ( m_connections.at ( index ) [ 0 ].paramPosition ); } ext::type_index getReturnTypeIndex ( ) const override { - return m_abstractions [ m_resultId ]->getLifeReference ( )->getReturnTypeIndex ( ); + return getAbstractions ( ) [ m_resultId ]->getLifeReference ( )->getReturnTypeIndex ( ); } abstraction::ParamQualifiers::ParamQualifierSet getReturnTypeQualifiers ( ) const override { - return m_abstractions [ m_resultId ]->getLifeReference ( )->getReturnTypeQualifiers ( ); + return getAbstractions ( ) [ m_resultId ]->getLifeReference ( )->getReturnTypeQualifiers ( ); } std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( ) override { - return m_abstractions [ m_resultId ]->getLifeReference ( )->getProxyAbstraction ( ); + return getAbstractions ( ) [ m_resultId ]->getLifeReference ( )->getProxyAbstraction ( ); } }; diff --git a/alib2abstraction/src/abstraction/Value.cpp b/alib2abstraction/src/abstraction/Value.cpp index 548fac02fa..78e42fc415 100644 --- a/alib2abstraction/src/abstraction/Value.cpp +++ b/alib2abstraction/src/abstraction/Value.cpp @@ -31,30 +31,4 @@ abstraction::ParamQualifiers::ParamQualifierSet Void::getTypeQualifiers ( ) cons return abstraction::ParamQualifiers::paramQualifiers < void > ( ); } - -LazyValue::LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref ) : m_lifeReference ( std::move ( ref ) ) { -} - -std::shared_ptr < abstraction::Value > LazyValue::clone ( abstraction::ParamQualifiers::ParamQualifierSet, bool, bool ) { - throw std::domain_error ( "Feature not available on lazy value" ); -} - -ext::type_index LazyValue::getTypeIndex ( ) const { - return this->getLifeReference( )->getReturnTypeIndex ( ); -} - -abstraction::ParamQualifiers::ParamQualifierSet LazyValue::getTypeQualifiers ( ) const { - return this->getLifeReference ( )->getReturnTypeQualifiers ( ); -} - -std::shared_ptr < abstraction::Value > LazyValue::getProxyAbstraction ( ) { - if ( cache == nullptr ) - cache = this->getLifeReference ( )->eval ( ); - return cache->getProxyAbstraction ( ); -} - -const std::shared_ptr < abstraction::OperationAbstraction > & LazyValue::getLifeReference ( ) const { - return m_lifeReference; -} - } /* namespace abstraction */ diff --git a/alib2abstraction/src/abstraction/Value.hpp b/alib2abstraction/src/abstraction/Value.hpp index df351ba59d..c6b6f969b3 100644 --- a/alib2abstraction/src/abstraction/Value.hpp +++ b/alib2abstraction/src/abstraction/Value.hpp @@ -60,24 +60,6 @@ public: }; -class LazyValue : public Value { - std::shared_ptr < Value > cache; - std::shared_ptr < abstraction::OperationAbstraction > m_lifeReference; - -public: - LazyValue ( const std::shared_ptr < abstraction::OperationAbstraction > & ref ); - - std::shared_ptr < abstraction::Value > clone ( abstraction::ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary, bool move ) override; - - ext::type_index getTypeIndex ( ) const override; - - abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override; - - std::shared_ptr < abstraction::Value > getProxyAbstraction ( ) override; - - const std::shared_ptr < abstraction::OperationAbstraction > & getLifeReference ( ) const; -}; - } /* namespace abstraction */ #endif /* _VALUE_HPP_ */ -- GitLab