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

handling of variables in abstractions

parent 077c1cba
No related branches found
No related tags found
No related merge requests found
Showing
with 397 additions and 276 deletions
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
   
#include <alib/memory> #include <alib/memory>
   
#include <abstraction/ValueOperationAbstraction.hpp> #include <abstraction/ReturnValueOperationAbstraction.hpp>
#include <common/AbstractionHelpers.hpp> #include <common/AbstractionHelpers.hpp>
   
#include <registry/Registry.h> #include <registry/Registry.h>
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
}; };
   
template < class ReturnType, class ParamType > template < class ReturnType, class ParamType >
class AnyaryOperationAbstraction : virtual public AnyaryOperationAbstractionImpl, virtual public ValueOperationAbstraction < ReturnType > { class AnyaryOperationAbstraction : virtual public AnyaryOperationAbstractionImpl, virtual public ReturnValueOperationAbstraction < ReturnType > {
bool checkInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index ) const override { bool checkInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index ) const override {
return abstraction::checkInput < ValueInterface < std::decay_t < ParamType > > > ( input, index ); return abstraction::checkInput < ValueInterface < std::decay_t < ParamType > > > ( input, index );
} }
......
...@@ -8,90 +8,16 @@ ...@@ -8,90 +8,16 @@
#ifndef _NARY_OPERATION_ABSTRACTION_HPP_ #ifndef _NARY_OPERATION_ABSTRACTION_HPP_
#define _NARY_OPERATION_ABSTRACTION_HPP_ #define _NARY_OPERATION_ABSTRACTION_HPP_
   
#include <alib/tuple>
#include <alib/memory> #include <alib/memory>
#include <alib/array>
   
#include <abstraction/ValueOperationAbstraction.hpp> #include <abstraction/NaryOperationAbstractionImpl.hpp>
   
#include <registry/Registry.h> #include <abstraction/ReturnValueOperationAbstraction.hpp>
   
namespace abstraction { namespace abstraction {
   
template < size_t N >
class NaryOperationAbstractionImpl : virtual public OperationAbstraction {
ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, N > m_params;
protected:
ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, N > & getParams ( ) {
return m_params;
}
private:
bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index, bool move, bool checkInput ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
if ( input == nullptr )
return false;
if ( checkInput && ! this->checkInput ( input, index ) )
return false;
m_params [ index ].first = input;
m_params [ index ].second = move;
return true;
}
bool detachInput ( size_t index ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = nullptr;
m_params [ index ].second = false;
return true;
}
public:
NaryOperationAbstractionImpl ( ) {
for ( size_t i = 0; i < N; ++ i ) {
m_params [ i ].first = nullptr;
m_params [ i ].second = false;
}
}
bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first )
return false;
return true;
}
bool eval ( ) override {
if ( ! inputsAttached ( ) )
return false;
if ( this->evaluated ( ) )
return true;
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first->eval ( ) )
return false;
return this->run ( );
}
size_t numberOfParams ( ) const override {
return N;
}
};
template < class ReturnType, class ... ParamTypes > template < class ReturnType, class ... ParamTypes >
class NaryOperationAbstraction : virtual public NaryOperationAbstractionImpl < sizeof ... ( ParamTypes ) >, virtual public ValueOperationAbstraction < ReturnType > { class NaryOperationAbstraction : virtual public NaryOperationAbstractionImpl < sizeof ... ( ParamTypes ) >, virtual public ReturnValueOperationAbstraction < ReturnType > {
bool checkInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index ) const override { bool checkInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index ) const override {
return abstraction::checkInput < ValueInterface < std::decay_t < ParamTypes > > ... > ( input, index ); return abstraction::checkInput < ValueInterface < std::decay_t < ParamTypes > > ... > ( input, index );
} }
...@@ -109,9 +35,4 @@ public: ...@@ -109,9 +35,4 @@ public:
   
} /* namespace abstraction */ } /* namespace abstraction */
   
