Skip to content
Snippets Groups Projects

procedural aql

Merged Jan Trávníček requested to merge merge-jt into master
2 files
+ 14
21
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -8,63 +8,34 @@
#ifndef _VALUE_HOLDER_INTERFACE_HPP_
#define _VALUE_HOLDER_INTERFACE_HPP_
#include <abstraction/Value.hpp>
#include <abstraction/ValueInterface.hpp>
namespace abstraction {
template < class Type >
class ValueHolderInterface : public Value {
ParamQualifiers::ParamQualifierSet m_paramQualifierSet;
bool m_isTemporary;
protected:
ValueHolderInterface ( const std::shared_ptr < abstraction::OperationAbstraction > & ref, ParamQualifiers::ParamQualifierSet paramQualifierSet, bool isTemporary ) : Value ( ref ), 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." );
}
class ValueHolderInterface : public ValueInterface {
public:
virtual Type && getValue ( ) const = 0;
using ValueInterface::ValueInterface;
ParamQualifiers::ParamQualifierSet getParamQualifiersSet ( ) const {
return m_paramQualifierSet;
}
bool isConst ( ) const {
return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::CONST;
}
bool isRef ( ) const {
return isRvalueRef ( ) || isLvalueRef ( );
}
bool isRvalueRef ( ) const {
return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::RREF;
}
bool isLvalueRef ( ) const {
return m_paramQualifierSet && ParamQualifiers::ParamQualifierSet::LREF;
}
bool isTemporary ( ) const {
return m_isTemporary;
}
virtual Type && getValue ( ) const = 0;
};
template < class ParamType >
ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param, bool move ) {
(void) move;
ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param ) {
using Type = std::decay_t < ParamType >;
std::shared_ptr < ValueHolderInterface < Type > > interface = std::dynamic_pointer_cast < ValueHolderInterface < Type > > ( param->getProxyAbstraction ( ) );
if ( ! interface )
throw std::invalid_argument ( "Abstraction does not provide value of type " + ext::to_string < ParamType > ( ) + " but " + param->getType ( ) + "." );
/* if constexpr ( std::is_reference_v < ParamType > ) {
if ( interface->isTemporary ( ) && ! interface->isRef ( ) && interface->getTemporaryReferences ( ) == 0 )
throw std::domain_error ( "Taking reference to a temporary." );
}*/
if constexpr ( std::is_rvalue_reference_v < ParamType > ) {
if ( move || interface->isTemporary ( ) )
if ( interface->isTemporary ( ) )
return std::move ( interface->getValue ( ) );
else
throw std::domain_error ( "Cannot bind without move" );
@@ -77,26 +48,26 @@ ParamType retrieveValue ( const std::shared_ptr < abstraction::Value > & param,
Type && res = interface->getValue ( );
return res;
} else if constexpr ( std::is_copy_constructible_v < Type > && std::is_move_constructible_v < Type > ) {
if ( ! interface->isConst ( ) && ( move || interface->isTemporary ( ) ) )
if ( ! interface->isConst ( ) && interface->isTemporary ( ) )
return std::move ( interface->getValue ( ) );
else {
const Type & res = interface->getValue ( );
return res;
}
} else if constexpr ( std::is_copy_constructible_v < Type > && ! std::is_move_constructible_v < Type > ) {
if ( ! interface->isConst ( ) && ( move || interface->isTemporary ( ) ) )
if ( ! interface->isConst ( ) && interface->isTemporary ( ) )
throw std::domain_error ( "Value not move constructible" );
else {
Type && res = interface->getValue ( );
return res;
}
} else if constexpr ( ! std::is_copy_constructible_v < Type > && std::is_move_constructible_v < Type > ) {
if ( ! interface->isConst ( ) && ( move || interface->isTemporary ( ) ) )
if ( ! interface->isConst ( ) && interface->isTemporary ( ) )
return std::move ( interface->getValue ( ) );
else
throw std::domain_error ( "Value not copy constructible" );
} else { // ! std::is_copy_constructible_v < Type > && ! std::is_move_constructible_v < Type >
if ( ! interface->isConst ( ) && move )
if ( ! interface->isConst ( ) )
throw std::domain_error ( "Value not move constructible" );
else
throw std::domain_error ( "Value not copy constructible" );
Loading