1 #include <cpPlugins/Interface/Parameters.h>
2 #include <cpPlugins/Interface/ProcessObject.h>
6 // -------------------------------------------------------------------------
8 ProcessObject* cpPlugins::Interface::Parameters::
11 return( this->m_Process );
14 // -------------------------------------------------------------------------
15 const cpPlugins::Interface::
16 ProcessObject* cpPlugins::Interface::Parameters::
17 GetProcessObject( ) const
19 return( this->m_Process );
22 // -------------------------------------------------------------------------
23 void cpPlugins::Interface::Parameters::
24 SetProcessObject( ProcessObject* v )
29 // -------------------------------------------------------------------------
30 void cpPlugins::Interface::Parameters::
33 this->Superclass::Modified( );
34 if( this->m_Process != NULL )
35 this->m_Process->Modified( );
38 // -------------------------------------------------------------------------
39 void cpPlugins::Interface::Parameters::
42 this->m_Parameters.clear( );
46 // -------------------------------------------------------------------------
47 void cpPlugins::Interface::Parameters::
48 ConfigureAsString( const TString& name, const TString& v )
50 this->m_Parameters[ name ] =
51 TParameter( Self::String, TValues( v, v ) );
55 // -------------------------------------------------------------------------
56 #define cpPlugins_Parameters_Configure( Y ) \
57 void cpPlugins::Interface::Parameters:: \
58 ConfigureAs##Y( const TString& name, const T##Y& v ) \
60 std::stringstream str; \
62 std::string s = str.str( ); \
63 this->m_Parameters[ name ] = \
64 TParameter( Self::Y, TValues( s, s ) ); \
68 cpPlugins_Parameters_Configure( Bool );
69 cpPlugins_Parameters_Configure( Int );
70 cpPlugins_Parameters_Configure( Uint );
71 cpPlugins_Parameters_Configure( Real );
73 // -------------------------------------------------------------------------
74 #define cpPlugins_Parameters_List_Configure( Y ) \
75 void cpPlugins::Interface::Parameters:: \
76 ConfigureAs##Y##List( const TString& name ) \
78 this->m_Parameters[ name ] = \
79 TParameter( Self::Y##List, TValues( "", "" ) ); \
83 cpPlugins_Parameters_List_Configure( String );
84 cpPlugins_Parameters_List_Configure( Bool );
85 cpPlugins_Parameters_List_Configure( Int );
86 cpPlugins_Parameters_List_Configure( Uint );
87 cpPlugins_Parameters_List_Configure( Real );
88 cpPlugins_Parameters_List_Configure( Index );
89 cpPlugins_Parameters_List_Configure( Point );
90 cpPlugins_Parameters_List_Configure( Vector );
92 // -------------------------------------------------------------------------
93 void cpPlugins::Interface::Parameters::
95 const TString& name, const std::vector< TString >& choices
98 // It is invalid not to give choices when configuring
99 if( choices.size( ) == 0 )
102 std::stringstream str_choices;
103 str_choices << choices[ 0 ];
104 for( unsigned int i = 1; i < choices.size( ); ++i )
105 str_choices << "#" << choices[ i ];
106 this->m_Parameters[ name ] =
107 TParameter( Self::Choices, TValues( str_choices.str( ), "" ) );
111 // -------------------------------------------------------------------------
112 void cpPlugins::Interface::Parameters::
113 GetNames( std::vector< TString >& container ) const
116 TParameters::const_iterator i = this->m_Parameters.begin( );
117 for( ; i != this->m_Parameters.end( ); ++i )
118 container.push_back( i->first );
121 // -------------------------------------------------------------------------
122 cpPlugins::Interface::Parameters::
123 Type cpPlugins::Interface::Parameters::
124 GetType( const TString& name ) const
126 TParameters::const_iterator i = this->m_Parameters.find( name );
127 if( i != this->m_Parameters.end( ) )
128 return( i->second.first );
130 return( Self::NoType );
133 // -------------------------------------------------------------------------
134 #define cpPlugins_Parameters_Has( Y ) \
135 bool cpPlugins::Interface::Parameters:: \
136 Has##Y( const TString& name ) const \
138 TParameters::const_iterator i = this->m_Parameters.find( name ); \
139 if( i != this->m_Parameters.end( ) ) \
140 return( i->second.first == Self::Y ); \
145 cpPlugins_Parameters_Has( String );
146 cpPlugins_Parameters_Has( Bool );
147 cpPlugins_Parameters_Has( Int );
148 cpPlugins_Parameters_Has( Uint );
149 cpPlugins_Parameters_Has( Real );
150 cpPlugins_Parameters_Has( Index );
151 cpPlugins_Parameters_Has( Point );
152 cpPlugins_Parameters_Has( Vector );
153 cpPlugins_Parameters_Has( StringList );
154 cpPlugins_Parameters_Has( BoolList );
155 cpPlugins_Parameters_Has( IntList );
156 cpPlugins_Parameters_Has( UintList );
157 cpPlugins_Parameters_Has( RealList );
158 cpPlugins_Parameters_Has( IndexList );
159 cpPlugins_Parameters_Has( PointList );
160 cpPlugins_Parameters_Has( VectorList );
161 cpPlugins_Parameters_Has( Choices );
163 // -------------------------------------------------------------------------
164 cpPlugins::Interface::Parameters::
165 TString cpPlugins::Interface::Parameters::
166 GetString( const TString& name ) const
168 TParameters::const_iterator i = this->m_Parameters.find( name );
169 if( i != this->m_Parameters.end( ) )
171 if( i->second.first == Self::String )
172 return( i->second.second.second );
178 // -------------------------------------------------------------------------
179 cpPlugins::Interface::Parameters::
180 TBool cpPlugins::Interface::Parameters::
181 GetBool( const TString& name ) const
183 TParameters::const_iterator i = this->m_Parameters.find( name );
184 if( i != this->m_Parameters.end( ) )
186 if( i->second.first == Self::Bool )
187 return( std::atoi( i->second.second.second.c_str( ) ) == 1 );
193 // -------------------------------------------------------------------------
194 cpPlugins::Interface::Parameters::
195 TInt cpPlugins::Interface::Parameters::
196 GetInt( const TString& name ) const
198 TParameters::const_iterator i = this->m_Parameters.find( name );
199 if( i != this->m_Parameters.end( ) )
201 if( i->second.first == Self::Int )
202 return( TInt( std::atoi( i->second.second.second.c_str( ) ) ) );
208 // -------------------------------------------------------------------------
209 cpPlugins::Interface::Parameters::
210 TUint cpPlugins::Interface::Parameters::
211 GetUint( const TString& name ) const
213 TParameters::const_iterator i = this->m_Parameters.find( name );
214 if( i != this->m_Parameters.end( ) )
216 if( i->second.first == Self::Uint )
217 return( TUint( std::atoi( i->second.second.second.c_str( ) ) ) );
220 return( TUint( 0 ) );
223 // -------------------------------------------------------------------------
224 cpPlugins::Interface::Parameters::
225 TReal cpPlugins::Interface::Parameters::
226 GetReal( const TString& name ) const
228 TParameters::const_iterator i = this->m_Parameters.find( name );
229 if( i != this->m_Parameters.end( ) )
231 if( i->second.first == Self::Real )
233 std::istringstream tok_str( i->second.second.second );
236 return( TReal( v ) );
241 return( TReal( 0 ) );
244 // -------------------------------------------------------------------------
245 void cpPlugins::Interface::Parameters::
246 GetStringList( std::vector< TString >& lst, const TString& name ) const
249 TParameters::const_iterator i = this->m_Parameters.find( name );
250 if( i == this->m_Parameters.end( ) )
252 if( i->second.first != Self::StringList )
255 std::istringstream str( i->second.second.second );
257 while( std::getline( str, token, '#' ) )
258 lst.push_back( token );
261 // -------------------------------------------------------------------------
262 void cpPlugins::Interface::Parameters::
263 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
266 TParameters::const_iterator i = this->m_Parameters.find( name );
267 if( i == this->m_Parameters.end( ) )
269 if( i->second.first != Self::BoolList )
272 std::istringstream str( i->second.second.second );
274 while( std::getline( str, token, '#' ) )
275 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
278 // -------------------------------------------------------------------------
279 void cpPlugins::Interface::Parameters::
280 GetIntList( std::vector< TInt >& lst, const TString& name ) const
283 TParameters::const_iterator i = this->m_Parameters.find( name );
284 if( i == this->m_Parameters.end( ) )
286 if( i->second.first != Self::IntList )
289 std::istringstream str( i->second.second.second );
291 while( std::getline( str, token, '#' ) )
292 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
295 // -------------------------------------------------------------------------
296 void cpPlugins::Interface::Parameters::
297 GetUintList( std::vector< TUint >& lst, const TString& name ) const
300 TParameters::const_iterator i = this->m_Parameters.find( name );
301 if( i == this->m_Parameters.end( ) )
303 if( i->second.first != Self::UintList )
306 std::istringstream str( i->second.second.second );
308 while( std::getline( str, token, '#' ) )
309 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
312 // -------------------------------------------------------------------------
313 void cpPlugins::Interface::Parameters::
314 GetRealList( std::vector< TReal >& lst, const TString& name ) const
317 TParameters::const_iterator i = this->m_Parameters.find( name );
318 if( i == this->m_Parameters.end( ) )
320 if( i->second.first != Self::RealList )
323 std::istringstream str( i->second.second.second );
325 while( std::getline( str, token, '#' ) )
327 std::istringstream tok_str( token );
330 lst.push_back( TReal( v ) );
335 // -------------------------------------------------------------------------
336 void cpPlugins::Interface::Parameters::
337 GetChoices( std::vector< TString >& choices, const TString& name ) const
340 TParameters::const_iterator i = this->m_Parameters.find( name );
341 if( i == this->m_Parameters.end( ) )
343 if( i->second.first != Self::Choices )
346 std::istringstream str( i->second.second.first );
348 while( std::getline( str, token, '#' ) )
349 choices.push_back( token );
352 // -------------------------------------------------------------------------
353 cpPlugins::Interface::Parameters::
354 TString cpPlugins::Interface::Parameters::
355 GetSelectedChoice( const TString& name ) const
357 TParameters::const_iterator i = this->m_Parameters.find( name );
358 if( i == this->m_Parameters.end( ) )
360 if( i->second.first != Self::Choices )
362 return( i->second.second.second );
365 // -------------------------------------------------------------------------
366 void cpPlugins::Interface::Parameters::
367 SetString( const TString& name, const TString& v )
369 TParameters::iterator i = this->m_Parameters.find( name );
370 if( i == this->m_Parameters.end( ) )
372 if( i->second.first != Self::String )
374 i->second.second.second = v;
378 // -------------------------------------------------------------------------
379 #define cpPlugins_Parameters_Set( Y ) \
380 void cpPlugins::Interface::Parameters:: \
381 Set##Y( const TString& name, const T##Y& v ) \
383 TParameters::iterator i = this->m_Parameters.find( name ); \
384 if( i == this->m_Parameters.end( ) ) \
386 if( i->second.first != Self::Y ) \
388 std::stringstream str; \
390 i->second.second.second = str.str( ); \
394 cpPlugins_Parameters_Set( Bool );
395 cpPlugins_Parameters_Set( Int );
396 cpPlugins_Parameters_Set( Uint );
397 cpPlugins_Parameters_Set( Real );
399 // -------------------------------------------------------------------------
400 #define cpPlugins_Parameters_Add( Y ) \
401 void cpPlugins::Interface::Parameters:: \
402 AddTo##Y##List( const TString& name, const T##Y& v ) \
404 TParameters::iterator i = this->m_Parameters.find( name ); \
405 if( i == this->m_Parameters.end( ) ) \
407 if( i->second.first != Self::Y##List ) \
409 std::stringstream str; \
410 if( i->second.second.second == "" ) \
414 i->second.second.second += str.str( ); \
418 cpPlugins_Parameters_Add( String );
419 cpPlugins_Parameters_Add( Bool );
420 cpPlugins_Parameters_Add( Int );
421 cpPlugins_Parameters_Add( Uint );
422 cpPlugins_Parameters_Add( Real );
424 // -------------------------------------------------------------------------
425 #define cpPlugins_Parameters_Clear( Y ) \
426 void cpPlugins::Interface::Parameters:: \
427 Clear##Y##List( const TString& name ) \
429 TParameters::iterator i = this->m_Parameters.find( name ); \
430 if( i == this->m_Parameters.end( ) ) \
432 if( i->second.first != Self::Y##List ) \
434 i->second.second.second = ""; \
438 cpPlugins_Parameters_Clear( String );
439 cpPlugins_Parameters_Clear( Bool );
440 cpPlugins_Parameters_Clear( Int );
441 cpPlugins_Parameters_Clear( Uint );
442 cpPlugins_Parameters_Clear( Real );
443 cpPlugins_Parameters_Clear( Index );
444 cpPlugins_Parameters_Clear( Point );
445 cpPlugins_Parameters_Clear( Vector );
447 // -------------------------------------------------------------------------
448 bool cpPlugins::Interface::Parameters::
449 SetSelectedChoice( const TString& name, const TString& choice )
451 TParameters::iterator i = this->m_Parameters.find( name );
452 if( i == this->m_Parameters.end( ) )
454 if( i->second.first != Self::Choices )
456 if( i->second.second.first.find( choice ) != std::string::npos )
458 i->second.second.second = choice;
466 // -------------------------------------------------------------------------
467 cpPlugins::Interface::Parameters::
475 // -------------------------------------------------------------------------
476 cpPlugins::Interface::Parameters::
481 // -------------------------------------------------------------------------
482 void cpPlugins::Interface::Parameters::
483 PrintSelf( std::ostream& os, itk::Indent indent ) const
485 TParameters::const_iterator i = this->m_Parameters.begin( );
486 for( ; i != this->m_Parameters.end( ); ++i )
489 << i->second.first << " | "
490 << i->second.second.first << " | "
491 << i->second.second.second << ")"