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 );
91 // -------------------------------------------------------------------------
92 void cpPlugins::Interface::Parameters::
94 const TString& name, const std::vector< TString >& choices
97 // It is invalid not to give choices when configuring
98 if( choices.size( ) == 0 )
101 std::stringstream str_choices;
102 str_choices << choices[ 0 ];
103 for( unsigned int i = 1; i < choices.size( ); ++i )
104 str_choices << "#" << choices[ i ];
105 this->m_Parameters[ name ] =
106 TParameter( Self::Choices, TValues( str_choices.str( ), "" ) );
110 // -------------------------------------------------------------------------
111 void cpPlugins::Interface::Parameters::
112 GetNames( std::vector< TString >& container ) const
115 TParameters::const_iterator i = this->m_Parameters.begin( );
116 for( ; i != this->m_Parameters.end( ); ++i )
117 container.push_back( i->first );
120 // -------------------------------------------------------------------------
121 cpPlugins::Interface::Parameters::
122 Type cpPlugins::Interface::Parameters::
123 GetType( const TString& name ) const
125 TParameters::const_iterator i = this->m_Parameters.find( name );
126 if( i != this->m_Parameters.end( ) )
127 return( i->second.first );
129 return( Self::NoType );
132 // -------------------------------------------------------------------------
133 #define cpPlugins_Parameters_Has( Y ) \
134 bool cpPlugins::Interface::Parameters:: \
135 Has##Y( const TString& name ) const \
137 TParameters::const_iterator i = this->m_Parameters.find( name ); \
138 if( i != this->m_Parameters.end( ) ) \
139 return( i->second.first == Self::Y ); \
144 cpPlugins_Parameters_Has( String );
145 cpPlugins_Parameters_Has( Bool );
146 cpPlugins_Parameters_Has( Int );
147 cpPlugins_Parameters_Has( Uint );
148 cpPlugins_Parameters_Has( Real );
149 cpPlugins_Parameters_Has( Index );
150 cpPlugins_Parameters_Has( Point );
151 cpPlugins_Parameters_Has( StringList );
152 cpPlugins_Parameters_Has( BoolList );
153 cpPlugins_Parameters_Has( IntList );
154 cpPlugins_Parameters_Has( UintList );
155 cpPlugins_Parameters_Has( RealList );
156 cpPlugins_Parameters_Has( IndexList );
157 cpPlugins_Parameters_Has( PointList );
158 cpPlugins_Parameters_Has( Choices );
160 // -------------------------------------------------------------------------
161 cpPlugins::Interface::Parameters::
162 TString cpPlugins::Interface::Parameters::
163 GetString( const TString& name ) const
165 TParameters::const_iterator i = this->m_Parameters.find( name );
166 if( i != this->m_Parameters.end( ) )
168 if( i->second.first == Self::String )
169 return( i->second.second.second );
175 // -------------------------------------------------------------------------
176 cpPlugins::Interface::Parameters::
177 TBool cpPlugins::Interface::Parameters::
178 GetBool( const TString& name ) const
180 TParameters::const_iterator i = this->m_Parameters.find( name );
181 if( i != this->m_Parameters.end( ) )
183 if( i->second.first == Self::Bool )
184 return( std::atoi( i->second.second.second.c_str( ) ) == 1 );
190 // -------------------------------------------------------------------------
191 cpPlugins::Interface::Parameters::
192 TInt cpPlugins::Interface::Parameters::
193 GetInt( const TString& name ) const
195 TParameters::const_iterator i = this->m_Parameters.find( name );
196 if( i != this->m_Parameters.end( ) )
198 if( i->second.first == Self::Int )
199 return( TInt( std::atoi( i->second.second.second.c_str( ) ) ) );
205 // -------------------------------------------------------------------------
206 cpPlugins::Interface::Parameters::
207 TUint cpPlugins::Interface::Parameters::
208 GetUint( const TString& name ) const
210 TParameters::const_iterator i = this->m_Parameters.find( name );
211 if( i != this->m_Parameters.end( ) )
213 if( i->second.first == Self::Uint )
214 return( TUint( std::atoi( i->second.second.second.c_str( ) ) ) );
217 return( TUint( 0 ) );
220 // -------------------------------------------------------------------------
221 cpPlugins::Interface::Parameters::
222 TReal cpPlugins::Interface::Parameters::
223 GetReal( const TString& name ) const
225 TParameters::const_iterator i = this->m_Parameters.find( name );
226 if( i != this->m_Parameters.end( ) )
228 if( i->second.first == Self::Real )
229 return( TReal( std::atof( i->second.second.second.c_str( ) ) ) );
232 return( TReal( 0 ) );
235 // -------------------------------------------------------------------------
236 void cpPlugins::Interface::Parameters::
237 GetStringList( std::vector< TString >& lst, const TString& name ) const
240 TParameters::const_iterator i = this->m_Parameters.find( name );
241 if( i == this->m_Parameters.end( ) )
243 if( i->second.first != Self::StringList )
246 std::istringstream str( i->second.second.second );
248 while( std::getline( str, token, '#' ) )
249 lst.push_back( token );
252 // -------------------------------------------------------------------------
253 void cpPlugins::Interface::Parameters::
254 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
257 TParameters::const_iterator i = this->m_Parameters.find( name );
258 if( i == this->m_Parameters.end( ) )
260 if( i->second.first != Self::BoolList )
263 std::istringstream str( i->second.second.second );
265 while( std::getline( str, token, '#' ) )
266 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
269 // -------------------------------------------------------------------------
270 void cpPlugins::Interface::Parameters::
271 GetIntList( std::vector< TInt >& lst, const TString& name ) const
274 TParameters::const_iterator i = this->m_Parameters.find( name );
275 if( i == this->m_Parameters.end( ) )
277 if( i->second.first != Self::IntList )
280 std::istringstream str( i->second.second.second );
282 while( std::getline( str, token, '#' ) )
283 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
286 // -------------------------------------------------------------------------
287 void cpPlugins::Interface::Parameters::
288 GetUintList( std::vector< TUint >& lst, const TString& name ) const
291 TParameters::const_iterator i = this->m_Parameters.find( name );
292 if( i == this->m_Parameters.end( ) )
294 if( i->second.first != Self::UintList )
297 std::istringstream str( i->second.second.second );
299 while( std::getline( str, token, '#' ) )
300 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
303 // -------------------------------------------------------------------------
304 void cpPlugins::Interface::Parameters::
305 GetRealList( std::vector< TReal >& lst, const TString& name ) const
308 TParameters::const_iterator i = this->m_Parameters.find( name );
309 if( i == this->m_Parameters.end( ) )
311 if( i->second.first != Self::RealList )
314 std::istringstream str( i->second.second.second );
316 while( std::getline( str, token, '#' ) )
317 lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
320 // -------------------------------------------------------------------------
321 void cpPlugins::Interface::Parameters::
322 GetChoices( std::vector< TString >& choices, const TString& name ) const
325 TParameters::const_iterator i = this->m_Parameters.find( name );
326 if( i == this->m_Parameters.end( ) )
328 if( i->second.first != Self::Choices )
331 std::istringstream str( i->second.second.first );
333 while( std::getline( str, token, '#' ) )
334 choices.push_back( token );
337 // -------------------------------------------------------------------------
338 cpPlugins::Interface::Parameters::
339 TString cpPlugins::Interface::Parameters::
340 GetSelectedChoice( const TString& name ) const
342 TParameters::const_iterator i = this->m_Parameters.find( name );
343 if( i == this->m_Parameters.end( ) )
345 if( i->second.first != Self::Choices )
347 return( i->second.second.second );
350 // -------------------------------------------------------------------------
351 void cpPlugins::Interface::Parameters::
352 SetString( const TString& name, const TString& v )
354 TParameters::iterator i = this->m_Parameters.find( name );
355 if( i == this->m_Parameters.end( ) )
357 if( i->second.first != Self::String )
359 i->second.second.second = v;
363 // -------------------------------------------------------------------------
364 #define cpPlugins_Parameters_Set( Y ) \
365 void cpPlugins::Interface::Parameters:: \
366 Set##Y( const TString& name, const T##Y& v ) \
368 TParameters::iterator i = this->m_Parameters.find( name ); \
369 if( i == this->m_Parameters.end( ) ) \
371 if( i->second.first != Self::Y ) \
373 std::stringstream str; \
375 i->second.second.second = str.str( ); \
379 cpPlugins_Parameters_Set( Bool );
380 cpPlugins_Parameters_Set( Int );
381 cpPlugins_Parameters_Set( Uint );
382 cpPlugins_Parameters_Set( Real );
384 // -------------------------------------------------------------------------
385 #define cpPlugins_Parameters_Add( Y ) \
386 void cpPlugins::Interface::Parameters:: \
387 AddTo##Y##List( const TString& name, const T##Y& v ) \
389 TParameters::iterator i = this->m_Parameters.find( name ); \
390 if( i == this->m_Parameters.end( ) ) \
392 if( i->second.first != Self::Y##List ) \
394 std::stringstream str; \
395 if( i->second.second.second == "" ) \
399 i->second.second.second += str.str( ); \
403 cpPlugins_Parameters_Add( String );
404 cpPlugins_Parameters_Add( Bool );
405 cpPlugins_Parameters_Add( Int );
406 cpPlugins_Parameters_Add( Uint );
407 cpPlugins_Parameters_Add( Real );
409 // -------------------------------------------------------------------------
410 #define cpPlugins_Parameters_Clear( Y ) \
411 void cpPlugins::Interface::Parameters:: \
412 Clear##Y##List( const TString& name ) \
414 TParameters::iterator i = this->m_Parameters.find( name ); \
415 if( i == this->m_Parameters.end( ) ) \
417 if( i->second.first != Self::Y##List ) \
419 i->second.second.second = ""; \
423 cpPlugins_Parameters_Clear( String );
424 cpPlugins_Parameters_Clear( Bool );
425 cpPlugins_Parameters_Clear( Int );
426 cpPlugins_Parameters_Clear( Uint );
427 cpPlugins_Parameters_Clear( Real );
428 cpPlugins_Parameters_Clear( Index );
429 cpPlugins_Parameters_Clear( Point );
431 // -------------------------------------------------------------------------
432 bool cpPlugins::Interface::Parameters::
433 SetSelectedChoice( const TString& name, const TString& choice )
435 TParameters::iterator i = this->m_Parameters.find( name );
436 if( i == this->m_Parameters.end( ) )
438 if( i->second.first != Self::Choices )
440 if( i->second.second.first.find( choice ) != std::string::npos )
442 i->second.second.second = choice;
450 // -------------------------------------------------------------------------
451 cpPlugins::Interface::Parameters::
459 // -------------------------------------------------------------------------
460 cpPlugins::Interface::Parameters::
465 // -------------------------------------------------------------------------
466 void cpPlugins::Interface::Parameters::
467 PrintSelf( std::ostream& os, itk::Indent indent ) const
469 TParameters::const_iterator i = this->m_Parameters.begin( );
470 for( ; i != this->m_Parameters.end( ); ++i )
473 << i->second.first << " | "
474 << i->second.second.first << " | "
475 << i->second.second.second << ")"