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

Abstraction: remove isReady and inputsReady functions

parent b441900a
No related branches found
No related tags found
1 merge request!47Redesign abstraction
......@@ -51,14 +51,6 @@ public:
AnyaryOperationAbstraction ( ) {
}
 
virtual bool inputsReady ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! ( bool ) param.first || ! param.first->isReady ( ) )
return false;
return true;
}
virtual bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! ( bool ) param.first )
......
......@@ -58,14 +58,6 @@ public:
}
}
 
virtual bool inputsReady ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first || ! param.first->isReady ( ) )
return false;
return true;
}
virtual bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first )
......
......@@ -25,12 +25,10 @@ public:
virtual ~OperationAbstraction ( ) noexcept {
}
 
virtual bool inputsReady ( ) const = 0;
virtual bool inputsAttached ( ) const = 0;
virtual bool eval ( ) = 0;
virtual unsigned numberOfParams ( ) const = 0;
virtual bool cached ( ) const = 0;
virtual bool isReady ( ) const = 0;
 
virtual ext::type_index getParamTypeIndex ( unsigned index ) const = 0;
virtual ext::type_index getReturnTypeIndex ( ) const = 0;
......
......@@ -66,14 +66,6 @@ private:
return res;
}
public:
virtual bool inputsReady ( ) const override {
for ( const std::shared_ptr < abstraction::OperationAbstraction > & operation : m_abstractions )
if ( operation->inputsReady ( ) == false )
return false;
return true;
}
virtual bool inputsAttached ( ) const override {
for ( const std::shared_ptr < abstraction::OperationAbstraction > & operation : m_abstractions )
if ( operation->inputsAttached ( ) == false )
......@@ -100,10 +92,6 @@ public:
return NumberOfParams;
}
 
virtual bool isReady ( ) const override {
return m_abstractions [ m_resultId ]->isReady ( );
}
virtual bool cached ( ) const override {
return m_abstractions [ m_resultId ]->cached ( );
}
......
......@@ -38,27 +38,23 @@ protected:
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 ( ! isReady ( ) )
if ( ! cached ( ) )
m_data = abstraction::apply < ParamTypes ... > ( callback, inputs );
}
 
virtual bool isReady ( ) const override {
return ( bool ) m_data;
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( isReady ( ) )
if ( cached ( ) )
return ext::type_index ( typeid ( getData ( ) ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
}
 
virtual bool cached ( ) const override {
return isReady ( );
return ( bool ) m_data;
}
};
 
......@@ -78,27 +74,23 @@ protected:
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 ( ! isReady ( ) )
if ( ! cached ( ) )
m_data = std::reference_wrapper < ReturnType > ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
 
virtual bool isReady ( ) const override {
return ( bool ) m_data;
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( isReady ( ) )
if ( cached ( ) )
return ext::type_index ( typeid ( getData ( ) ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
}
 
virtual bool cached ( ) const override {
return isReady ( );
return ( bool ) m_data;
}
};
 
......@@ -114,27 +106,23 @@ protected:
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 ( ! isReady ( ) )
if ( ! cached ( ) )
m_data = std::reference_wrapper < const ReturnType > ( abstraction::apply < ParamTypes ... > ( callback, inputs ) );
}
 
virtual bool isReady ( ) const override {
return ( bool ) m_data;
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( isReady ( ) )
if ( cached ( ) )
return ext::type_index ( typeid ( getConstData ( ) ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
}
 
virtual bool cached ( ) const override {
return isReady ( );
return ( bool ) m_data;
}
};
 
......@@ -154,29 +142,25 @@ protected:
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 ( ! isReady ( ) ) {
if ( ! cached ( ) ) {
ReturnType && res = abstraction::apply < ParamTypes ... > ( callback, inputs );
m_data = std::reference_wrapper < ReturnType > ( res );
}
}
 
virtual bool isReady ( ) const override {
return ( bool ) m_data;
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( isReady ( ) )
if ( cached ( ) )
return ext::type_index ( typeid ( getData ( ) ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
}
 
virtual bool cached ( ) const override {
return isReady ( );
return ( bool ) m_data;
}
};
 
......@@ -192,29 +176,25 @@ protected:
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 ( ! isReady ( ) ) {
if ( ! cached ( ) ) {
const ReturnType && res = abstraction::apply < ParamTypes ... > ( callback, inputs );
m_data = std::reference_wrapper < const ReturnType > ( res );
}
}
 
virtual bool isReady ( ) const override {
return ( bool ) m_data;
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( ReturnType ) );
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( isReady ( ) )
if ( cached ( ) )
return ext::type_index ( typeid ( getConstData ( ) ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
}
 
virtual bool cached ( ) const override {
return isReady ( );
return ( bool ) m_data;
}
};
 
......@@ -226,10 +206,6 @@ public:
abstraction::apply < ParamTypes ... > ( callback, inputs );
}
 
virtual bool isReady ( ) const override {
return true;
}
virtual ext::type_index getReturnTypeIndex ( ) const override {
return ext::type_index ( typeid ( void ) );
}
......
......@@ -53,8 +53,6 @@ public:
}
 
virtual bool eval ( ) = 0;
virtual bool isReady ( ) const = 0;
};
 
template < class Type >
......@@ -72,8 +70,6 @@ public:
}
 
virtual bool eval ( ) = 0;
virtual bool isReady ( ) const = 0;
};
 
template < class Type >
......@@ -91,8 +87,6 @@ public:
}
 
virtual bool eval ( ) = 0;
virtual bool isReady ( ) const = 0;
};
 
template < class Type >
......@@ -113,8 +107,6 @@ public:
}
 
virtual bool eval ( ) = 0;
virtual bool isReady ( ) const = 0;
};
 
template < class Type >
......@@ -135,8 +127,6 @@ public:
}
 
virtual bool eval ( ) = 0;
virtual bool isReady ( ) const = 0;
};
 
} /* namespace abstraction */
......
......@@ -57,14 +57,6 @@ private:
}
 
public:
virtual bool inputsReady ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first || ! param.first->isReady ( ) )
return false;
return true;
}
virtual bool inputsAttached ( ) const override {
for ( const std::pair < std::shared_ptr < OperationAbstraction >, bool > & param : m_params )
if ( ! param.first )
......@@ -92,12 +84,8 @@ public:
return sizeof ... ( ParamTypes );
}
 
virtual bool isReady ( ) const override {
return ( bool ) m_abstraction && m_abstraction->isReady ( );
}
virtual bool cached ( ) const override {
return isReady ( );
return ( bool ) m_abstraction && m_abstraction->cached ( );
}
 
virtual ext::type_index getParamTypeIndex ( unsigned index ) const override {
......@@ -105,7 +93,7 @@ public:
}
 
virtual std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( ) override {
if ( this->isReady ( ) )
if ( this->cached ( ) )
return this->m_abstraction->getProxyAbstraction ( );
else
throw std::domain_error ( "Proxy abstraction not avaiable before evaluation." );
......@@ -142,7 +130,7 @@ public:
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( this->isReady ( ) )
if ( this->cached ( ) )
return ext::type_index ( typeid ( ReturnType ) );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
......@@ -169,7 +157,7 @@ public:
}
 
virtual ext::type_index getRuntimeReturnTypeIndex ( ) const override {
if ( this->isReady ( ) )
if ( this->cached ( ) )
return this->m_abstraction->getProxyAbstraction ( )->getRuntimeReturnTypeIndex ( );
else
throw std::domain_error ( "Runtime type unknown before evaluation." );
......
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