X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FFilter.h;fp=lib%2FcpPlugins%2FFilter.h;h=e7b278f00fa38309fe13bbd2fd2dd0e0052c8cb4;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=0000000000000000000000000000000000000000;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/lib/cpPlugins/Filter.h b/lib/cpPlugins/Filter.h new file mode 100644 index 0000000..e7b278f --- /dev/null +++ b/lib/cpPlugins/Filter.h @@ -0,0 +1,122 @@ +// ========================================================================= +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ========================================================================= +#ifndef __cpPlugins__Filter__h__ +#define __cpPlugins__Filter__h__ + +#include +#include +#include + +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$