diff --git a/alib2common/src/abstraction/AlgorithmAbstraction.hpp b/alib2common/src/abstraction/AlgorithmAbstraction.hpp index 2c95d014543bda18ca01d23ba6eee0dad4e7026e..7b6b993bec77e9d59facb36ec1bc87f7e69106f3 100644 --- a/alib2common/src/abstraction/AlgorithmAbstraction.hpp +++ b/alib2common/src/abstraction/AlgorithmAbstraction.hpp @@ -30,7 +30,7 @@ public: if ( this->cached ( ) ) return true; - this->run_helper ( m_callback, this->inputs, std::make_index_sequence < sizeof ... ( ParamTypes ) > { } ); + this->run_helper ( m_callback, this->m_params, std::make_index_sequence < sizeof ... ( ParamTypes ) > { } ); return true; } diff --git a/alib2common/src/abstraction/CastAbstraction.hpp b/alib2common/src/abstraction/CastAbstraction.hpp index a92b875d976e443a7999548975a976554486987a..5fc7947d9cb275b48f794df77925dfd1d6d3e0a7 100644 --- a/alib2common/src/abstraction/CastAbstraction.hpp +++ b/alib2common/src/abstraction/CastAbstraction.hpp @@ -26,7 +26,7 @@ public: if ( this->cached ( ) ) return true; - this->m_data = ReturnType ( this->m_param->getConstValueReference ( ) ); + this->m_data = ReturnType ( std::get < 0 > ( this->m_params )->getConstValueReference ( ) ); return true; } diff --git a/alib2common/src/abstraction/DowncastAbstraction.hpp b/alib2common/src/abstraction/DowncastAbstraction.hpp index 386c7ea22d36aad9e0fe1d8056e1cdeea9aa6714..91b15da440ddbba9d517f514708343f7a5dfeac7 100644 --- a/alib2common/src/abstraction/DowncastAbstraction.hpp +++ b/alib2common/src/abstraction/DowncastAbstraction.hpp @@ -26,7 +26,7 @@ public: if ( this->cached ( ) ) return true; - this->m_data = ConcreteType ( static_cast < const ConcreteType & > ( this->m_param->getConstValueReference ( ) ) ); + this->m_data = ConcreteType ( static_cast < const ConcreteType & > ( std::get < 0 > ( this->m_params )->getConstValueReference ( ) ) ); return true; } diff --git a/alib2common/src/abstraction/NaryOperationAbstraction.hpp b/alib2common/src/abstraction/NaryOperationAbstraction.hpp index 8da97cccc0d725e49af1601245c7c3ee529e9caf..7f3a55f02675eea4690d756f1b1bcb57fd89c1e2 100644 --- a/alib2common/src/abstraction/NaryOperationAbstraction.hpp +++ b/alib2common/src/abstraction/NaryOperationAbstraction.hpp @@ -18,7 +18,7 @@ namespace abstraction { template < class ReturnType, class ... ParamTypes > class NaryOperationAbstraction : public ValueOperationAbstraction < ReturnType > { protected: - ext::tuple < std::shared_ptr < ValueProvider < ParamTypes > > ... > inputs; + ext::tuple < std::shared_ptr < ValueProvider < ParamTypes > > ... > m_params; private: virtual bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, unsigned index ) override { @@ -34,7 +34,7 @@ private: return false; } }; - return ext::call_on_nth < bool > ( inputs, index, attachCallback ); + return ext::call_on_nth < bool > ( m_params, index, attachCallback ); } virtual bool detachInput ( unsigned index ) override { @@ -42,19 +42,16 @@ private: param = nullptr; return true; }; - return ext::call_on_nth < bool > ( inputs, index, detachCallback ); + return ext::call_on_nth < bool > ( m_params, index, detachCallback ); } public: - NaryOperationAbstraction ( ) { - } - virtual bool inputsReady ( ) const override { auto readyCallback = [ ] ( const auto & param ) { return ( bool ) param && param->isReady ( ); }; - return ext::all_of ( inputs, readyCallback ); + return ext::all_of ( m_params, readyCallback ); } virtual bool inputsAttached ( ) const override { @@ -62,7 +59,7 @@ public: return ( bool ) param; }; - return ext::all_of ( inputs, attachedCallback ); + return ext::all_of ( m_params, attachedCallback ); } virtual bool eval ( ) override { @@ -76,7 +73,7 @@ public: return param->eval ( ); }; - if ( ! ext::all_of ( inputs, evalCallback ) ) + if ( ! ext::all_of ( m_params, evalCallback ) ) return false; return this->run ( ); @@ -90,7 +87,7 @@ public: auto callback = [ & ] ( auto & param ) { return ext::type_index ( typeid ( typename std::decay < decltype ( param ) >::type::element_type::return_type ) ); }; - return ext::call_on_nth < ext::type_index > ( inputs, index, callback ); + return ext::call_on_nth < ext::type_index > ( m_params, index, callback ); } }; diff --git a/alib2common/src/abstraction/NormalizeAbstraction.hpp b/alib2common/src/abstraction/NormalizeAbstraction.hpp index 58caf4295f90af388cba1244250c4a94342f876e..ce775fffa485f1b0dbac7350b5d676e3eed083fd 100644 --- a/alib2common/src/abstraction/NormalizeAbstraction.hpp +++ b/alib2common/src/abstraction/NormalizeAbstraction.hpp @@ -26,7 +26,7 @@ public: if ( this->cached ( ) ) return true; - this->m_data = ReturnType ( * std::unique_ptr < ReturnType > ( static_cast < ReturnType * > ( std::move ( this->m_param->getValue ( ) ).normalize ( ) ) ) ); + this->m_data = ReturnType ( * std::unique_ptr < ReturnType > ( static_cast < ReturnType * > ( std::move ( std::get < 0 > ( this->m_params )->getValue ( ) ).normalize ( ) ) ) ); return true; } diff --git a/alib2common/src/abstraction/NullaryOperationAbstraction.hpp b/alib2common/src/abstraction/NullaryOperationAbstraction.hpp index d0a4ec6fb82bb45c4ac4399727147e909aa0e4b8..8c5df82ee742f3e832fadaa1fc6c9234e15d8b9c 100644 --- a/alib2common/src/abstraction/NullaryOperationAbstraction.hpp +++ b/alib2common/src/abstraction/NullaryOperationAbstraction.hpp @@ -8,48 +8,12 @@ #ifndef _NULLARY_OPERATION_ABSTRACTION_HPP_ #define _NULLARY_OPERATION_ABSTRACTION_HPP_ -#include <abstraction/ValueOperationAbstraction.hpp> -#include <exception/CommonException.h> +#include <abstraction/NaryOperationAbstraction.hpp> namespace abstraction { template < class ReturnType > -class NullaryOperationAbstraction : public ValueOperationAbstraction < ReturnType > { - virtual bool attachInput ( const std::shared_ptr < OperationAbstraction > &, unsigned ) override { - return false; - } - - virtual bool detachInput ( unsigned ) override { - return true; - } - -public: - NullaryOperationAbstraction ( ) { - } - - virtual bool inputsReady ( ) const override { - return true; - } - - virtual bool inputsAttached ( ) const override { - return true; - } - - virtual bool eval ( ) override { - if ( this->cached ( ) ) - return true; - - return this->run ( ); - } - - virtual unsigned numberOfParams ( ) const override { - return 0; - } - - virtual ext::type_index getParamTypeIndex ( unsigned ) const override { - throw exception::CommonException ( "Nullary algorithm does not have any parameter." ); - } - +class NullaryOperationAbstraction : public NaryOperationAbstraction < ReturnType > { }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/UnaryOperationAbstraction.hpp b/alib2common/src/abstraction/UnaryOperationAbstraction.hpp index bce9dae138773abd9413d1faed7bfcafe4b11f6e..7443e837e89faa72665ac4dda6995bf93a9e275c 100644 --- a/alib2common/src/abstraction/UnaryOperationAbstraction.hpp +++ b/alib2common/src/abstraction/UnaryOperationAbstraction.hpp @@ -8,74 +8,12 @@ #ifndef _UNARY_OPERATION_ABSTRACTION_HPP_ #define _UNARY_OPERATION_ABSTRACTION_HPP_ -#include <abstraction/ValueOperationAbstraction.hpp> -#include <tuple> -#include <abstraction/Registry.h> +#include <abstraction/NaryOperationAbstraction.hpp> namespace abstraction { template < class ReturnType, class ParamType > -class UnaryOperationAbstraction : public ValueOperationAbstraction < ReturnType > { -protected: - std::shared_ptr < ValueProvider < ParamType > > m_param; - -private: - virtual bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, unsigned index ) override { - if ( index != 0 ) - throw exception::CommonException ( "Out of range index: " + ext::to_string ( index ) + " max: " + ext::to_string ( numberOfParams ( ) ) + "." ); - - std::shared_ptr < ValueProvider < ParamType > > validData = std::dynamic_pointer_cast < ValueProvider < ParamType > > ( input ); - if ( validData ) { - m_param = validData; - return true; - } else { - return false; - } - } - - virtual bool detachInput ( unsigned index ) override { - if ( index != 0 ) - return false; - - m_param = nullptr; - return true; - } - -public: - UnaryOperationAbstraction ( ) { - } - - virtual bool inputsReady ( ) const override { - return m_param && m_param->isReady ( ); - } - - virtual bool inputsAttached ( ) const override { - return ( bool ) m_param; - } - - virtual bool eval ( ) override { - if ( ! inputsAttached ( ) ) - return false; - - if ( this->cached ( ) ) - return true; - - this->m_param->eval ( ); - - return this->run ( ); - } - - virtual unsigned numberOfParams ( ) const override { - return 1; - } - - virtual ext::type_index getParamTypeIndex ( unsigned index ) const override { - if ( index != 0 ) - throw std::out_of_range ( "Invalid input index" ); - - return ext::type_index ( typeid ( ParamType ) ); - } - +class UnaryOperationAbstraction : public NaryOperationAbstraction < ReturnType, ParamType > { }; } /* namespace abstraction */ diff --git a/alib2common/src/abstraction/ValueOperationAbstraction.hpp b/alib2common/src/abstraction/ValueOperationAbstraction.hpp index 89a9d0a1130356fd020f86b595d167e7517c2449..8e1a605921a2e2515b82223b5c158692dd9bfb91 100644 --- a/alib2common/src/abstraction/ValueOperationAbstraction.hpp +++ b/alib2common/src/abstraction/ValueOperationAbstraction.hpp @@ -108,12 +108,6 @@ public: m_data = callback ( std::get < Indexes > ( inputs )->getValue ( ) ... ); } - template < typename Callable, typename T > - inline void run_helper ( Callable callback, const T & input ) const { - if ( ! isReady ( ) ) - m_data = callback ( input->getValue ( ) ); - } - virtual bool isReady ( ) const override { return m_data.template is < ReturnType > ( ); } @@ -154,12 +148,6 @@ public: m_data = std::reference_wrapper < ReturnType > ( callback ( std::get < Indexes > ( inputs )->getValue ( ) ... ) ); } - template < typename Callable, typename T > - inline void run_helper ( Callable callback, const T & input ) const { - if ( ! isReady ( ) ) - m_data = std::reference_wrapper < ReturnType > ( callback ( input->getValue ( ) ) ); - } - virtual bool isReady ( ) const override { return m_data.template is < std::reference_wrapper < ReturnType > > ( ); } @@ -196,12 +184,6 @@ public: m_data = std::reference_wrapper < const ReturnType > ( callback ( std::get < Indexes > ( inputs )->getValue ( ) ... ) ); } - template < typename Callable, typename T > - inline void run_helper ( Callable callback, const T & input ) const { - if ( ! isReady ( ) ) - m_data = std::reference_wrapper < const ReturnType > ( callback ( input->getValue ( ) ) ); - } - virtual bool isReady ( ) const override { return m_data.template is < std::reference_wrapper < const ReturnType > > ( ); } @@ -242,12 +224,6 @@ public: m_data = std::unique_ptr < ReturnType > ( callback ( std::get < Indexes > ( inputs )->getValue ( ) ... ) ); } - template < typename Callable, typename T > - inline void run_helper ( Callable callback, const T & input ) const { - if ( ! isReady ( ) ) - m_data = std::unique_ptr < ReturnType > ( callback ( input->getValue ( ) ) ); - } - virtual bool isReady ( ) const override { return m_data != nullptr; } @@ -276,11 +252,6 @@ public: callback ( std::get < Indexes > ( inputs )->getValue ( ) ... ); } - template < typename Callable, typename T > - inline void run_helper ( Callable callback, const T & input ) const { - callback ( input->getValue ( ) ); - } - virtual bool isReady ( ) const { return true; } diff --git a/alib2common/src/abstraction/ValuePrinterAbstraction.hpp b/alib2common/src/abstraction/ValuePrinterAbstraction.hpp index 71318a04e848837ba09de3546df6e4f4097a1964..83b8c4a1699888f39c81d27b49871217fd048d9e 100644 --- a/alib2common/src/abstraction/ValuePrinterAbstraction.hpp +++ b/alib2common/src/abstraction/ValuePrinterAbstraction.hpp @@ -23,7 +23,7 @@ public: if ( ! this->inputsReady ( ) ) return false; - std::cout << this->m_param->getConstValueReference ( ) << std::endl; + std::cout << std::get < 0 > ( this->m_params )->getConstValueReference ( ) << std::endl; return true; } }; diff --git a/alib2common/src/abstraction/XmlFileWriterAbstraction.hpp b/alib2common/src/abstraction/XmlFileWriterAbstraction.hpp index 8076918e34c05fc505fe219117ba8dd26d013c12..c4283495b8389c9452c33cf2496fe1fc5d36db30 100644 --- a/alib2common/src/abstraction/XmlFileWriterAbstraction.hpp +++ b/alib2common/src/abstraction/XmlFileWriterAbstraction.hpp @@ -25,7 +25,7 @@ public: if ( ! this->inputsReady ( ) ) return false; - alib::XmlDataFactory::toFile ( this->m_param->getConstValueReference ( ), m_filename ); + alib::XmlDataFactory::toFile ( std::get < 0 > ( this->m_params )->getConstValueReference ( ), m_filename ); return true; } };