]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Ports.h
Moved to version 1.0
[cpPlugins.git] / lib / cpPlugins / Ports.h
diff --git a/lib/cpPlugins/Ports.h b/lib/cpPlugins/Ports.h
new file mode 100644 (file)
index 0000000..cb13329
--- /dev/null
@@ -0,0 +1,128 @@
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+#ifndef __cpPlugins__Ports__h__
+#define __cpPlugins__Ports__h__
+
+#include <vector>
+#include <cpPlugins/Config.h>
+
+namespace cpPlugins
+{
+  class Object;
+  class DataObject;
+  class Functor;
+
+  /**
+   */
+  class CPPLUGINS_EXPORT BasePort
+  {
+  public:
+    BasePort( );
+    virtual ~BasePort( );
+  }; // end class
+
+  /**
+   */
+  class CPPLUGINS_EXPORT InputPort
+    : public BasePort
+  {
+  public:
+    typedef InputPort Self;
+    typedef BasePort  Superclass;
+
+    typedef std::shared_ptr< DataObject > SharedPtr;
+    typedef std::weak_ptr< DataObject >   WeakPtr;
+
+  public:
+    InputPort( );
+    virtual ~InputPort( );
+
+    template< class _TObject >
+    void Configure( bool required, bool multiple )
+      {
+        this->m_Required = required;
+        this->m_Multiple = multiple;
+        this->m_Data.clear( );
+        this->m_Template = _TObject::New( );
+      }
+
+    DataObject* Get( const unsigned int& i );
+    const DataObject* Get( const unsigned int& i ) const;
+    unsigned int Count( ) const;
+    bool IsValid( ) const;
+    bool Set( DataObject* data );
+    bool Update( );
+
+  protected:
+    std::vector< SharedPtr > m_Data;
+    SharedPtr m_Template;
+    bool m_Required;
+    bool m_Multiple;
+  }; // end class
+
+  /**
+   */
+  class CPPLUGINS_EXPORT OutputPort
+    : public BasePort
+  {
+  public:
+    typedef OutputPort Self;
+    typedef BasePort   Superclass;
+
+    typedef std::shared_ptr< DataObject > SharedPtr;
+    typedef std::weak_ptr< DataObject >   WeakPtr;
+
+  public:
+    OutputPort( );
+    virtual ~OutputPort( );
+
+    DataObject* Get( );
+    const DataObject* Get( ) const;
+
+    template< class _TObject >
+    void Configure( )
+      {
+        this->m_Data = _TObject::New( );
+      }
+
+  protected:
+    SharedPtr m_Data;
+  }; // end class
+
+  /**
+   */
+  class CPPLUGINS_EXPORT FunctorPort
+    : public BasePort
+  {
+  public:
+    typedef FunctorPort Self;
+    typedef BasePort    Superclass;
+
+    typedef std::shared_ptr< Functor > SharedPtr;
+    typedef std::weak_ptr< Functor >   WeakPtr;
+
+  public:
+    FunctorPort( );
+    virtual ~FunctorPort( );
+
+    template< class _TFunctor >
+    void Configure( bool required )
+      {
+        this->m_Required = required;
+      }
+
+    Functor* Get( );
+    const Functor* Get( ) const;
+    bool Set( Functor* f );
+    bool Update( );
+
+  protected:
+    SharedPtr m_Functor;
+    bool m_Required;
+  }; // end class
+} // end namespace
+
+#endif // __cpPlugins__Ports__h__
+
+// eof - $RCSfile$