extern template class abstraction::NaryOperationAbstractionImpl < 0 >;
extern template class abstraction::NaryOperationAbstractionImpl < 1 >;
extern template class abstraction::NaryOperationAbstractionImpl < 2 >;
extern template class abstraction::NaryOperationAbstractionImpl < 3 >;
#endif /* _NARY_OPERATION_ABSTRACTION_HPP_ */ #endif /* _NARY_OPERATION_ABSTRACTION_HPP_ */
/* /*
* NaryOperationAbstraction.hpp * NaryOperationAbstractionImpl.hpp
* *
* Created on: 20. 8. 2017 * Created on: 20. 8. 2017
* Author: Jan Travnicek * Author: Jan Travnicek
*/ */
   
#include "NaryOperationAbstraction.hpp" #include "NaryOperationAbstractionImpl.hpp"
   
template class abstraction::NaryOperationAbstractionImpl < 0 >; template class abstraction::NaryOperationAbstractionImpl < 0 >;
template class abstraction::NaryOperationAbstractionImpl < 1 >; template class abstraction::NaryOperationAbstractionImpl < 1 >;
......
/*
* NaryOperationAbstractionImpl.hpp
*
* Created on: 20. 8. 2017
* Author: Jan Travnicek
*/
#ifndef _NARY_OPERATION_ABSTRACTION_IMPL_HPP_
#define _NARY_OPERATION_ABSTRACTION_IMPL_HPP_
#include <alib/memory>
#include <alib/array>
#include <abstraction/OperationAbstraction.hpp>
namespace abstraction {
template < size_t N >
class NaryOperationAbstractionImpl : virtual public OperationAbstraction {
ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, N > m_params;
protected:
ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, N > & getParams ( ) {
return m_params;
}
private:
bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index, bool move, bool checkInput ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
if ( input == nullptr )
return false;
if ( checkInput && ! this->checkInput ( input, index ) )
return false;
m_params [ index ].first = input;
m_params [ index ].second = move;
return true;
}
bool detachInput ( size_t index ) override {
if ( index >= m_params.size ( ) )
throw std::invalid_argument ( "Parameter index " + ext::to_string ( index ) + " out of bounds.");
m_params [ index ].first = nullptr;
m_params [ index ].second = false;
return true;
}
public:
NaryOperationAbstractionImpl ( ) {
for ( size_t i = 0; i < N; ++ i ) {
m_params [ i ].first = nullptr;
m_params [ i ].second = false;
}
}
bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first )
return false;
return true;
}
bool eval ( ) override {
if ( ! inputsAttached ( ) )
return false;
if ( this->evaluated ( ) )
return true;
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first->eval ( ) )
return false;
return this->run ( );
}
size_t numberOfParams ( ) const override {
return N;
}
};
} /* namespace abstraction */
extern template class abstraction::NaryOperationAbstractionImpl < 0 >;
extern template class abstraction::NaryOperationAbstractionImpl < 1 >;
extern template class abstraction::NaryOperationAbstractionImpl < 2 >;
extern template class abstraction::NaryOperationAbstractionImpl < 3 >;
#endif /* _NARY_OPERATION_ABSTRACTION_IMPL_HPP_ */
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
virtual ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const = 0; virtual ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const = 0;
   
virtual std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( ); virtual std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( );
virtual std::shared_ptr < abstraction::OperationAbstraction > getVariableOperationAbstraction ( ) = 0;
}; };
   
} /* namespace abstraction */ } /* namespace abstraction */
......
...@@ -124,6 +124,10 @@ public: ...@@ -124,6 +124,10 @@ public:
return m_abstractions [ m_resultId ]->getProxyAbstraction ( ); return m_abstractions [ m_resultId ]->getProxyAbstraction ( );
} }
   
std::shared_ptr < abstraction::OperationAbstraction > getVariableOperationAbstraction ( ) override {
return m_abstractions [ m_resultId ]->getProxyAbstraction ( )->getVariableOperationAbstraction ( );
}
}; };
   
} /* namespace abstraction */ } /* namespace abstraction */
......
...@@ -8,163 +8,11 @@ ...@@ -8,163 +8,11 @@
#ifndef _VALUE_OPERATION_ABSTRACTION_HPP_ #ifndef _VALUE_OPERATION_ABSTRACTION_HPP_
#define _VALUE_OPERATION_ABSTRACTION_HPP_ #define _VALUE_OPERATION_ABSTRACTION_HPP_
   
