Newer
Older
/*
* PackingAbstraction.hpp
*
* Created on: 29. 5. 2018
* Author: Jan Travnicek
*/
#ifndef _PACKING_ABSTRACTION_HPP_
#define _PACKING_ABSTRACTION_HPP_
#include <alib/memory>
#include <alib/array>
#include <abstraction/ValueOperationAbstraction.hpp>
#include <registry/Registry.h>
namespace abstraction {
class PackingAbstraction : public OperationAbstraction {
struct ConnectionTarget {
unsigned targetId;
unsigned paramPosition;
};
ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > m_abstractions;
ext::array < ext::vector < ConnectionTarget >, NumberOfParams > m_connections;
unsigned m_resultId;
public:
PackingAbstraction ( ext::vector < std::shared_ptr < abstraction::OperationAbstraction > > abstractions, unsigned resultId ) : m_abstractions ( std::move ( abstractions ) ), m_resultId ( resultId ) {
}
bool setInnerConnection ( unsigned sourceId, unsigned targetId, unsigned paramPosition, bool move ) {
return m_abstractions [ targetId ]->attachInput ( m_abstractions [ sourceId ], paramPosition, move, true );
}
bool clearInnerConnection ( unsigned targetId, unsigned paramPosition ) {
return m_abstractions [ targetId ]->detachInput ( paramPosition );
}
void setOuterConnection ( unsigned sourceId, unsigned targetId, unsigned paramPosition ) {
m_connections [ sourceId ].push_back ( ConnectionTarget { targetId, paramPosition } );
}
private:
bool attachInput ( const std::shared_ptr < OperationAbstraction > & input, unsigned index, bool move, bool checkInput ) override {
for ( const ConnectionTarget & target : m_connections [ index ] )
res &= m_abstractions [ target.targetId ]->attachInput ( input, target.paramPosition, move, checkInput );
if ( ! res )
this->detachInput ( index );
return res;
bool detachInput ( unsigned index ) override {
for ( const ConnectionTarget & target : m_connections [ index ] )
res &= m_abstractions [ target.targetId ]->detachInput ( target.paramPosition );
bool inputsAttached ( ) const override {
for ( const std::shared_ptr < abstraction::OperationAbstraction > & operation : m_abstractions )
if ( operation->inputsAttached ( ) == false )
return false;
return true;
}
bool run ( ) override {
return m_abstractions [ m_resultId ]->eval ( );
bool eval ( ) override {
if ( ! inputsAttached ( ) )
return false;
if ( this->cached ( ) )
return true;
unsigned numberOfParams ( ) const override {
bool cached ( ) const override {
return m_abstractions [ m_resultId ]->cached ( );
void reset ( ) override {
for ( std::shared_ptr < abstraction::OperationAbstraction > & abstraction : m_abstractions )
return abstraction->reset ( );
}
ext::type_index getParamTypeIndex ( unsigned index ) const override {
return m_abstractions [ m_connections.at ( index ) [ 0 ].targetId ]->getParamTypeIndex ( m_connections.at ( index ) [ 0 ].paramPosition );
}
ext::set < abstraction::ParamQualifiers::ParamQualifier > getParamTypeQualifiers ( unsigned index ) const override {
return m_abstractions [ m_connections.at ( index ) [ 0 ].targetId ]->getParamTypeQualifiers ( m_connections.at ( index ) [ 0 ].paramPosition );
}
ext::type_index getReturnTypeIndex ( ) const override {
return m_abstractions [ m_resultId ]->getReturnTypeIndex ( );
}
ext::set < abstraction::ParamQualifiers::ParamQualifier > getReturnTypeQualifiers ( ) const override {
return m_abstractions [ m_resultId ]->getReturnTypeQualifiers ( );
}
std::shared_ptr < abstraction::OperationAbstraction > getProxyAbstraction ( ) override {
return m_abstractions [ m_resultId ]->getProxyAbstraction ( );
}
};
} /* namespace abstraction */
#endif /* _PACKING_ABSTRACTION_HPP_ */