--- /dev/null
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+#ifndef __cpPlugins__Filter__h__
+#define __cpPlugins__Filter__h__
+
+#include <cpPlugins/ProcessObject.h>
+#include <cpPlugins/DataObject.h>
+#include <cpPlugins/Functor.h>
+
+namespace cpPlugins
+{
+ /*! \brief
+ */
+ class CPPLUGINS_EXPORT Filter
+ : public ProcessObject
+ {
+ cpPluginsTypeMacro( Filter, ProcessObject );
+
+ public:
+ typedef Functor TFunctor;
+ typedef OutputPort TOutputPort;
+ typedef FunctorPort TFunctorPort;
+ typedef std::map< std::string, TOutputPort > TOutputs;
+ typedef std::map< std::string, TFunctorPort > TFunctors;
+
+ public:
+ //! IO management
+ virtual void SetFunctor( const std::string& name, Functor* functor );
+
+ virtual DataObject* GetOutput( const std::string& name );
+ virtual const DataObject* GetOutput( const std::string& name ) const;
+
+ virtual bool HasOutput( const std::string& name ) const;
+
+ virtual Functor* GetFunctor( const std::string& name );
+ virtual const Functor* GetFunctor( const std::string& name ) const;
+
+ std::set< std::string > GetOutputsNames( ) const;
+ std::set< std::string > GetFunctorsNames( ) const;
+ virtual std::set< std::string > GetAllInputsNames( ) const override;
+ virtual std::set< std::string > GetAllOutputsNames( ) const override;
+
+ protected:
+ Filter( );
+ virtual ~Filter( );
+
+ virtual bool _BeforeUpdate( ) override;
+
+ template< class _TData >
+ _TData* _GetOutput( const std::string& name )
+ {
+ TOutputs::iterator i = this->m_Outputs.find( name );
+ if( i != this->m_Outputs.end( ) )
+ return( dynamic_cast< _TData* >( i->second.Get( ) ) );
+ else
+ cpPluginsErrorMacro(
+ this,
+ << "Output \"" << name << "\" does not belong to this filter."
+ );
+ }
+
+ template< class _TFunctor >
+ _TFunctor* _GetFunctor( const std::string& name )
+ {
+ TFunctors::iterator i = this->m_Functors.find( name );
+ if( i != this->m_Functors.end( ) )
+ return( dynamic_cast< _TFunctor* >( i->second.Get( ) ) );
+ else
+ cpPluginsErrorMacro(
+ this,
+ << "Functor \"" << name << "\" does not belong to this filter."
+ );
+ }
+
+ template< class _TFunctor >
+ const _TFunctor* _GetFunctor( const std::string& name ) const
+ {
+ TFunctors::const_iterator i = this->m_Functors.find( name );
+ if( i != this->m_Functors.end( ) )
+ return( dynamic_cast< const _TFunctor* >( i->second.Get( ) ) );
+ else
+ cpPluginsErrorMacro(
+ this,
+ << "Functor \"" << name << "\" does not belong to this filter."
+ );
+ }
+
+ template< class _TData >
+ void _ConfigureOutput( const std::string& name )
+ {
+ if( this->m_Outputs.find( name ) != this->m_Outputs.end( ) )
+ cpPluginsErrorMacro(
+ this, << "Output \"" << name << "\" already exists."
+ );
+ TOutputPort port;
+ port.Configure< _TData >( );
+ port.Get( )->SetSource( this );
+ this->m_Outputs[ name ] = port;
+ }
+
+ template< class _TFunctor >
+ void _ConfigureFunctor( const std::string& name, bool required )
+ {
+ if( this->m_Functors.find( name ) != this->m_Functors.end( ) )
+ cpPluginsErrorMacro(
+ this, << "Functor \"" << name << "\" already exists."
+ );
+ TFunctorPort port;
+ port.Configure< _TFunctor >( required );
+ this->m_Functors[ name ] = port;
+ }
+
+ protected:
+ TOutputs m_Outputs;
+ TFunctors m_Functors;
+ }; // end class
+} // end namespace
+
+#endif // __cpPlugins__Filter__h__
+
+// eof - $RCSfile$