1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
5 #include <cpPlugins/Ports.h>
6 #include <cpPlugins/DataObject.h>
7 #include <cpPlugins/Functor.h>
9 // -------------------------------------------------------------------------
15 // -------------------------------------------------------------------------
21 // -------------------------------------------------------------------------
22 cpPlugins::InputPort::
30 // -------------------------------------------------------------------------
31 cpPlugins::InputPort::
36 // -------------------------------------------------------------------------
37 cpPlugins::DataObject* cpPlugins::InputPort::
38 Get( const unsigned int& i )
40 if( i < this->m_Data.size( ) )
42 if( this->m_Data[ i ] )
43 return( this->m_Data[ i ].get( ) );
51 // -------------------------------------------------------------------------
52 const cpPlugins::DataObject* cpPlugins::InputPort::
53 Get( const unsigned int& i ) const
55 if( i < this->m_Data.size( ) )
57 if( this->m_Data[ i ] )
58 return( this->m_Data[ i ].get( ) );
66 // -------------------------------------------------------------------------
67 unsigned int cpPlugins::InputPort::
70 return( this->m_Data.size( ) );
73 // -------------------------------------------------------------------------
74 bool cpPlugins::InputPort::
77 if( this->m_Required )
79 if( this->m_Data.size( ) > 0 )
80 return( bool( this->m_Data[ 0 ] ) );
88 // -------------------------------------------------------------------------
89 bool cpPlugins::InputPort::
90 Set( cpPlugins::DataObject* data )
92 if( this->m_Multiple || this->m_Template.get( ) != NULL )
94 if( data->IsCompatible( this->m_Template.get( ) ) )
96 this->m_Data.push_back(
97 data->CastSharedPtr< cpPlugins::DataObject >( )
108 // -------------------------------------------------------------------------
109 bool cpPlugins::InputPort::
112 bool is_updated = true;
114 for( SharedPtr& d: this->m_Data )
119 if( !( d->IsUpdated( ) ) )
127 if( this->m_Required && N == 0 )
128 cpPluginsErrorMacro( << "Input is needed, but not yet assigned." );
129 return( is_updated );
132 // -------------------------------------------------------------------------
133 cpPlugins::OutputPort::
139 // -------------------------------------------------------------------------
140 cpPlugins::OutputPort::
145 // -------------------------------------------------------------------------
146 cpPlugins::DataObject* cpPlugins::OutputPort::
150 return( this->m_Data.get( ) );
155 // -------------------------------------------------------------------------
156 const cpPlugins::DataObject* cpPlugins::OutputPort::
160 return( this->m_Data.get( ) );
165 // -------------------------------------------------------------------------
166 cpPlugins::FunctorPort::
173 // -------------------------------------------------------------------------
174 cpPlugins::FunctorPort::
179 // -------------------------------------------------------------------------
180 cpPlugins::Functor* cpPlugins::FunctorPort::
183 if( this->m_Functor )
184 return( this->m_Functor.get( ) );
189 // -------------------------------------------------------------------------
190 const cpPlugins::Functor* cpPlugins::FunctorPort::
193 if( this->m_Functor )
194 return( this->m_Functor.get( ) );
199 // -------------------------------------------------------------------------
200 bool cpPlugins::FunctorPort::
201 Set( cpPlugins::Functor* f )
204 this->m_Functor = f->CastSharedPtr< cpPlugins::Functor >( );
206 this->m_Functor.reset( );
210 // -------------------------------------------------------------------------
211 bool cpPlugins::FunctorPort::
214 if( this->m_Functor )
216 if( !( this->m_Functor->IsUpdated( ) ) )
217 this->m_Functor->Update( );