1 #include <cpPlugins/Interface/Parameters.h>
5 // -------------------------------------------------------------------------
6 void cpPlugins::Interface::Parameters::
9 this->m_Parameters.clear( );
13 // -------------------------------------------------------------------------
14 void cpPlugins::Interface::Parameters::
15 ConfigureAsString( const TString& name, const TString& v )
17 this->m_Parameters[ name ] = TParameter( Self::String, TValues( v, v ) );
21 // -------------------------------------------------------------------------
22 #define cpPlugins_Parameters_Configure( Y ) \
23 void cpPlugins::Interface::Parameters:: \
24 ConfigureAs##Y( const TString& name, const T##Y& v ) \
26 std::stringstream str; \
28 std::string s = str.str( ); \
29 this->m_Parameters[ name ] = \
30 TParameter( Self::Y, TValues( s, s ) ); \
34 cpPlugins_Parameters_Configure( Bool );
35 cpPlugins_Parameters_Configure( Int );
36 cpPlugins_Parameters_Configure( Uint );
37 cpPlugins_Parameters_Configure( Real );
39 // -------------------------------------------------------------------------
40 #define cpPlugins_Parameters_List_Configure( Y ) \
41 void cpPlugins::Interface::Parameters:: \
42 ConfigureAs##Y##List( const TString& name ) \
44 this->m_Parameters[ name ] = \
45 TParameter( Self::Y##List, TValues( "", "" ) ); \
49 cpPlugins_Parameters_List_Configure( String );
50 cpPlugins_Parameters_List_Configure( Bool );
51 cpPlugins_Parameters_List_Configure( Int );
52 cpPlugins_Parameters_List_Configure( Uint );
53 cpPlugins_Parameters_List_Configure( Real );
54 cpPlugins_Parameters_List_Configure( Index );
55 cpPlugins_Parameters_List_Configure( Point );
57 // -------------------------------------------------------------------------
58 void cpPlugins::Interface::Parameters::
60 const TString& name, const std::vector< TString >& choices
63 // It is invalid not to give choices when configuring
64 if( choices.size( ) == 0 )
67 std::stringstream str_choices;
68 str_choices << choices[ 0 ];
69 for( unsigned int i = 1; i < choices.size( ); ++i )
70 str_choices << "#" << choices[ i ];
71 this->m_Parameters[ name ] =
72 TParameter( Self::Choices, TValues( str_choices.str( ), "" ) );
76 // -------------------------------------------------------------------------
77 void cpPlugins::Interface::Parameters::
78 GetNames( std::vector< TString >& container ) const
81 TParameters::const_iterator i = this->m_Parameters.begin( );
82 for( ; i != this->m_Parameters.end( ); ++i )
83 container.push_back( i->first );
86 // -------------------------------------------------------------------------
87 cpPlugins::Interface::Parameters::
88 Type cpPlugins::Interface::Parameters::
89 GetType( const TString& name ) const
91 TParameters::const_iterator i = this->m_Parameters.find( name );
92 if( i != this->m_Parameters.end( ) )
93 return( i->second.first );
95 return( Self::NoType );
98 // -------------------------------------------------------------------------
99 #define cpPlugins_Parameters_Has( Y ) \
100 bool cpPlugins::Interface::Parameters:: \
101 Has##Y( const TString& name ) const \
103 TParameters::const_iterator i = this->m_Parameters.find( name ); \
104 if( i != this->m_Parameters.end( ) ) \
105 return( i->second.first == Self::Y ); \
110 cpPlugins_Parameters_Has( String );
111 cpPlugins_Parameters_Has( Bool );
112 cpPlugins_Parameters_Has( Int );
113 cpPlugins_Parameters_Has( Uint );
114 cpPlugins_Parameters_Has( Real );
115 cpPlugins_Parameters_Has( Index );
116 cpPlugins_Parameters_Has( Point );
117 cpPlugins_Parameters_Has( StringList );
118 cpPlugins_Parameters_Has( BoolList );
119 cpPlugins_Parameters_Has( IntList );
120 cpPlugins_Parameters_Has( UintList );
121 cpPlugins_Parameters_Has( RealList );
122 cpPlugins_Parameters_Has( IndexList );
123 cpPlugins_Parameters_Has( PointList );
124 cpPlugins_Parameters_Has( Choices );
126 // -------------------------------------------------------------------------
127 cpPlugins::Interface::Parameters::
128 TString cpPlugins::Interface::Parameters::
129 GetString( const TString& name ) const
131 TParameters::const_iterator i = this->m_Parameters.find( name );
132 if( i != this->m_Parameters.end( ) )
134 if( i->second.first == Self::String )
135 return( i->second.second.second );
141 // -------------------------------------------------------------------------
142 cpPlugins::Interface::Parameters::
143 TBool cpPlugins::Interface::Parameters::
144 GetBool( const TString& name ) const
146 TParameters::const_iterator i = this->m_Parameters.find( name );
147 if( i != this->m_Parameters.end( ) )
149 if( i->second.first == Self::Bool )
150 return( std::atoi( i->second.second.second.c_str( ) ) == 1 );
156 // -------------------------------------------------------------------------
157 cpPlugins::Interface::Parameters::
158 TInt cpPlugins::Interface::Parameters::
159 GetInt( const TString& name ) const
161 TParameters::const_iterator i = this->m_Parameters.find( name );
162 if( i != this->m_Parameters.end( ) )
164 if( i->second.first == Self::Int )
165 return( TInt( std::atoi( i->second.second.second.c_str( ) ) ) );
171 // -------------------------------------------------------------------------
172 cpPlugins::Interface::Parameters::
173 TUint cpPlugins::Interface::Parameters::
174 GetUint( const TString& name ) const
176 TParameters::const_iterator i = this->m_Parameters.find( name );
177 if( i != this->m_Parameters.end( ) )
179 if( i->second.first == Self::Uint )
180 return( TUint( std::atoi( i->second.second.second.c_str( ) ) ) );
183 return( TUint( 0 ) );
186 // -------------------------------------------------------------------------
187 cpPlugins::Interface::Parameters::
188 TReal cpPlugins::Interface::Parameters::
189 GetReal( const TString& name ) const
191 TParameters::const_iterator i = this->m_Parameters.find( name );
192 if( i != this->m_Parameters.end( ) )
194 if( i->second.first == Self::Real )
195 return( TReal( std::atof( i->second.second.second.c_str( ) ) ) );
198 return( TReal( 0 ) );
201 // -------------------------------------------------------------------------
202 void cpPlugins::Interface::Parameters::
203 GetStringList( std::vector< TString >& lst, const TString& name ) const
206 TParameters::const_iterator i = this->m_Parameters.find( name );
207 if( i == this->m_Parameters.end( ) )
209 if( i->second.first != Self::StringList )
212 std::istringstream str( i->second.second.second );
214 while( std::getline( str, token, '#' ) )
215 lst.push_back( token );
218 // -------------------------------------------------------------------------
219 void cpPlugins::Interface::Parameters::
220 GetBoolList( std::vector< TBool >& lst, const TString& name ) const
223 TParameters::const_iterator i = this->m_Parameters.find( name );
224 if( i == this->m_Parameters.end( ) )
226 if( i->second.first != Self::BoolList )
229 std::istringstream str( i->second.second.second );
231 while( std::getline( str, token, '#' ) )
232 lst.push_back( std::atoi( token.c_str( ) ) == 1 );
235 // -------------------------------------------------------------------------
236 void cpPlugins::Interface::Parameters::
237 GetIntList( std::vector< TInt >& 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::IntList )
246 std::istringstream str( i->second.second.second );
248 while( std::getline( str, token, '#' ) )
249 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
252 // -------------------------------------------------------------------------
253 void cpPlugins::Interface::Parameters::
254 GetUintList( std::vector< TUint >& 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::UintList )
263 std::istringstream str( i->second.second.second );
265 while( std::getline( str, token, '#' ) )
266 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
269 // -------------------------------------------------------------------------
270 void cpPlugins::Interface::Parameters::
271 GetRealList( std::vector< TReal >& 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::RealList )
280 std::istringstream str( i->second.second.second );
282 while( std::getline( str, token, '#' ) )
283 lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
286 // -------------------------------------------------------------------------
287 void cpPlugins::Interface::Parameters::
288 GetChoices( std::vector< TString >& choices, 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::Choices )
297 std::istringstream str( i->second.second.first );
299 while( std::getline( str, token, '#' ) )
300 choices.push_back( token );
303 // -------------------------------------------------------------------------
304 cpPlugins::Interface::Parameters::
305 TString cpPlugins::Interface::Parameters::
306 GetSelectedChoice( 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::Choices )
313 return( i->second.second.second );
316 // -------------------------------------------------------------------------
317 void cpPlugins::Interface::Parameters::
318 SetString( const TString& name, const TString& v )
320 TParameters::iterator i = this->m_Parameters.find( name );
321 if( i == this->m_Parameters.end( ) )
323 if( i->second.first != Self::String )
325 i->second.second.second = v;
329 // -------------------------------------------------------------------------
330 #define cpPlugins_Parameters_Set( Y ) \
331 void cpPlugins::Interface::Parameters:: \
332 Set##Y( const TString& name, const T##Y& v ) \
334 TParameters::iterator i = this->m_Parameters.find( name ); \
335 if( i == this->m_Parameters.end( ) ) \
337 if( i->second.first != Self::Y ) \
339 std::stringstream str; \
341 i->second.second.second = str.str( ); \
345 cpPlugins_Parameters_Set( Bool );
346 cpPlugins_Parameters_Set( Int );
347 cpPlugins_Parameters_Set( Uint );
348 cpPlugins_Parameters_Set( Real );
350 // -------------------------------------------------------------------------
351 #define cpPlugins_Parameters_Add( Y ) \
352 void cpPlugins::Interface::Parameters:: \
353 AddTo##Y##List( const TString& name, const T##Y& v ) \
355 TParameters::iterator i = this->m_Parameters.find( name ); \
356 if( i == this->m_Parameters.end( ) ) \
358 if( i->second.first != Self::Y##List ) \
360 std::stringstream str; \
361 if( i->second.second.second == "" ) \
365 i->second.second.second += str.str( ); \
369 cpPlugins_Parameters_Add( String );
370 cpPlugins_Parameters_Add( Bool );
371 cpPlugins_Parameters_Add( Int );
372 cpPlugins_Parameters_Add( Uint );
373 cpPlugins_Parameters_Add( Real );
375 // -------------------------------------------------------------------------
376 #define cpPlugins_Parameters_Clear( Y ) \
377 void cpPlugins::Interface::Parameters:: \
378 Clear##Y##List( const TString& name ) \
380 TParameters::iterator i = this->m_Parameters.find( name ); \
381 if( i == this->m_Parameters.end( ) ) \
383 if( i->second.first != Self::Y ) \
385 i->second.second.second = ""; \
389 cpPlugins_Parameters_Clear( String );
390 cpPlugins_Parameters_Clear( Bool );
391 cpPlugins_Parameters_Clear( Int );
392 cpPlugins_Parameters_Clear( Uint );
393 cpPlugins_Parameters_Clear( Real );
394 cpPlugins_Parameters_Clear( Index );
395 cpPlugins_Parameters_Clear( Point );
397 // -------------------------------------------------------------------------
398 bool cpPlugins::Interface::Parameters::
399 SetSelectedChoice( const TString& name, const TString& choice )
401 TParameters::iterator i = this->m_Parameters.find( name );
402 if( i == this->m_Parameters.end( ) )
404 if( i->second.first != Self::Choices )
406 if( i->second.second.first.find( choice ) != std::string::npos )
408 i->second.second.second = choice;
416 // -------------------------------------------------------------------------
417 cpPlugins::Interface::Parameters::
424 // -------------------------------------------------------------------------
425 cpPlugins::Interface::Parameters::
430 // -------------------------------------------------------------------------
431 void cpPlugins::Interface::Parameters::
432 PrintSelf( std::ostream& os, itk::Indent indent ) const
434 TParameters::const_iterator i = this->m_Parameters.begin( );
435 for( ; i != this->m_Parameters.end( ); ++i )
438 << i->second.first << " | "
439 << i->second.second.first << " | "
440 << i->second.second.second << ")"