diff --git a/alib2abstraction/src/abstraction/ValueHolder.hpp b/alib2abstraction/src/abstraction/ValueHolder.hpp index 88cb61a23d066958feeb5cbc961c1a23a78b0712..7c2b5ef0275dcd52b0667e55a55bfb87eac294fa 100644 --- a/alib2abstraction/src/abstraction/ValueHolder.hpp +++ b/alib2abstraction/src/abstraction/ValueHolder.hpp @@ -114,7 +114,10 @@ public: template < class Type > class ValueHolder : public ValueHolderImpl < Type > { public: - ValueHolder ( Type && value, bool temporary ) : ValueHolderImpl < Type > ( ParamQualifiers::paramQualifiers < Type > ( ), temporary ) { + ValueHolder ( Type && value, bool temporary ) : ValueHolderImpl < Type > ( temporary ) { + if ( this->isLvalueRef ( ) && this->isTemporary ( ) ) + throw std::domain_error ( "Lvalue references cannot be a temporarie." ); + this->setData ( std::forward < Type > ( value ) ); } @@ -123,21 +126,21 @@ public: throw std::domain_error ( "Taking reference to a temporary" );*/ if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) && ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF ) ) - return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > & > > ( retrieveValue < const std::decay_t < Type > & > ( this->getProxyAbstraction ( ), move ), isTemporary ); + return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > & > > ( retrieveValue < const std::decay_t < Type > & > ( this->shared_from_this ( ), move ), isTemporary ); else if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) && ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF ) ) - return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > && > > ( retrieveValue < const std::decay_t < Type > && > ( this->getProxyAbstraction ( ), move ), isTemporary ); + return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > && > > ( retrieveValue < const std::decay_t < Type > && > ( this->shared_from_this ( ), move ), isTemporary ); else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF ) - return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > & > > ( retrieveValue < std::decay_t < Type > & > ( this->getProxyAbstraction ( ), move ), isTemporary ); + return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > & > > ( retrieveValue < std::decay_t < Type > & > ( this->shared_from_this ( ), move ), isTemporary ); else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF ) - return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > && > > ( retrieveValue < std::decay_t < Type > && > ( this->getProxyAbstraction ( ), move ), isTemporary ); + return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > && > > ( retrieveValue < std::decay_t < Type > && > ( this->shared_from_this ( ), move ), isTemporary ); else if constexpr ( std::is_abstract_v < std::decay_t < Type > > ) throw std::domain_error ( "Cannot declare value of abstract class." ); else if constexpr ( ! std::is_assignable_v < std::decay_t < Type > &, std::decay_t < Type > > ) throw std::domain_error ( "Cannot assign value." ); else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) - return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > > > ( retrieveValue < const std::decay_t < Type > > ( this->getProxyAbstraction ( ), move ), isTemporary ); + return std::make_shared < abstraction::ValueHolder < const std::decay_t < Type > > > ( retrieveValue < const std::decay_t < Type > > ( this->shared_from_this ( ), move ), isTemporary ); else - return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->getProxyAbstraction ( ), move ), isTemporary ); + return std::make_shared < abstraction::ValueHolder < std::decay_t < Type > > > ( retrieveValue < std::decay_t < Type > > ( this->shared_from_this ( ), move ), isTemporary ); } abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override { diff --git a/alib2abstraction/src/abstraction/ValueInterface.hpp b/alib2abstraction/src/abstraction/ValueInterface.hpp index 9b908c3ee5e77bec37a559e7c5be79f78dbbdddd..7c3d54f1cd2d0fe5b6c21e67492871242549d173 100644 --- a/alib2abstraction/src/abstraction/ValueInterface.hpp +++ b/alib2abstraction/src/abstraction/ValueInterface.hpp @@ -13,24 +13,15 @@ namespace abstraction { class ValueInterface : public Value { - ParamQualifiers::ParamQualifierSet m_paramQualifierSet; bool m_isTemporary; protected: - ValueInterface ( ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) : m_paramQualifierSet ( paramQualifierSet ), m_isTemporary ( isTemporary ) { - if ( this->isLvalueRef ( ) && this->isTemporary ( ) ) - throw std::domain_error ( "Lvalue references cannot be a temporarie." ); - if ( this->isLvalueRef ( ) && this->isRvalueRef ( ) ) - throw std::domain_error ( "A reference cannot be both, rvalue and lvalue." ); + ValueInterface ( bool isTemporary ) : m_isTemporary ( isTemporary ) { } public: - ParamQualifiers::ParamQualifierSet getParamQualifiersSet ( ) const { - return m_paramQualifierSet; - } - bool isConst ( ) const { - return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST; + return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::CONST; } bool isRef ( ) const { @@ -38,17 +29,16 @@ public: } bool isRvalueRef ( ) const { - return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF; + return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::RREF; } bool isLvalueRef ( ) const { - return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF; + return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::LREF; } bool isTemporary ( ) const { return m_isTemporary; } - }; } /* namespace abstraction */