1 #include <cpPlugins/Interface/Parameters.h>
2 #include <cpPlugins/Interface/ProcessObject.h>
6 // -------------------------------------------------------------------------
7 const cpPlugins::Interface::
8 ProcessObject* cpPlugins::Interface::Parameters::
9 GetProcessObject( ) const
11 return( this->m_Process );
14 // -------------------------------------------------------------------------
15 void cpPlugins::Interface::Parameters::
16 SetProcessObject( ProcessObject* v )
21 // -------------------------------------------------------------------------
22 void cpPlugins::Interface::Parameters::
25 this->Superclass::Modified( );
26 if( this->m_Process != NULL )
27 this->m_Process->Modified( );
30 // -------------------------------------------------------------------------
31 void cpPlugins::Interface::Parameters::
34 this->m_Parameters.clear( );
38 // -------------------------------------------------------------------------
39 void cpPlugins::Interface::Parameters::
40 ConfigureAsString( const TString& name, const TString& v )
42 this->m_Parameters[ name ] = TParameter( Self::String, TValues( v, v ) );
46 // -------------------------------------------------------------------------
47 #define cpPlugins_Parameters_Configure( Y ) \
48 void cpPlugins::Interface::Parameters:: \
49 ConfigureAs##Y( const TString& name, const T##Y& v ) \
51 std::stringstream str; \
53 std::string s = str.str( ); \
54 this->m_Parameters[ name ] = \
55 TParameter( Self::Y, TValues( s, s ) ); \
59 cpPlugins_Parameters_Configure( Bool );
60 cpPlugins_Parameters_Configure( Int );
61 cpPlugins_Parameters_Configure( Uint );
62 cpPlugins_Parameters_Configure( Real );
64 // -------------------------------------------------------------------------
65 #define cpPlugins_Parameters_List_Configure( Y ) \
66 void cpPlugins::Interface::Parameters:: \
67 ConfigureAs##Y##List( const TString& name ) \
69 this->m_Parameters[ name ] = \
70 TParameter( Self::Y##List, TValues( "", "" ) ); \
74 cpPlugins_Parameters_List_Configure( String );
75 cpPlugins_Parameters_List_Configure( Bool );
76 cpPlugins_Parameters_List_Configure( Int );
77 cpPlugins_Parameters_List_Configure( Uint );
78 cpPlugins_Parameters_List_Configure( Real );
79 cpPlugins_Parameters_List_Configure( Index );
80 cpPlugins_Parameters_List_Configure( Point );
82 // -------------------------------------------------------------------------
83 void cpPlugins::Interface::Parameters::
85 const TString& name, const std::vector< TString >& choices
88 // It is invalid not to give choices when configuring
89 if( choices.size( ) == 0 )
92 std::stringstream str_choices;
93 str_choices << choices[ 0 ];
94 for( unsigned int i = 1; i < choices.size( ); ++i )
95 str_choices << "#" << choices[ i ];
96 this->m_Parameters[ name ] =
97 TParameter( Self::Choices, TValues( str_choices.str( ), "" ) );
101 // -------------------------------------------------------------------------
102 void cpPlugins::Interface::Parameters::
103 GetNames( std::vector< TString >& container ) const
106 TParameters::const_iterator i = this->m_Parameters.begin( );
107 for( ; i != this->m_Parameters.end( ); ++i )
108 container.push_back( i->first );
111 // -------------------------------------------------------------------------
112 cpPlugins::Interface::Parameters::
113 Type cpPlugins::Interface::Parameters::
114 GetType( const TString& name ) const
116 TParameters::const_iterator i = this->m_Parameters.find( name );
117 if( i != this->m_Parameters.end( ) )
118 return( i->second.first );
120 return( Self::NoType );
123 // -------------------------------------------------------------------------
124 #define cpPlugins_Parameters_Has( Y ) \
125 bool cpPlugins::Interface::Parameters:: \
126 Has##Y( const TString& name ) const \
128 TParameters::const_iterator i = this->m_Parameters.find( name ); \
129 if( i != this->m_Parameters.end( ) ) \
130 return( i->second.first == Self::Y ); \
135 cpPlugins_Parameters_Has( String );
136 cpPlugins_Parameters_Has( Bool );
137 cpPlugins_Parameters_Has( Int );
138 cpPlugins_Parameters_Has( Uint );
139 cpPlugins_Parameters_Has( Real );
140 cpPlugins_Parameters_Has( Index );
141 cpPlugins_Parameters_Has( Point );
142 cpPlugins_Parameters_Has( StringList );
143 cpPlugins_Parameters_Has( BoolList );
144 cpPlugins_Parameters_Has( IntList );
145 cpPlugins_Parameters_Has( UintList );
146 cpPlugins_Parameters_Has( RealList );
147 cpPlugins_Parameters_Has( IndexList );
148 cpPlugins_Parameters_Has( PointList );
149 cpPlugins_Parameters_Has( Choices );
151 // -------------------------------------------------------------------------
152 cpPlugins::Interface::Parameters::
153 TString cpPlugins::Interface::Parameters::
154 GetString( const TString& name ) const
156 TParameters::const_iterator i = this->m_Parameters.find( name );
157 if( i != this->m_Parameters.end( ) )
159 if( i->second.first == Self::String )
160 return( i->second.second.second );
166 // -------------------------------------------------------------------------
167 cpPlugins::Interface::Parameters::
168 TBool cpPlugins::Interface::Parameters::
169 GetBool( const TString& name ) const
171 TParameters::const_iterator i = this->m_Parameters.find( name );
172 if( i != this->m_Parameters.end( ) )
174 if( i->second.first == Self::Bool )
175 return( std::atoi( i->second.second.second.c_str( ) ) == 1 );
181 // -------------------------------------------------------------------------
182 cpPlugins::Interface::Parameters::
183 TInt cpPlugins::Interface::Parameters::
184 GetInt( const TString& name ) const
186 TParameters::const_iterator i = this->m_Parameters.find( name );
187 if( i != this->m_Parameters.end( ) )
189 if( i->second.first == Self::Int )
190 return( TInt( std::atoi( i->second.second.second.c_str( ) ) ) );
196 // -------------------------------------------------------------------------
197 cpPlugins::Interface::Parameters::
198 TUint cpPlugins::Interface::Parameters::
199 GetUint( const TString& name ) const
201 TParameters::const_iterator i = this->m_Parameters.find( name );
202 if( i != this->m_Parameters.end( ) )
204 if( i->second.first == Self::Uint )
205 return( TUint( std::atoi( i->second.second.second.c_str( ) ) ) );
208 return( TUint( 0 ) );
211 // -------------------------------------------------------------------------
212 cpPlugins::Interface::Parameters::
213 TReal cpPlugins::Interface::Parameters::
214 GetReal( const TString& name ) const
216 TParameters::const_iterator i = this->m_Parameters.find( name );
217 if( i != this->m_Parameters.end( ) )
219 if( i->second.first == Self::Real )
220 return( TReal( std::atof( i->second.second.second.c_str( ) ) ) );
223 return( TReal( 0 ) );
226 // -------------------------------------------------------------------------
227 void cpPlugins::Interface::Parameters::
228 GetStringList( std::vector< TString >& lst, const TString& name ) const
231 TParameters::const_iterator i = this->m_Parameters.find( name );
232 if( i == this->m_Parameters.end( ) )
234 if( i->second.first != Self::StringList )
237 std::istringstream str( i->second.second.second );
239 while( std::getline( str, token, '#' ) )
240 lst.push_back( token );
243 // -------------------------------------------------------------------------
244 void cpPlugins::Interface::Parameters::
245 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
248 TParameters::const_iterator i = this->m_Parameters.find( name );
249 if( i == this->m_Parameters.end( ) )
251 if( i->second.first != Self::BoolList )
254 std::istringstream str( i->second.second.second );
256 while( std::getline( str, token, '#' ) )
257 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
260 // -------------------------------------------------------------------------
261 void cpPlugins::Interface::Parameters::
262 GetIntList( std::vector< TInt >& lst, const TString& name ) const
265 TParameters::const_iterator i = this->m_Parameters.find( name );
266 if( i == this->m_Parameters.end( ) )
268 if( i->second.first != Self::IntList )
271 std::istringstream str( i->second.second.second );
273 while( std::getline( str, token, '#' ) )
274 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
277 // -------------------------------------------------------------------------
278 void cpPlugins::Interface::Parameters::
279 GetUintList( std::vector< TUint >& lst, const TString& name ) const
282 TParameters::const_iterator i = this->m_Parameters.find( name );
283 if( i == this->m_Parameters.end( ) )
285 if( i->second.first != Self::UintList )
288 std::istringstream str( i->second.second.second );
290 while( std::getline( str, token, '#' ) )
291 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
294 // -------------------------------------------------------------------------
295 void cpPlugins::Interface::Parameters::
296 GetRealList( std::vector< TReal >& lst, const TString& name ) const
299 TParameters::const_iterator i = this->m_Parameters.find( name );
300 if( i == this->m_Parameters.end( ) )
302 if( i->second.first != Self::RealList )
305 std::istringstream str( i->second.second.second );
307 while( std::getline( str, token, '#' ) )
308 lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
311 // -------------------------------------------------------------------------
312 void cpPlugins::Interface::Parameters::
313 GetChoices( std::vector< TString >& choices, const TString& name ) const
316 TParameters::const_iterator i = this->m_Parameters.find( name );
317 if( i == this->m_Parameters.end( ) )
319 if( i->second.first != Self::Choices )
322 std::istringstream str( i->second.second.first );
324 while( std::getline( str, token, '#' ) )
325 choices.push_back( token );
328 // -------------------------------------------------------------------------
329 cpPlugins::Interface::Parameters::
330 TString cpPlugins::Interface::Parameters::
331 GetSelectedChoice( const TString& name ) const
333 TParameters::const_iterator i = this->m_Parameters.find( name );
334 if( i == this->m_Parameters.end( ) )
336 if( i->second.first != Self::Choices )
338 return( i->second.second.second );
341 // -------------------------------------------------------------------------
342 void cpPlugins::Interface::Parameters::
343 SetString( const TString& name, const TString& v )
345 TParameters::iterator i = this->m_Parameters.find( name );
346 if( i == this->m_Parameters.end( ) )
348 if( i->second.first != Self::String )
350 i->second.second.second = v;
354 // -------------------------------------------------------------------------
355 #define cpPlugins_Parameters_Set( Y ) \
356 void cpPlugins::Interface::Parameters:: \
357 Set##Y( const TString& name, const T##Y& v ) \
359 TParameters::iterator i = this->m_Parameters.find( name ); \
360 if( i == this->m_Parameters.end( ) ) \
362 if( i->second.first != Self::Y ) \
364 std::stringstream str; \
366 i->second.second.second = str.str( ); \
370 cpPlugins_Parameters_Set( Bool );
371 cpPlugins_Parameters_Set( Int );
372 cpPlugins_Parameters_Set( Uint );
373 cpPlugins_Parameters_Set( Real );
375 // -------------------------------------------------------------------------
376 #define cpPlugins_Parameters_Add( Y ) \
377 void cpPlugins::Interface::Parameters:: \
378 AddTo##Y##List( const TString& name, const T##Y& v ) \
380 TParameters::iterator i = this->m_Parameters.find( name ); \
381 if( i == this->m_Parameters.end( ) ) \
383 if( i->second.first != Self::Y##List ) \
385 std::stringstream str; \
386 if( i->second.second.second == "" ) \
390 i->second.second.second += str.str( ); \
394 cpPlugins_Parameters_Add( String );
395 cpPlugins_Parameters_Add( Bool );
396 cpPlugins_Parameters_Add( Int );
397 cpPlugins_Parameters_Add( Uint );
398 cpPlugins_Parameters_Add( Real );
400 // -------------------------------------------------------------------------
401 #define cpPlugins_Parameters_Clear( Y ) \
402 void cpPlugins::Interface::Parameters:: \
403 Clear##Y##List( const TString& name ) \
405 TParameters::iterator i = this->m_Parameters.find( name ); \
406 if( i == this->m_Parameters.end( ) ) \
408 if( i->second.first != Self::Y##List ) \
410 i->second.second.second = ""; \
414 cpPlugins_Parameters_Clear( String );
415 cpPlugins_Parameters_Clear( Bool );
416 cpPlugins_Parameters_Clear( Int );
417 cpPlugins_Parameters_Clear( Uint );
418 cpPlugins_Parameters_Clear( Real );
419 cpPlugins_Parameters_Clear( Index );
420 cpPlugins_Parameters_Clear( Point );
422 // -------------------------------------------------------------------------
423 bool cpPlugins::Interface::Parameters::
424 SetSelectedChoice( const TString& name, const TString& choice )
426 TParameters::iterator i = this->m_Parameters.find( name );
427 if( i == this->m_Parameters.end( ) )
429 if( i->second.first != Self::Choices )
431 if( i->second.second.first.find( choice ) != std::string::npos )
433 i->second.second.second = choice;
441 // -------------------------------------------------------------------------
442 cpPlugins::Interface::Parameters::
450 // -------------------------------------------------------------------------
451 cpPlugins::Interface::Parameters::
456 // -------------------------------------------------------------------------
457 void cpPlugins::Interface::Parameters::
458 PrintSelf( std::ostream& os, itk::Indent indent ) const
460 TParameters::const_iterator i = this->m_Parameters.begin( );
461 for( ; i != this->m_Parameters.end( ); ++i )
464 << i->second.first << " | "
465 << i->second.second.first << " | "
466 << i->second.second.second << ")"