1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __cpPlugins__Filter__h__
5 #define __cpPlugins__Filter__h__
7 #include <cpPlugins/ProcessObject.h>
8 #include <cpPlugins/DataObject.h>
9 #include <cpPlugins/Functor.h>
15 class CPPLUGINS_EXPORT Filter
16 : public ProcessObject
18 cpPluginsTypeMacro( Filter, ProcessObject );
21 typedef Functor TFunctor;
22 typedef OutputPort TOutputPort;
23 typedef FunctorPort TFunctorPort;
24 typedef std::map< std::string, TOutputPort > TOutputs;
25 typedef std::map< std::string, TFunctorPort > TFunctors;
29 virtual void SetFunctor( const std::string& name, Functor* functor );
31 virtual DataObject* GetOutput( const std::string& name );
32 virtual const DataObject* GetOutput( const std::string& name ) const;
34 virtual bool HasOutput( const std::string& name ) const;
36 virtual Functor* GetFunctor( const std::string& name );
37 virtual const Functor* GetFunctor( const std::string& name ) const;
39 std::set< std::string > GetOutputsNames( ) const;
40 std::set< std::string > GetFunctorsNames( ) const;
41 virtual std::set< std::string > GetAllInputsNames( ) const override;
42 virtual std::set< std::string > GetAllOutputsNames( ) const override;
48 virtual bool _BeforeUpdate( ) override;
50 template< class _TData >
51 _TData* _GetOutput( const std::string& name )
53 TOutputs::iterator i = this->m_Outputs.find( name );
54 if( i != this->m_Outputs.end( ) )
55 return( dynamic_cast< _TData* >( i->second.Get( ) ) );
59 << "Output \"" << name << "\" does not belong to this filter."
63 template< class _TFunctor >
64 _TFunctor* _GetFunctor( const std::string& name )
66 TFunctors::iterator i = this->m_Functors.find( name );
67 if( i != this->m_Functors.end( ) )
68 return( dynamic_cast< _TFunctor* >( i->second.Get( ) ) );
72 << "Functor \"" << name << "\" does not belong to this filter."
76 template< class _TFunctor >
77 const _TFunctor* _GetFunctor( const std::string& name ) const
79 TFunctors::const_iterator i = this->m_Functors.find( name );
80 if( i != this->m_Functors.end( ) )
81 return( dynamic_cast< const _TFunctor* >( i->second.Get( ) ) );
85 << "Functor \"" << name << "\" does not belong to this filter."
89 template< class _TData >
90 void _ConfigureOutput( const std::string& name )
92 if( this->m_Outputs.find( name ) != this->m_Outputs.end( ) )
94 this, << "Output \"" << name << "\" already exists."
97 port.Configure< _TData >( );
98 port.Get( )->SetSource( this );
99 this->m_Outputs[ name ] = port;
102 template< class _TFunctor >
103 void _ConfigureFunctor( const std::string& name, bool required )
105 if( this->m_Functors.find( name ) != this->m_Functors.end( ) )
107 this, << "Functor \"" << name << "\" already exists."
110 port.Configure< _TFunctor >( required );
111 this->m_Functors[ name ] = port;
116 TFunctors m_Functors;
120 #endif // __cpPlugins__Filter__h__