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 )
232 return( TReal( std::atof( i->second.second.second.c_str( ) ) ) );
235 return( TReal( 0 ) );
238 // -------------------------------------------------------------------------
239 void cpPlugins::Interface::Parameters::
240 GetStringList( std::vector< TString >& lst, const TString& name ) const
243 TParameters::const_iterator i = this->m_Parameters.find( name );
244 if( i == this->m_Parameters.end( ) )
246 if( i->second.first != Self::StringList )
249 std::istringstream str( i->second.second.second );
251 while( std::getline( str, token, '#' ) )
252 lst.push_back( token );
255 // -------------------------------------------------------------------------
256 void cpPlugins::Interface::Parameters::
257 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
260 TParameters::const_iterator i = this->m_Parameters.find( name );
261 if( i == this->m_Parameters.end( ) )
263 if( i->second.first != Self::BoolList )
266 std::istringstream str( i->second.second.second );
268 while( std::getline( str, token, '#' ) )
269 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
272 // -------------------------------------------------------------------------
273 void cpPlugins::Interface::Parameters::
274 GetIntList( std::vector< TInt >& lst, const TString& name ) const
277 TParameters::const_iterator i = this->m_Parameters.find( name );
278 if( i == this->m_Parameters.end( ) )
280 if( i->second.first != Self::IntList )
283 std::istringstream str( i->second.second.second );
285 while( std::getline( str, token, '#' ) )
286 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
289 // -------------------------------------------------------------------------
290 void cpPlugins::Interface::Parameters::
291 GetUintList( std::vector< TUint >& lst, const TString& name ) const
294 TParameters::const_iterator i = this->m_Parameters.find( name );
295 if( i == this->m_Parameters.end( ) )
297 if( i->second.first != Self::UintList )
300 std::istringstream str( i->second.second.second );
302 while( std::getline( str, token, '#' ) )
303 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
306 // -------------------------------------------------------------------------
307 void cpPlugins::Interface::Parameters::
308 GetRealList( std::vector< TReal >& lst, const TString& name ) const
311 TParameters::const_iterator i = this->m_Parameters.find( name );
312 if( i == this->m_Parameters.end( ) )
314 if( i->second.first != Self::RealList )
317 std::istringstream str( i->second.second.second );
319 while( std::getline( str, token, '#' ) )
320 lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
323 // -------------------------------------------------------------------------
324 void cpPlugins::Interface::Parameters::
325 GetChoices( std::vector< TString >& choices, const TString& name ) const
328 TParameters::const_iterator i = this->m_Parameters.find( name );
329 if( i == this->m_Parameters.end( ) )
331 if( i->second.first != Self::Choices )
334 std::istringstream str( i->second.second.first );
336 while( std::getline( str, token, '#' ) )
337 choices.push_back( token );
340 // -------------------------------------------------------------------------
341 cpPlugins::Interface::Parameters::
342 TString cpPlugins::Interface::Parameters::
343 GetSelectedChoice( const TString& name ) const
345 TParameters::const_iterator i = this->m_Parameters.find( name );
346 if( i == this->m_Parameters.end( ) )
348 if( i->second.first != Self::Choices )
350 return( i->second.second.second );
353 // -------------------------------------------------------------------------
354 void cpPlugins::Interface::Parameters::
355 SetString( const TString& name, const TString& v )
357 TParameters::iterator i = this->m_Parameters.find( name );
358 if( i == this->m_Parameters.end( ) )
360 if( i->second.first != Self::String )
362 i->second.second.second = v;
366 // -------------------------------------------------------------------------
367 #define cpPlugins_Parameters_Set( Y ) \
368 void cpPlugins::Interface::Parameters:: \
369 Set##Y( const TString& name, const T##Y& v ) \
371 TParameters::iterator i = this->m_Parameters.find( name ); \
372 if( i == this->m_Parameters.end( ) ) \
374 if( i->second.first != Self::Y ) \
376 std::stringstream str; \
378 i->second.second.second = str.str( ); \
382 cpPlugins_Parameters_Set( Bool );
383 cpPlugins_Parameters_Set( Int );
384 cpPlugins_Parameters_Set( Uint );
385 cpPlugins_Parameters_Set( Real );
387 // -------------------------------------------------------------------------
388 #define cpPlugins_Parameters_Add( Y ) \
389 void cpPlugins::Interface::Parameters:: \
390 AddTo##Y##List( const TString& name, const T##Y& v ) \
392 TParameters::iterator i = this->m_Parameters.find( name ); \
393 if( i == this->m_Parameters.end( ) ) \
395 if( i->second.first != Self::Y##List ) \
397 std::stringstream str; \
398 if( i->second.second.second == "" ) \
402 i->second.second.second += str.str( ); \
406 cpPlugins_Parameters_Add( String );
407 cpPlugins_Parameters_Add( Bool );
408 cpPlugins_Parameters_Add( Int );
409 cpPlugins_Parameters_Add( Uint );
410 cpPlugins_Parameters_Add( Real );
412 // -------------------------------------------------------------------------
413 #define cpPlugins_Parameters_Clear( Y ) \
414 void cpPlugins::Interface::Parameters:: \
415 Clear##Y##List( const TString& name ) \
417 TParameters::iterator i = this->m_Parameters.find( name ); \
418 if( i == this->m_Parameters.end( ) ) \
420 if( i->second.first != Self::Y##List ) \
422 i->second.second.second = ""; \
426 cpPlugins_Parameters_Clear( String );
427 cpPlugins_Parameters_Clear( Bool );
428 cpPlugins_Parameters_Clear( Int );
429 cpPlugins_Parameters_Clear( Uint );
430 cpPlugins_Parameters_Clear( Real );
431 cpPlugins_Parameters_Clear( Index );
432 cpPlugins_Parameters_Clear( Point );
433 cpPlugins_Parameters_Clear( Vector );
435 // -------------------------------------------------------------------------
436 bool cpPlugins::Interface::Parameters::
437 SetSelectedChoice( const TString& name, const TString& choice )
439 TParameters::iterator i = this->m_Parameters.find( name );
440 if( i == this->m_Parameters.end( ) )
442 if( i->second.first != Self::Choices )
444 if( i->second.second.first.find( choice ) != std::string::npos )
446 i->second.second.second = choice;
454 // -------------------------------------------------------------------------
455 cpPlugins::Interface::Parameters::
463 // -------------------------------------------------------------------------
464 cpPlugins::Interface::Parameters::
469 // -------------------------------------------------------------------------
470 void cpPlugins::Interface::Parameters::
471 PrintSelf( std::ostream& os, itk::Indent indent ) const
473 TParameters::const_iterator i = this->m_Parameters.begin( );
474 for( ; i != this->m_Parameters.end( ); ++i )
477 << i->second.first << " | "
478 << i->second.second.first << " | "
479 << i->second.second.second << ")"