]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Pipeline/Port.cxx
yet another refactoring
[cpPlugins.git] / lib / cpPlugins / Pipeline / Port.cxx
diff --git a/lib/cpPlugins/Pipeline/Port.cxx b/lib/cpPlugins/Pipeline/Port.cxx
new file mode 100644 (file)
index 0000000..4c980c0
--- /dev/null
@@ -0,0 +1,231 @@
+#include <cpPlugins/Pipeline/Port.h>
+
+// -------------------------------------------------------------------------
+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$