#include <alib/tuple>
#include <alib/memory>
#include <abstraction/ValueInterface.hpp>
#include <common/ParamQualifiers.hpp> #include <common/ParamQualifiers.hpp>
#include <common/AbstractionHelpers.hpp>
   
namespace abstraction { #include <abstraction/ValueOperationAbstractionImpl.hpp>
template < class ReturnType >
class ValueOperationAbstractionImpl : virtual public ValueInterface < ReturnType > {
mutable std::optional < ReturnType > m_data;
protected:
void setData ( ReturnType && data ) {
m_data = std::move ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data.value ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < const ReturnType > : virtual public ValueInterface < ReturnType > {
mutable std::optional < ReturnType > m_data;
protected:
void setData ( ReturnType && data ) {
m_data = std::move ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data.value ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < ReturnType & > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( ReturnType & data ) {
m_data = std::reference_wrapper < ReturnType > ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < const ReturnType & > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( const ReturnType & data ) {
m_data = std::reference_wrapper < ReturnType > ( const_cast < ReturnType & > ( data ) );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
   
public: namespace abstraction {
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < ReturnType && > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( ReturnType && data ) {
m_data = std::reference_wrapper < ReturnType > ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < const ReturnType && > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( const ReturnType && data ) {
m_data = std::reference_wrapper < ReturnType > ( const_cast < ReturnType & > ( data ) );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
   
template < class ReturnType > template < class ReturnType >
class ValueOperationAbstraction : virtual public ValueOperationAbstractionImpl < ReturnType > { class ValueOperationAbstraction : virtual public ValueOperationAbstractionImpl < ReturnType > {
...@@ -180,37 +28,12 @@ class ValueOperationAbstraction : virtual public ValueOperationAbstractionImpl < ...@@ -180,37 +28,12 @@ class ValueOperationAbstraction : virtual public ValueOperationAbstractionImpl <
return std::is_lvalue_reference_v < ReturnType >; return std::is_lvalue_reference_v < ReturnType >;
} }
   
bool isAutoMove ( ) const override {
return false;
}
public: public:
ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const override { ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const override {
return abstraction::ParamQualifiers::paramQualifiers < ReturnType > ( ); return abstraction::ParamQualifiers::paramQualifiers < ReturnType > ( );
} }
}; };
   
template < >
class ValueOperationAbstraction < void > : virtual public OperationAbstraction {
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
abstraction::apply < ParamTypes ... > ( callback, inputs );
}
ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( void ) );
}
ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const override {
return abstraction::ParamQualifiers::paramQualifiers < void > ( );
}
bool evaluated ( ) const override {
return false;
}
};
} /* namespace abstraction */ } /* namespace abstraction */
   
#endif /* _VALUE_OPERATION_ABSTRACTION_HPP_ */ #endif /* _VALUE_OPERATION_ABSTRACTION_HPP_ */
/*
* ValueOperationAbstractionImpl.hpp
*
* Created on: 11. 7. 2017
* Author: Jan Travnicek
*/
#ifndef _VALUE_OPERATION_ABSTRACTION_IMPL_HPP_
#define _VALUE_OPERATION_ABSTRACTION_IMPL_HPP_
#include <alib/memory>
#include <abstraction/ValueInterface.hpp>
#include <common/AbstractionHelpers.hpp>
namespace abstraction {
template < class ReturnType >
class ValueOperationAbstractionImpl : virtual public ValueInterface < ReturnType > {
mutable std::optional < ReturnType > m_data;
protected:
void setData ( ReturnType && data ) {
m_data = std::move ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data.value ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < const ReturnType > : virtual public ValueInterface < ReturnType > {
mutable std::optional < ReturnType > m_data;
protected:
void setData ( ReturnType && data ) {
m_data = std::move ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data.value ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < ReturnType & > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( ReturnType & data ) {
m_data = std::reference_wrapper < ReturnType > ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < const ReturnType & > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( const ReturnType & data ) {
m_data = std::reference_wrapper < ReturnType > ( const_cast < ReturnType & > ( data ) );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < ReturnType && > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( ReturnType && data ) {
m_data = std::reference_wrapper < ReturnType > ( data );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
template < class ReturnType >
class ValueOperationAbstractionImpl < const ReturnType && > : virtual public ValueInterface < ReturnType > {
mutable std::optional < std::reference_wrapper < ReturnType > > m_data;
protected:
void setData ( const ReturnType && data ) {
m_data = std::reference_wrapper < ReturnType > ( const_cast < ReturnType & > ( data ) );
}
ReturnType && getValue ( ) const override {
return std::move ( m_data->get ( ) );
}
public:
template < typename ... ParamTypes, typename Callable >
inline void run_helper ( Callable callback, const ext::array < std::pair < std::shared_ptr < OperationAbstraction >, bool >, sizeof ... ( ParamTypes ) > & inputs ) {
if ( ! evaluated ( ) )
setData ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
bool evaluated ( ) const override {
return ( bool ) m_data;
}
};
} /* namespace abstraction */
#endif /* _VALUE_OPERATION_ABSTRACTION_IMPL_HPP_ */
/*
* VariableOperationAbstraction.hpp
*
* Created on: 11. 7. 2017
* Author: Jan Travnicek
*/
#ifndef _VARIABLE_OPERATION_ABSTRACTION_HPP_
#define _VARIABLE_OPERATION_ABSTRACTION_HPP_
#include <alib/memory>
#include <alib/typeindex>
#include <abstraction/NaryOperationAbstractionImpl.hpp>
#include <abstraction/ValueOperationAbstraction.hpp>
#include <common/ParamQualifiers.hpp>
namespace abstraction {
template < class Type >
class VariableOperationAbstraction : virtual public NaryOperationAbstractionImpl < 1 >, virtual public ValueOperationAbstraction < Type > {
bool isAutoMove ( ) const override {
return false;
}
bool checkInput ( const std::shared_ptr < OperationAbstraction > & input, size_t index ) const override {
return abstraction::checkInput < ValueInterface < Type > > ( input, index );
}
public:
bool run ( ) override {
this->template run_helper < Type > ( []( Type value ) -> Type { return std::forward < Type > ( value ); }, this->getParams ( ) );
return true;
}
ext::type_index getParamTypeIndex ( size_t index ) const override {
return abstraction::paramType < Type > ( index );
}
ext::set < abstraction::ParamQualifiers::ParamQualifier > getParamTypeQualifiers ( size_t index ) const override {
return abstraction::paramTypeQualifiers < Type > ( index );
}
std::shared_ptr < abstraction::OperationAbstraction > getVariableOperationAbstraction ( ) override {
std::shared_ptr < abstraction::OperationAbstraction > res = std::make_shared < abstraction::VariableOperationAbstraction < Type > > ( );
res->attachInput ( this->getProxyAbstraction ( ), 0, false, false );
return res;
}
};
} /* namespace abstraction */
#endif /* _VARIABLE_OPERATION_ABSTRACTION_HPP_ */
...@@ -129,6 +129,13 @@ public: ...@@ -129,6 +129,13 @@ public:
throw std::domain_error ( "Proxy abstraction not avaiable before evaluation." ); throw std::domain_error ( "Proxy abstraction not avaiable before evaluation." );
} }
   
std::shared_ptr < abstraction::OperationAbstraction > getVariableOperationAbstraction ( ) override {
if ( this->evaluated ( ) )
return this->getAbstraction ( )->getProxyAbstraction ( )->getVariableOperationAbstraction ( );
else
throw std::domain_error ( "Variable deduction not available before evaluation." );
}
}; };
   
template < class ReturnType, class ... ParamTypes > template < class ReturnType, class ... ParamTypes >
......
...@@ -101,6 +101,32 @@ public: ...@@ -101,6 +101,32 @@ public:
   
}; };
   
template < class Algorithm, class ReturnType, class ObjectType, class ... ParameterTypes >
class MethodRegister < Algorithm, ReturnType, const ObjectType, ParameterTypes ... > : public ext::Register < void > {
registration::NormalizationRegister < ReturnType > normalize;
std::string m_methodName;
public:
template < class ... ParamNames >
MethodRegister ( ReturnType ( ObjectType::* callback ) ( ParameterTypes ... ) const, std::string methodName, ParamNames ... paramNames ) : ext::Register < void > ( [=] ( ) {
std::array < std::string, sizeof ... ( ParameterTypes ) > parameterNames = AlgoRegisterHelper::generateNames < sizeof ... ( ParameterTypes ) > ( paramNames ... );
abstraction::AlgorithmRegistry::registerMethod < Algorithm > ( callback, methodName, std::move ( parameterNames ) );
}, [=] ( ) {
abstraction::AlgorithmRegistry::unregisterMethod < Algorithm, const ObjectType, ParameterTypes ... > ( methodName );
} ), m_methodName ( methodName ) {
}
MethodRegister ( MethodRegister && ) noexcept = default;
MethodRegister && setDocumentation ( std::string documentation ) && {
abstraction::AlgorithmRegistry::setDocumentationOfMethod < Algorithm, const ObjectType, ParameterTypes ... > ( m_methodName, std::move ( documentation ) );
return std::move ( * this );
}
};
} /* namespace registration */ } /* namespace registration */
   
#endif // _ALGO_REGISTRATION_HPP_ #endif // _ALGO_REGISTRATION_HPP_
...@@ -169,7 +169,7 @@ std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbst ...@@ -169,7 +169,7 @@ std::shared_ptr < abstraction::OperationAbstraction > AlgorithmRegistry::getAbst
return compatibilityData [ * winner.begin ( ) ].second->getAbstraction ( ); return compatibilityData [ * winner.begin ( ) ].second->getAbstraction ( );
} else if ( winner.size ( ) > 1 ) { } else if ( winner.size ( ) > 1 ) {
// throw std::invalid_argument ( "Entry overload " + ext::to_string ( paramTypes ) + " ambiguous." ); FIXME make better overload select algorithm // throw std::invalid_argument ( "Entry overload " + ext::to_string ( paramTypes ) + " ambiguous." ); FIXME make better overload select algorithm
return compatibilityData [ * winner.begin ( ) ].second->getAbstraction ( ); return compatibilityData [ * std::next ( winner.begin ( ) ) ].second->getAbstraction ( ); // FIXME terrible hack to get to const variant of get on datastructures...
   
/* if(common::GlobalData::verbose) /* if(common::GlobalData::verbose)
common::Streams::err << "Entry overload " + ss.str ( ) + " ambiguous. First selected." << std::endl;*/ common::Streams::err << "Entry overload " + ss.str ( ) + " ambiguous. First selected." << std::endl;*/
......
...@@ -113,7 +113,7 @@ public: ...@@ -113,7 +113,7 @@ public:
std::string algorithm = ext::to_string < Algo > ( ) + "::" + methodName; std::string algorithm = ext::to_string < Algo > ( ) + "::" + methodName;
ext::vector < std::string > templateParams; ext::vector < std::string > templateParams;
   
setDocumentation ( algorithm, templateParams, AlgorithmBaseInfo::methodEntryInfo < ObjectType, ParamTypes ... > ( ), documentation ); setDocumentation ( algorithm, templateParams, AlgorithmBaseInfo::methodEntryInfo < ObjectType &, ParamTypes ... > ( ), documentation );
} }
   
template < class Algo, class ... ParamTypes > template < class Algo, class ... ParamTypes >
...@@ -139,7 +139,7 @@ public: ...@@ -139,7 +139,7 @@ public:
std::string algorithm = ext::to_string < Algo > ( ) + "::" + methodName; std::string algorithm = ext::to_string < Algo > ( ) + "::" + methodName;
ext::vector < std::string > templateParams; ext::vector < std::string > templateParams;
   
unregisterInternal ( algorithm, templateParams, AlgorithmBaseInfo::methodEntryInfo < ObjectType, ParamTypes ... > ( ) ); unregisterInternal ( algorithm, templateParams, AlgorithmBaseInfo::methodEntryInfo < ObjectType &, ParamTypes ... > ( ) );
} }
   
