]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Filter.h
Moved to version 1.0
[cpPlugins.git] / lib / cpPlugins / Filter.h
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __cpPlugins__Filter__h__
5 #define __cpPlugins__Filter__h__
6
7 #include <cpPlugins/ProcessObject.h>
8 #include <cpPlugins/DataObject.h>
9 #include <cpPlugins/Functor.h>
10
11 namespace cpPlugins
12 {
13   /*! \brief 
14    */
15   class CPPLUGINS_EXPORT Filter
16     : public ProcessObject
17   {
18     cpPluginsTypeMacro( Filter, ProcessObject );
19
20   public:
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;
26
27   public:
28     //! IO management
29     virtual void SetFunctor( const std::string& name, Functor* functor );
30
31     virtual DataObject* GetOutput( const std::string& name );
32     virtual const DataObject* GetOutput( const std::string& name ) const;
33
34     virtual bool HasOutput( const std::string& name ) const;
35
36     virtual Functor* GetFunctor( const std::string& name );
37     virtual const Functor* GetFunctor( const std::string& name ) const;
38
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;
43
44   protected:
45     Filter( );
46     virtual ~Filter( );
47
48     virtual bool _BeforeUpdate( ) override;
49
50     template< class _TData >
51     _TData* _GetOutput( const std::string& name )
52       {
53         TOutputs::iterator i = this->m_Outputs.find( name );
54         if( i != this->m_Outputs.end( ) )
55           return( dynamic_cast< _TData* >( i->second.Get( ) ) );
56         else
57           cpPluginsErrorMacro(
58             this,
59             << "Output \"" << name << "\" does not belong to this filter."
60             );
61       }
62
63     template< class _TFunctor >
64     _TFunctor* _GetFunctor( const std::string& name )
65       {
66         TFunctors::iterator i = this->m_Functors.find( name );
67         if( i != this->m_Functors.end( ) )
68           return( dynamic_cast< _TFunctor* >( i->second.Get( ) ) );
69         else
70           cpPluginsErrorMacro(
71             this,
72             << "Functor \"" << name << "\" does not belong to this filter."
73             );
74       }
75
76     template< class _TFunctor >
77     const _TFunctor* _GetFunctor( const std::string& name ) const
78       {
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( ) ) );
82         else
83           cpPluginsErrorMacro(
84             this,
85             << "Functor \"" << name << "\" does not belong to this filter."
86             );
87       }
88
89     template< class _TData >
90     void _ConfigureOutput( const std::string& name )
91       {
92         if( this->m_Outputs.find( name ) != this->m_Outputs.end( ) )
93           cpPluginsErrorMacro(
94             this, << "Output \"" << name << "\" already exists."
95             );
96         TOutputPort port;
97         port.Configure< _TData >( );
98         port.Get( )->SetSource( this );
99         this->m_Outputs[ name ] = port;
100       }
101
102     template< class _TFunctor >
103     void _ConfigureFunctor( const std::string& name, bool required )
104       {
105         if( this->m_Functors.find( name ) != this->m_Functors.end( ) )
106           cpPluginsErrorMacro(
107             this, << "Functor \"" << name << "\" already exists."
108             );
109         TFunctorPort port;
110         port.Configure< _TFunctor >( required );
111         this->m_Functors[ name ] = port;
112       }
113
114   protected:
115     TOutputs  m_Outputs;
116     TFunctors m_Functors;
117   }; // end class
118 } // end namespace
119
120 #endif // __cpPlugins__Filter__h__
121
122 // eof - $RCSfile$