Skip to content
Snippets Groups Projects
Commit 91113e48 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

unify type qualifiers in abstraction value

parent a38b84ea
No related branches found
No related tags found
1 merge request!125procedural aql
...@@ -114,7 +114,10 @@ public: ...@@ -114,7 +114,10 @@ public:
template < class Type > template < class Type >
class ValueHolder : public ValueHolderImpl < Type > { class ValueHolder : public ValueHolderImpl < Type > {
public: 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 ) ); this->setData ( std::forward < Type > ( value ) );
} }
   
...@@ -123,21 +126,21 @@ public: ...@@ -123,21 +126,21 @@ public:
throw std::domain_error ( "Taking reference to a temporary" );*/ throw std::domain_error ( "Taking reference to a temporary" );*/
   
if ( ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) && ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF ) ) 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 ) ) 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 ) 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 ) 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 > > ) else if constexpr ( std::is_abstract_v < std::decay_t < Type > > )
throw std::domain_error ( "Cannot declare value of abstract class." ); 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 > > ) else if constexpr ( ! std::is_assignable_v < std::decay_t < Type > &, std::decay_t < Type > > )
throw std::domain_error ( "Cannot assign value." ); throw std::domain_error ( "Cannot assign value." );
else if ( paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST ) 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 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 { abstraction::ParamQualifiers::ParamQualifierSet getTypeQualifiers ( ) const override {
......
...@@ -13,24 +13,15 @@ ...@@ -13,24 +13,15 @@
namespace abstraction { namespace abstraction {
   
class ValueInterface : public Value { class ValueInterface : public Value {
ParamQualifiers::ParamQualifierSet m_paramQualifierSet;
bool m_isTemporary; bool m_isTemporary;
   
protected: protected:
ValueInterface ( ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) : m_paramQualifierSet ( paramQualifierSet ), m_isTemporary ( isTemporary ) { ValueInterface ( bool isTemporary ) : 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." );
} }
   
public: public:
ParamQualifiers::ParamQualifierSet getParamQualifiersSet ( ) const {
return m_paramQualifierSet;
}
bool isConst ( ) const { bool isConst ( ) const {
return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST; return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::CONST;
} }
   
bool isRef ( ) const { bool isRef ( ) const {
...@@ -38,17 +29,16 @@ public: ...@@ -38,17 +29,16 @@ public:
} }
   
bool isRvalueRef ( ) const { bool isRvalueRef ( ) const {
return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF; return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::RREF;
} }
   
bool isLvalueRef ( ) const { bool isLvalueRef ( ) const {
return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF; return getTypeQualifiers ( ) && ParamQualifiers::ParamQualifierSet::LREF;
} }
   
bool isTemporary ( ) const { bool isTemporary ( ) const {
return m_isTemporary; return m_isTemporary;
} }
}; };
   
} /* namespace abstraction */ } /* namespace abstraction */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment