From 91113e482be10cd8eacca3b0606b2560d687e767 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Sat, 28 Dec 2019 16:30:17 +0100 Subject: [PATCH] unify type qualifiers in abstraction value --- .../src/abstraction/ValueHolder.hpp | 17 ++++++++++------- .../src/abstraction/ValueInterface.hpp | 18 ++++-------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/alib2abstraction/src/abstraction/ValueHolder.hpp b/alib2abstraction/src/abstraction/ValueHolder.hpp index 88cb61a23d..7c2b5ef027 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 9b908c3ee5..7c3d54f1cd 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 */ -- GitLab