1 #include <cpPlugins/BaseObjects/Port.h>
3 // -------------------------------------------------------------------------
4 cpPlugins::BaseObjects::Port::
6 : m_Required( required )
10 // -------------------------------------------------------------------------
11 cpPlugins::BaseObjects::Port::
16 // -------------------------------------------------------------------------
17 bool cpPlugins::BaseObjects::Port::
20 return( this->m_Required );
23 // -------------------------------------------------------------------------
24 void cpPlugins::BaseObjects::Port::
29 // -------------------------------------------------------------------------
30 cpPlugins::BaseObjects::SingleDataPort::
31 SingleDataPort( bool required )
32 : Superclass( required )
36 // -------------------------------------------------------------------------
37 cpPlugins::BaseObjects::SingleDataPort::
42 // -------------------------------------------------------------------------
43 void cpPlugins::BaseObjects::SingleDataPort::
44 Add( cpPlugins::BaseObjects::DataObject* o )
46 if( this->m_Sample.IsNull( ) )
47 throw std::logic_error(
48 "cpPlugins::SingleDataPort: Port not yet configured"
52 if( this->m_Sample->IsCompatible( o ) )
55 throw std::logic_error(
56 "cpPlugins::SingleDataPort: incompatible types \"" +
57 std::string( typeid( *o ).name( ) ) + std::string( "\" and \"" ) +
58 std::string( typeid( *( this->m_Sample.GetPointer( ) ) ).name( ) ) +
66 // -------------------------------------------------------------------------
67 cpPlugins::BaseObjects::DataObject* cpPlugins::BaseObjects::SingleDataPort::
70 return( this->m_Data.GetPointer( ) );
73 // -------------------------------------------------------------------------
74 const cpPlugins::BaseObjects::DataObject* cpPlugins::BaseObjects::SingleDataPort::
75 Get( unsigned int i ) const
77 return( this->m_Data.GetPointer( ) );
80 // -------------------------------------------------------------------------
81 unsigned int cpPlugins::BaseObjects::SingleDataPort::
87 // -------------------------------------------------------------------------
88 bool cpPlugins::BaseObjects::SingleDataPort::
91 return( this->m_Data.IsNotNull( ) );
94 // -------------------------------------------------------------------------
95 void cpPlugins::BaseObjects::SingleDataPort::
101 // -------------------------------------------------------------------------
102 cpPlugins::BaseObjects::OutputPort::
103 OutputPort( bool required )
104 : Superclass( required )
108 // -------------------------------------------------------------------------
109 cpPlugins::BaseObjects::OutputPort::
114 // -------------------------------------------------------------------------
115 void cpPlugins::BaseObjects::OutputPort::
122 // -------------------------------------------------------------------------
123 cpPlugins::BaseObjects::InputPort::
124 InputPort( bool required )
125 : Superclass( required )
129 // -------------------------------------------------------------------------
130 cpPlugins::BaseObjects::InputPort::
135 // -------------------------------------------------------------------------
136 cpPlugins::BaseObjects::MultipleInputsPort::
137 MultipleInputsPort( bool required )
138 : Superclass( required )
142 // -------------------------------------------------------------------------
143 cpPlugins::BaseObjects::MultipleInputsPort::
144 ~MultipleInputsPort( )
148 // -------------------------------------------------------------------------
149 void cpPlugins::BaseObjects::MultipleInputsPort::
150 Add( cpPlugins::BaseObjects::DataObject* o )
155 auto otype = std::type_index( typeid( *o ) );
156 if( this->m_Type == otype )
157 this->m_Data.push_back( o );
159 throw std::logic_error(
160 "cpPlugins::MultipleInputsPort: incompatible types \"" +
161 std::string( otype.name( ) ) + std::string( "\" and \"" ) +
162 std::string( this->m_Type.name( ) ) + std::string( "\"" )
167 // -------------------------------------------------------------------------
168 cpPlugins::BaseObjects::DataObject*
169 cpPlugins::BaseObjects::MultipleInputsPort::
170 Get( unsigned int i )
172 if( i < this->m_Data.size( ) )
173 return( this->m_Data[ i ].GetPointer( ) );
178 // -------------------------------------------------------------------------
179 const cpPlugins::BaseObjects::DataObject*
180 cpPlugins::BaseObjects::MultipleInputsPort::
181 Get( unsigned int i ) const
183 if( i < this->m_Data.size( ) )
184 return( this->m_Data[ i ].GetPointer( ) );
189 // -------------------------------------------------------------------------
190 unsigned int cpPlugins::BaseObjects::MultipleInputsPort::
193 return( this->m_Data.size( ) );
196 // -------------------------------------------------------------------------
197 bool cpPlugins::BaseObjects::MultipleInputsPort::
200 if( this->m_Data.size( ) > 0 )
201 return( this->m_Data[ 0 ].IsNotNull( ) );
206 // -------------------------------------------------------------------------
207 void cpPlugins::BaseObjects::MultipleInputsPort::
210 this->m_Data.clear( );