X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FPipeline%2FPort.cxx;fp=lib%2FcpPlugins%2FPipeline%2FPort.cxx;h=4c980c0e6f43fa15a9b37bc2ad34e67bfa5d34e7;hb=3c250e0e573d7f08276aefd93a5336f128e6b1a7;hp=0000000000000000000000000000000000000000;hpb=32cfe91acc85230333199444bc712ea86da65c4e;p=cpPlugins.git diff --git a/lib/cpPlugins/Pipeline/Port.cxx b/lib/cpPlugins/Pipeline/Port.cxx new file mode 100644 index 0000000..4c980c0 --- /dev/null +++ b/lib/cpPlugins/Pipeline/Port.cxx @@ -0,0 +1,231 @@ +#include + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::Port:: +Port( bool required ) + : m_Required( required ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::Port:: +~Port( ) +{ +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Pipeline::Port:: +IsRequired( ) const +{ + return( this->m_Required ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::Port:: +Clear( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::SingleDataPort:: +SingleDataPort( bool required ) + : Superclass( required ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::SingleDataPort:: +~SingleDataPort( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::SingleDataPort:: +Add( cpPlugins::Pipeline::DataObject* o ) +{ + if( this->m_Sample.IsNull( ) ) + throw std::logic_error( + "cpPlugins::SingleDataPort: Port not yet configured" + ); + if( o != NULL ) + { + if( this->m_Sample->IsCompatible( o ) ) + this->m_Data = o; + else + throw std::logic_error( + "cpPlugins::SingleDataPort: incompatible types \"" + + std::string( typeid( *o ).name( ) ) + std::string( "\" and \"" ) + + std::string( typeid( *( this->m_Sample.GetPointer( ) ) ).name( ) ) + + std::string( "\"" ) + ); + } + else + this->m_Data = NULL; +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::DataObject* cpPlugins::Pipeline::SingleDataPort:: +Get( unsigned int i ) +{ + return( this->m_Data.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Pipeline::DataObject* cpPlugins::Pipeline::SingleDataPort:: +Get( unsigned int i ) const +{ + return( this->m_Data.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +unsigned int cpPlugins::Pipeline::SingleDataPort:: +Size( ) const +{ + return( 1 ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Pipeline::SingleDataPort:: +IsValid( ) const +{ + return( this->m_Data.IsNotNull( ) ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::SingleDataPort:: +Clear( ) +{ + this->m_Data = NULL; +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::OutputPort:: +OutputPort( bool required ) + : Superclass( required ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::OutputPort:: +~OutputPort( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::OutputPort:: +Set( DataObject* o ) +{ + this->m_Sample = o; + this->m_Data = o; +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::InputPort:: +InputPort( bool required ) + : Superclass( required ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::InputPort:: +~InputPort( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::MultipleInputsPort:: +MultipleInputsPort( bool required ) + : Superclass( required ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::MultipleInputsPort:: +~MultipleInputsPort( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::MultipleInputsPort:: +Add( cpPlugins::Pipeline::DataObject* o ) +{ + if( this->m_Sample.IsNull( ) ) + throw std::logic_error( + "cpPlugins::SingleDataPort: Port not yet configured" + ); + if( o != NULL ) + { + if( this->m_Sample->IsCompatible( o ) ) + { + this->m_Data.push_back( o ); + } + else + throw std::logic_error( + "cpPlugins::SingleDataPort: incompatible types \"" + + std::string( typeid( *o ).name( ) ) + std::string( "\" and \"" ) + + std::string( typeid( *( this->m_Sample.GetPointer( ) ) ).name( ) ) + + std::string( "\"" ) + ); + + } // fi +} + +// ------------------------------------------------------------------------- +cpPlugins::Pipeline::DataObject* +cpPlugins::Pipeline::MultipleInputsPort:: +Get( unsigned int i ) +{ + if( i < this->m_Data.size( ) ) + return( this->m_Data[ i ].GetPointer( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Pipeline::DataObject* +cpPlugins::Pipeline::MultipleInputsPort:: +Get( unsigned int i ) const +{ + if( i < this->m_Data.size( ) ) + return( this->m_Data[ i ].GetPointer( ) ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +unsigned int cpPlugins::Pipeline::MultipleInputsPort:: +Size( ) const +{ + return( this->m_Data.size( ) ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Pipeline::MultipleInputsPort:: +IsValid( ) const +{ + if( this->m_Data.size( ) > 0 ) + return( this->m_Data[ 0 ].IsNotNull( ) ); + else + return( false ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::MultipleInputsPort:: +Clear( ) +{ + this->m_Data.clear( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Pipeline::MultipleInputsPort:: +Delete( unsigned int id ) +{ + if( id < this->m_Data.size( ) ) + { + this->m_Data[ id ] = NULL; + this->m_Data.erase( this->m_Data.begin( ) + id ); + + } // fi +} + +// eof - $RCSfile$