X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPorts.cxx;fp=lib%2FcpPlugins%2FPorts.cxx;h=b16de9153f229c4d7a92535c62dd3cf0cf31b03d;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=0000000000000000000000000000000000000000;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/lib/cpPlugins/Ports.cxx b/lib/cpPlugins/Ports.cxx new file mode 100644 index 0000000..b16de91 --- /dev/null +++ b/lib/cpPlugins/Ports.cxx @@ -0,0 +1,223 @@ +// ========================================================================= +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ========================================================================= + +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::BasePort:: +BasePort( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::BasePort:: +~BasePort( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::InputPort:: +InputPort( ) + : Superclass( ), + m_Required( false ), + m_Multiple( false ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::InputPort:: +~InputPort( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject* cpPlugins::InputPort:: +Get( const unsigned int& i ) +{ + if( i < this->m_Data.size( ) ) + { + if( this->m_Data[ i ] ) + return( this->m_Data[ i ].get( ) ); + else + return( NULL ); + } + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::DataObject* cpPlugins::InputPort:: +Get( const unsigned int& i ) const +{ + if( i < this->m_Data.size( ) ) + { + if( this->m_Data[ i ] ) + return( this->m_Data[ i ].get( ) ); + else + return( NULL ); + } + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +unsigned int cpPlugins::InputPort:: +Count( ) const +{ + return( this->m_Data.size( ) ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::InputPort:: +IsValid( ) const +{ + if( this->m_Required ) + { + if( this->m_Data.size( ) > 0 ) + return( bool( this->m_Data[ 0 ] ) ); + else + return( false ); + } + else + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::InputPort:: +Set( cpPlugins::DataObject* data ) +{ + if( this->m_Multiple || this->m_Template.get( ) != NULL ) + { + if( data->IsCompatible( this->m_Template.get( ) ) ) + { + this->m_Data.push_back( + data->CastSharedPtr< cpPlugins::DataObject >( ) + ); + return( true ); + } + else + return( false ); + } + else + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::InputPort:: +Update( ) +{ + bool is_updated = true; + unsigned int N = 0; + for( SharedPtr& d: this->m_Data ) + { + if( d ) + { + N++; + if( !( d->IsUpdated( ) ) ) + { + d->Update( ); + is_updated = false; + + } // end if + } // end if + } // end for + if( this->m_Required && N == 0 ) + cpPluginsErrorMacro( << "Input is needed, but not yet assigned." ); + return( is_updated ); +} + +// ------------------------------------------------------------------------- +cpPlugins::OutputPort:: +OutputPort( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::OutputPort:: +~OutputPort( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject* cpPlugins::OutputPort:: +Get( ) +{ + if( this->m_Data ) + return( this->m_Data.get( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::DataObject* cpPlugins::OutputPort:: +Get( ) const +{ + if( this->m_Data ) + return( this->m_Data.get( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +cpPlugins::FunctorPort:: +FunctorPort( ) + : Superclass( ), + m_Required( false ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::FunctorPort:: +~FunctorPort( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Functor* cpPlugins::FunctorPort:: +Get( ) +{ + if( this->m_Functor ) + return( this->m_Functor.get( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Functor* cpPlugins::FunctorPort:: +Get( ) const +{ + if( this->m_Functor ) + return( this->m_Functor.get( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::FunctorPort:: +Set( cpPlugins::Functor* f ) +{ + if( f != NULL ) + this->m_Functor = f->CastSharedPtr< cpPlugins::Functor >( ); + else + this->m_Functor.reset( ); + return( true ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::FunctorPort:: +Update( ) +{ + if( this->m_Functor ) + { + if( !( this->m_Functor->IsUpdated( ) ) ) + this->m_Functor->Update( ); + return( true ); + } // end if + return( false ); +} + +// eof - $RCSfile$