template < class Algo, class ... ParamTypes > template < class Algo, class ... ParamTypes >
......
...@@ -13,8 +13,10 @@ public: ...@@ -13,8 +13,10 @@ public:
} }
   
std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override { std::shared_ptr < abstraction::OperationAbstraction > translateAndEval ( const std::shared_ptr < abstraction::OperationAbstraction > & prev, Environment & environment ) const override {
environment.setVariable ( m_name->eval ( environment ), prev ); std::shared_ptr < abstraction::OperationAbstraction > res = prev->getVariableOperationAbstraction ( );
return prev; res->eval ( );
environment.setVariable ( m_name->eval ( environment ), res );
return res;
} }
   
bool getImplicitMove ( ) const override { bool getImplicitMove ( ) const override {
......
...@@ -15,11 +15,11 @@ class Foo { ...@@ -15,11 +15,11 @@ class Foo {
Foo ( int base ) : m_base ( base ) { Foo ( int base ) : m_base ( base ) {
} }
   
int bar ( int value ) { int bar ( int value ) const {
return m_base + value; return m_base + value;
} }
   
int base ( ) { int base ( ) const {
return m_base; return m_base;
} }
   
...@@ -29,7 +29,7 @@ class Foo { ...@@ -29,7 +29,7 @@ class Foo {
}; };
   
namespace { namespace {
auto fooBar = registration::MethodRegister < Foo, int, Foo, int > ( & Foo::bar, "bar" ); auto fooBar = registration::MethodRegister < Foo, int, const Foo, int > ( & Foo::bar, "bar" );
} /* namespace */ } /* namespace */
   
   
...@@ -163,6 +163,7 @@ TEST_CASE ( "Cli", "[unit][cli]" ) { ...@@ -163,6 +163,7 @@ TEST_CASE ( "Cli", "[unit][cli]" ) {
public: public:
static void bar ( std::unique_ptr < int > && out ) { static void bar ( std::unique_ptr < int > && out ) {
target = std::move ( out ); target = std::move ( out );
out = nullptr;
} }
}; };
   
...@@ -174,18 +175,33 @@ TEST_CASE ( "Cli", "[unit][cli]" ) { ...@@ -174,18 +175,33 @@ TEST_CASE ( "Cli", "[unit][cli]" ) {
source = std::make_unique < int > ( 1 ); source = std::make_unique < int > ( 1 );
cli::Environment environment; cli::Environment environment;
cli::Parser parser ( cli::Lexer ( "execute RvalueReferenceProvider | RvalueReferenceAcceptor - >" ) ); cli::Parser parser ( cli::Lexer ( "execute RvalueReferenceProvider | RvalueReferenceAcceptor - >" ) );
CHECK_THROWS ( parser.parse ( )->run ( environment ) ); CHECK_NOTHROW ( parser.parse ( )->run ( environment ) );
} }
   
CHECK ( * target == 1 );
CHECK ( source == nullptr );
{ {
source = std::make_unique < int > ( 1 ); source = std::make_unique < int > ( 1 );
cli::Environment environment; cli::Environment environment;
cli::Parser parser ( cli::Lexer ( "execute RvalueReferenceProvider | RvalueReferenceAcceptor ^ - >" ) ); cli::Parser parser ( cli::Lexer ( "execute RvalueReferenceProvider > $tmp" ) );
CHECK_NOTHROW ( parser.parse ( )->run ( environment ) );
parser = cli::Parser ( cli::Lexer ( "execute $tmp | RvalueReferenceAcceptor ^ - >" ) );
CHECK_NOTHROW ( parser.parse ( )->run ( environment ) ); CHECK_NOTHROW ( parser.parse ( )->run ( environment ) );
} }
   
CHECK ( * target == 1 ); CHECK ( * target == 1 );
CHECK ( source == nullptr ); /* implementation specific */ CHECK ( source == nullptr );
{
source = std::make_unique < int > ( 1 );
cli::Environment environment;
cli::Parser parser ( cli::Lexer ( "execute RvalueReferenceProvider > $tmp" ) );
CHECK_NOTHROW ( parser.parse ( )->run ( environment ) );
parser = cli::Parser ( cli::Lexer ( "execute $tmp | RvalueReferenceAcceptor - >" ) );
CHECK_THROWS ( parser.parse ( )->run ( environment ) );
}
} }
   
class ConstReferenceProvider { class ConstReferenceProvider {
......
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