]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BaseObjects/Port.cxx
06b10ee097a2d6100eecabec1d79bf80539e2dea
[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   /* TODO
153      if( o == NULL )
154      return;
155      auto otype = std::type_index( typeid( *o ) );
156      if( this->m_Type == otype )
157      this->m_Data.push_back( o );
158      else
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( "\"" )
163      );
164   */
165 }
166
167 // -------------------------------------------------------------------------
168 cpPlugins::BaseObjects::DataObject*
169 cpPlugins::BaseObjects::MultipleInputsPort::
170 Get( unsigned int i )
171 {
172   if( i < this->m_Data.size( ) )
173     return( this->m_Data[ i ].GetPointer( ) );
174   else
175     return( NULL );
176 }
177
178 // -------------------------------------------------------------------------
179 const cpPlugins::BaseObjects::DataObject*
180 cpPlugins::BaseObjects::MultipleInputsPort::
181 Get( unsigned int i ) const
182 {
183   if( i < this->m_Data.size( ) )
184     return( this->m_Data[ i ].GetPointer( ) );
185   else
186     return( NULL );
187 }
188
189 // -------------------------------------------------------------------------
190 unsigned int cpPlugins::BaseObjects::MultipleInputsPort::
191 Size( ) const
192 {
193   return( this->m_Data.size( ) );
194 }
195
196 // -------------------------------------------------------------------------
197 bool cpPlugins::BaseObjects::MultipleInputsPort::
198 IsValid( ) const
199 {
200   if( this->m_Data.size( ) > 0 )
201     return( this->m_Data[ 0 ].IsNotNull( ) );
202   else
203     return( false );
204 }
205
206 // -------------------------------------------------------------------------
207 void cpPlugins::BaseObjects::MultipleInputsPort::
208 Clear( )
209 {
210   this->m_Data.clear( );
211 }
212
213 // eof - $RCSfile$