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 ] = TParameter( Self::String, TValues( v, v ) );
54 // -------------------------------------------------------------------------
55 #define cpPlugins_Parameters_Configure( Y ) \
56 void cpPlugins::Interface::Parameters:: \
57 ConfigureAs##Y( const TString& name, const T##Y& v ) \
59 std::stringstream str; \
61 std::string s = str.str( ); \
62 this->m_Parameters[ name ] = \
63 TParameter( Self::Y, TValues( s, s ) ); \
67 cpPlugins_Parameters_Configure( Bool );
68 cpPlugins_Parameters_Configure( Int );
69 cpPlugins_Parameters_Configure( Uint );
70 cpPlugins_Parameters_Configure( Real );
72 // -------------------------------------------------------------------------
73 #define cpPlugins_Parameters_List_Configure( Y ) \
74 void cpPlugins::Interface::Parameters:: \
75 ConfigureAs##Y##List( const TString& name ) \
77 this->m_Parameters[ name ] = \
78 TParameter( Self::Y##List, TValues( "", "" ) ); \
82 cpPlugins_Parameters_List_Configure( String );
83 cpPlugins_Parameters_List_Configure( Bool );
84 cpPlugins_Parameters_List_Configure( Int );
85 cpPlugins_Parameters_List_Configure( Uint );
86 cpPlugins_Parameters_List_Configure( Real );
87 cpPlugins_Parameters_List_Configure( Index );
88 cpPlugins_Parameters_List_Configure( Point );
90 // -------------------------------------------------------------------------
91 void cpPlugins::Interface::Parameters::
93 const TString& name, const std::vector< TString >& choices
96 // It is invalid not to give choices when configuring
97 if( choices.size( ) == 0 )
100 std::stringstream str_choices;
101 str_choices << choices[ 0 ];
102 for( unsigned int i = 1; i < choices.size( ); ++i )
103 str_choices << "#" << choices[ i ];
104 this->m_Parameters[ name ] =
105 TParameter( Self::Choices, TValues( str_choices.str( ), "" ) );
109 // -------------------------------------------------------------------------
110 void cpPlugins::Interface::Parameters::
111 GetNames( std::vector< TString >& container ) const
114 TParameters::const_iterator i = this->m_Parameters.begin( );
115 for( ; i != this->m_Parameters.end( ); ++i )
116 container.push_back( i->first );
119 // -------------------------------------------------------------------------
120 cpPlugins::Interface::Parameters::
121 Type cpPlugins::Interface::Parameters::
122 GetType( const TString& name ) const
124 TParameters::const_iterator i = this->m_Parameters.find( name );
125 if( i != this->m_Parameters.end( ) )
126 return( i->second.first );
128 return( Self::NoType );
131 // -------------------------------------------------------------------------
132 #define cpPlugins_Parameters_Has( Y ) \
133 bool cpPlugins::Interface::Parameters:: \
134 Has##Y( const TString& name ) const \
136 TParameters::const_iterator i = this->m_Parameters.find( name ); \
137 if( i != this->m_Parameters.end( ) ) \
138 return( i->second.first == Self::Y ); \
143 cpPlugins_Parameters_Has( String );
144 cpPlugins_Parameters_Has( Bool );
145 cpPlugins_Parameters_Has( Int );
146 cpPlugins_Parameters_Has( Uint );
147 cpPlugins_Parameters_Has( Real );
148 cpPlugins_Parameters_Has( Index );
149 cpPlugins_Parameters_Has( Point );
150 cpPlugins_Parameters_Has( StringList );
151 cpPlugins_Parameters_Has( BoolList );
152 cpPlugins_Parameters_Has( IntList );
153 cpPlugins_Parameters_Has( UintList );
154 cpPlugins_Parameters_Has( RealList );
155 cpPlugins_Parameters_Has( IndexList );
156 cpPlugins_Parameters_Has( PointList );
157 cpPlugins_Parameters_Has( Choices );
159 // -------------------------------------------------------------------------
160 cpPlugins::Interface::Parameters::
161 TString cpPlugins::Interface::Parameters::
162 GetString( const TString& name ) const
164 TParameters::const_iterator i = this->m_Parameters.find( name );
165 if( i != this->m_Parameters.end( ) )
167 if( i->second.first == Self::String )
168 return( i->second.second.second );
174 // -------------------------------------------------------------------------
175 cpPlugins::Interface::Parameters::
176 TBool cpPlugins::Interface::Parameters::
177 GetBool( const TString& name ) const
179 TParameters::const_iterator i = this->m_Parameters.find( name );
180 if( i != this->m_Parameters.end( ) )
182 if( i->second.first == Self::Bool )
183 return( std::atoi( i->second.second.second.c_str( ) ) == 1 );
189 // -------------------------------------------------------------------------
190 cpPlugins::Interface::Parameters::
191 TInt cpPlugins::Interface::Parameters::
192 GetInt( const TString& name ) const
194 TParameters::const_iterator i = this->m_Parameters.find( name );
195 if( i != this->m_Parameters.end( ) )
197 if( i->second.first == Self::Int )
198 return( TInt( std::atoi( i->second.second.second.c_str( ) ) ) );
204 // -------------------------------------------------------------------------
205 cpPlugins::Interface::Parameters::
206 TUint cpPlugins::Interface::Parameters::
207 GetUint( const TString& name ) const
209 TParameters::const_iterator i = this->m_Parameters.find( name );
210 if( i != this->m_Parameters.end( ) )
212 if( i->second.first == Self::Uint )
213 return( TUint( std::atoi( i->second.second.second.c_str( ) ) ) );
216 return( TUint( 0 ) );
219 // -------------------------------------------------------------------------
220 cpPlugins::Interface::Parameters::
221 TReal cpPlugins::Interface::Parameters::
222 GetReal( const TString& name ) const
224 TParameters::const_iterator i = this->m_Parameters.find( name );
225 if( i != this->m_Parameters.end( ) )
227 if( i->second.first == Self::Real )
228 return( TReal( std::atof( i->second.second.second.c_str( ) ) ) );
231 return( TReal( 0 ) );
234 // -------------------------------------------------------------------------
235 void cpPlugins::Interface::Parameters::
236 GetStringList( std::vector< TString >& lst, const TString& name ) const
239 TParameters::const_iterator i = this->m_Parameters.find( name );
240 if( i == this->m_Parameters.end( ) )
242 if( i->second.first != Self::StringList )
245 std::istringstream str( i->second.second.second );
247 while( std::getline( str, token, '#' ) )
248 lst.push_back( token );
251 // -------------------------------------------------------------------------
252 void cpPlugins::Interface::Parameters::
253 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
256 TParameters::const_iterator i = this->m_Parameters.find( name );
257 if( i == this->m_Parameters.end( ) )
259 if( i->second.first != Self::BoolList )
262 std::istringstream str( i->second.second.second );
264 while( std::getline( str, token, '#' ) )
265 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
268 // -------------------------------------------------------------------------
269 void cpPlugins::Interface::Parameters::
270 GetIntList( std::vector< TInt >& lst, const TString& name ) const
273 TParameters::const_iterator i = this->m_Parameters.find( name );
274 if( i == this->m_Parameters.end( ) )
276 if( i->second.first != Self::IntList )
279 std::istringstream str( i->second.second.second );
281 while( std::getline( str, token, '#' ) )
282 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
285 // -------------------------------------------------------------------------
286 void cpPlugins::Interface::Parameters::
287 GetUintList( std::vector< TUint >& lst, const TString& name ) const
290 TParameters::const_iterator i = this->m_Parameters.find( name );
291 if( i == this->m_Parameters.end( ) )
293 if( i->second.first != Self::UintList )
296 std::istringstream str( i->second.second.second );
298 while( std::getline( str, token, '#' ) )
299 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
302 // -------------------------------------------------------------------------
303 void cpPlugins::Interface::Parameters::
304 GetRealList( std::vector< TReal >& lst, const TString& name ) const
307 TParameters::const_iterator i = this->m_Parameters.find( name );
308 if( i == this->m_Parameters.end( ) )
310 if( i->second.first != Self::RealList )
313 std::istringstream str( i->second.second.second );
315 while( std::getline( str, token, '#' ) )
316 lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
319 // -------------------------------------------------------------------------
320 void cpPlugins::Interface::Parameters::
321 GetChoices( std::vector< TString >& choices, const TString& name ) const
324 TParameters::const_iterator i = this->m_Parameters.find( name );
325 if( i == this->m_Parameters.end( ) )
327 if( i->second.first != Self::Choices )
330 std::istringstream str( i->second.second.first );
332 while( std::getline( str, token, '#' ) )
333 choices.push_back( token );
336 // -------------------------------------------------------------------------
337 cpPlugins::Interface::Parameters::
338 TString cpPlugins::Interface::Parameters::
339 GetSelectedChoice( const TString& name ) const
341 TParameters::const_iterator i = this->m_Parameters.find( name );
342 if( i == this->m_Parameters.end( ) )
344 if( i->second.first != Self::Choices )
346 return( i->second.second.second );
349 // -------------------------------------------------------------------------
350 void cpPlugins::Interface::Parameters::
351 SetString( const TString& name, const TString& v )
353 TParameters::iterator i = this->m_Parameters.find( name );
354 if( i == this->m_Parameters.end( ) )
356 if( i->second.first != Self::String )
358 i->second.second.second = v;
362 // -------------------------------------------------------------------------
363 #define cpPlugins_Parameters_Set( Y ) \
364 void cpPlugins::Interface::Parameters:: \
365 Set##Y( const TString& name, const T##Y& v ) \
367 TParameters::iterator i = this->m_Parameters.find( name ); \
368 if( i == this->m_Parameters.end( ) ) \
370 if( i->second.first != Self::Y ) \
372 std::stringstream str; \
374 i->second.second.second = str.str( ); \
378 cpPlugins_Parameters_Set( Bool );
379 cpPlugins_Parameters_Set( Int );
380 cpPlugins_Parameters_Set( Uint );
381 cpPlugins_Parameters_Set( Real );
383 // -------------------------------------------------------------------------
384 #define cpPlugins_Parameters_Add( Y ) \
385 void cpPlugins::Interface::Parameters:: \
386 AddTo##Y##List( const TString& name, const T##Y& v ) \
388 TParameters::iterator i = this->m_Parameters.find( name ); \
389 if( i == this->m_Parameters.end( ) ) \
391 if( i->second.first != Self::Y##List ) \
393 std::stringstream str; \
394 if( i->second.second.second == "" ) \
398 i->second.second.second += str.str( ); \
402 cpPlugins_Parameters_Add( String );
403 cpPlugins_Parameters_Add( Bool );
404 cpPlugins_Parameters_Add( Int );
405 cpPlugins_Parameters_Add( Uint );
406 cpPlugins_Parameters_Add( Real );
408 // -------------------------------------------------------------------------
409 #define cpPlugins_Parameters_Clear( Y ) \
410 void cpPlugins::Interface::Parameters:: \
411 Clear##Y##List( const TString& name ) \
413 TParameters::iterator i = this->m_Parameters.find( name ); \
414 if( i == this->m_Parameters.end( ) ) \
416 if( i->second.first != Self::Y##List ) \
418 i->second.second.second = ""; \
422 cpPlugins_Parameters_Clear( String );
423 cpPlugins_Parameters_Clear( Bool );
424 cpPlugins_Parameters_Clear( Int );
425 cpPlugins_Parameters_Clear( Uint );
426 cpPlugins_Parameters_Clear( Real );
427 cpPlugins_Parameters_Clear( Index );
428 cpPlugins_Parameters_Clear( Point );
430 // -------------------------------------------------------------------------
431 bool cpPlugins::Interface::Parameters::
432 SetSelectedChoice( const TString& name, const TString& choice )
434 TParameters::iterator i = this->m_Parameters.find( name );
435 if( i == this->m_Parameters.end( ) )
437 if( i->second.first != Self::Choices )
439 if( i->second.second.first.find( choice ) != std::string::npos )
441 i->second.second.second = choice;
449 // -------------------------------------------------------------------------
450 cpPlugins::Interface::Parameters::
458 // -------------------------------------------------------------------------
459 cpPlugins::Interface::Parameters::
464 // -------------------------------------------------------------------------
465 void cpPlugins::Interface::Parameters::
466 PrintSelf( std::ostream& os, itk::Indent indent ) const
468 TParameters::const_iterator i = this->m_Parameters.begin( );
469 for( ; i != this->m_Parameters.end( ); ++i )
472 << i->second.first << " | "
473 << i->second.second.first << " | "
474 << i->second.second.second << ")"