]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BaseObjects/Port.cxx
55864c2f49adac8ad4718f07b92162fd809d5c05
[cpPlugins.git] / lib / cpPlugins / BaseObjects / Port.cxx
1 #include <cpPlugins/BaseObjects/Port.h>
2
3 // -------------------------------------------------------------------------
4 cpPlugins::BaseObjects::Port::
5 Port( bool required )
6   : m_Required( required )
7 {
8 }
9
10 // -------------------------------------------------------------------------
11 cpPlugins::BaseObjects::Port::
12 ~Port( )
13 {
14 }
15
16 // -------------------------------------------------------------------------
17 bool cpPlugins::BaseObjects::Port::
18 IsRequired( ) const
19 {
20   return( this->m_Required );
21 }
22
23 // -------------------------------------------------------------------------
24 void cpPlugins::BaseObjects::Port::
25 Clear( )
26 {
27 }
28
29 // -------------------------------------------------------------------------
30 cpPlugins::BaseObjects::SingleDataPort::
31 SingleDataPort( bool required )
32   : Superclass( required )
33 {
34 }
35
36 // -------------------------------------------------------------------------
37 cpPlugins::BaseObjects::SingleDataPort::
38 ~SingleDataPort( )
39 {
40 }
41
42 // -------------------------------------------------------------------------
43 void cpPlugins::BaseObjects::SingleDataPort::
44 Add( cpPlugins::BaseObjects::DataObject* o )
45 {
46   if( this->m_Sample.IsNull( ) )
47     throw std::logic_error(
48       "cpPlugins::SingleDataPort: Port not yet configured"
49       );
50   if( o != NULL )
51   {
52     if( this->m_Sample->IsCompatible( o ) )
53       this->m_Data = o;
54     else
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( ) ) +
59         std::string( "\"" )
60         );
61   }
62   else
63     this->m_Data = NULL;
64 }
65
66 // -------------------------------------------------------------------------
67 cpPlugins::BaseObjects::DataObject* cpPlugins::BaseObjects::SingleDataPort::
68 Get( unsigned int i )
69 {
70   return( this->m_Data.GetPointer( ) );
71 }
72
73 // -------------------------------------------------------------------------
74 const cpPlugins::BaseObjects::DataObject* cpPlugins::BaseObjects::SingleDataPort::
75 Get( unsigned int i ) const
76 {
77   return( this->m_Data.GetPointer( ) );
78 }
79
80 // -------------------------------------------------------------------------
81 unsigned int cpPlugins::BaseObjects::SingleDataPort::
82 Size( ) const
83 {
84   return( 1 );
85 }
86
87 // -------------------------------------------------------------------------
88 bool cpPlugins::BaseObjects::SingleDataPort::
89 IsValid( ) const
90 {
91   return( this->m_Data.IsNotNull( ) );
92 }
93
94 // -------------------------------------------------------------------------
95 void cpPlugins::BaseObjects::SingleDataPort::
96 Clear( )
97 {
98   this->m_Data = NULL;
99 }
100
101 // -------------------------------------------------------------------------
102 cpPlugins::BaseObjects::OutputPort::
103 OutputPort( bool required )
104   : Superclass( required )
105 {
106 }
107
108 // -------------------------------------------------------------------------
109 cpPlugins::BaseObjects::OutputPort::
110 ~OutputPort( )
111 {
112 }
113
114 // -------------------------------------------------------------------------
115 void cpPlugins::BaseObjects::OutputPort::
116 Set( DataObject* o )
117 {
118   this->m_Sample = o;
119   this->m_Data = o;
120 }
121
122 // -------------------------------------------------------------------------
123 cpPlugins::BaseObjects::InputPort::
124 InputPort( bool required )
125   : Superclass( required )
126 {
127 }
128
129 // -------------------------------------------------------------------------
130 cpPlugins::BaseObjects::InputPort::
131 ~InputPort( )
132 {
133 }
134
135 // -------------------------------------------------------------------------
136 cpPlugins::BaseObjects::MultipleInputsPort::
137 MultipleInputsPort( bool required )
138   : Superclass( required )
139 {
140 }
141
142 // -------------------------------------------------------------------------
143 cpPlugins::BaseObjects::MultipleInputsPort::
144 ~MultipleInputsPort( )
145 {
146 }
147
148 // -------------------------------------------------------------------------
149 void cpPlugins::BaseObjects::MultipleInputsPort::
150 Add( cpPlugins::BaseObjects::DataObject* o )
151 {
152   if( this->m_Sample.IsNull( ) )
153     throw std::logic_error(
154       "cpPlugins::SingleDataPort: Port not yet configured"
155       );
156   if( o != NULL )
157   {
158     if( this->m_Sample->IsCompatible( o ) )
159     {
160       this->m_Data.push_back( o );
161     }
162     else
163       throw std::logic_error(
164         "cpPlugins::SingleDataPort: incompatible types \"" +
165         std::string( typeid( *o ).name( ) ) + std::string( "\" and \"" ) +
166         std::string( typeid( *( this->m_Sample.GetPointer( ) ) ).name( ) ) +
167         std::string( "\"" )
168         );
169
170   } // fi
171 }
172
173 // -------------------------------------------------------------------------
174 cpPlugins::BaseObjects::DataObject*
175 cpPlugins::BaseObjects::MultipleInputsPort::
176 Get( unsigned int i )
177 {
178   if( i < this->m_Data.size( ) )
179     return( this->m_Data[ i ].GetPointer( ) );
180   else
181     return( NULL );
182 }
183
184 // -------------------------------------------------------------------------
185 const cpPlugins::BaseObjects::DataObject*
186 cpPlugins::BaseObjects::MultipleInputsPort::
187 Get( unsigned int i ) const
188 {
189   if( i < this->m_Data.size( ) )
190     return( this->m_Data[ i ].GetPointer( ) );
191   else
192     return( NULL );
193 }
194
195 // -------------------------------------------------------------------------
196 unsigned int cpPlugins::BaseObjects::MultipleInputsPort::
197 Size( ) const
198 {
199   return( this->m_Data.size( ) );
200 }
201
202 // -------------------------------------------------------------------------
203 bool cpPlugins::BaseObjects::MultipleInputsPort::
204 IsValid( ) const
205 {
206   if( this->m_Data.size( ) > 0 )
207     return( this->m_Data[ 0 ].IsNotNull( ) );
208   else
209     return( false );
210 }
211
212 // -------------------------------------------------------------------------
213 void cpPlugins::BaseObjects::MultipleInputsPort::
214 Clear( )
215 {
216   this->m_Data.clear( );
217 }
218
219 // -------------------------------------------------------------------------
220 void cpPlugins::BaseObjects::MultipleInputsPort::
221 Delete( unsigned int id )
222 {
223   if( id < this->m_Data.size( ) )
224   {
225     this->m_Data[ id ] = NULL;
226     this->m_Data.erase( this->m_Data.begin( ) + id );
227
228   } // fi
229 }
230
231 // eof - $RCSfile$