1 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__
2 #define __CPPLUGINS__INTERFACE__PARAMETERS__H__
4 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
12 #include <itkObject.h>
13 #include <itkObjectFactory.h>
15 // Some forward declarations
18 // -------------------------------------------------------------------------
19 #define cpPlugins_Parameters_Configure( Y ) \
20 void ConfigureAs##Y( const std::string& name ) \
22 this->m_Parameters[ name ] = TParameter( Self::Y, "" ); \
25 bool Has##Y( const std::string& name ) const \
27 auto i = this->m_Parameters.find( name ); \
28 if( i != this->m_Parameters.end( ) ) \
29 return( i->second.first == Self::Y ); \
34 // -------------------------------------------------------------------------
35 #define cpPlugins_Parameters_GetSet( Y ) \
36 T##Y Get##Y( const std::string& name ) const \
38 auto i = this->m_Parameters.find( name ); \
39 if( i != this->m_Parameters.end( ) ) \
41 if( i->second.first == Self::Y ) \
43 if( typeid( T##Y ) != typeid( std::string ) ) \
45 std::istringstream tok_str( i->second.second ); \
53 reinterpret_cast< const T##Y* >( \
54 &( i->second.second ) \
60 return( T##Y( 0 ) ); \
62 void Set##Y( const std::string& name, const T##Y& v ) \
64 auto i = this->m_Parameters.find( name ); \
65 if( i != this->m_Parameters.end( ) ) \
67 if( i->second.first == Self::Y ) \
69 if( typeid( T##Y ) != typeid( std::string ) ) \
71 std::stringstream str; \
73 if( i->second.second != str.str( ) ) \
75 i->second.second = str.str( ); \
81 const std::string* str = \
82 reinterpret_cast< const std::string* >( &v ); \
83 if( i->second.second != *str ) \
85 i->second.second = *str; \
93 // -------------------------------------------------------------------------
94 #define cpPlugins_Parameters_GetSetList( Y ) \
95 std::vector< T##Y > Get##Y##List( const std::string& name ) const \
97 std::vector< T##Y > lst; \
98 std::vector< std::string >* slst = \
99 reinterpret_cast< std::vector< std::string >* >( &lst ); \
100 auto i = this->m_Parameters.find( name ); \
101 if( i != this->m_Parameters.end( ) ) \
103 if( i->second.first == Self::Y##List ) \
105 std::istringstream str( i->second.second ); \
107 while( std::getline( str, token, '#' ) ) \
109 if( typeid( T##Y ) != typeid( std::string ) ) \
111 std::istringstream tok_str( token ); \
114 lst.push_back( v ); \
117 slst->push_back( token ); \
123 void AddTo##Y##List( const std::string& name, const T##Y& v ) \
125 auto i = this->m_Parameters.find( name ); \
126 if( i != this->m_Parameters.end( ) ) \
128 if( i->second.first == Self::Y##List ) \
130 std::stringstream str; \
131 if( i->second.second != "" ) \
132 str << i->second.second << "#"; \
134 i->second.second = str.str( ); \
139 void Clear##Y##List( const std::string& name ) \
141 auto i = this->m_Parameters.find( name ); \
142 if( i != this->m_Parameters.end( ) ) \
144 if( i->second.first == Self::Y##List ) \
146 if( i->second.second != "" ) \
148 i->second.second = ""; \
159 // Some forward declarations
161 class ParametersQtDialog;
165 class cpPlugins_Interface_EXPORT Parameters
168 friend class ParametersQtDialog;
171 typedef Parameters Self;
172 typedef itk::Object Superclass;
173 typedef itk::SmartPointer< Self > Pointer;
174 typedef itk::SmartPointer< const Self > ConstPointer;
178 String , Bool , Int ,
179 Uint , Real , OpenFileName ,
180 SaveFileName , PathName , StringList ,
181 BoolList , IntList , UintList ,
182 RealList , OpenFileNameList , SaveFileNameList ,
183 PathNameList , Choices , NoType
188 typedef unsigned long TUint;
189 typedef double TReal;
190 typedef std::string TString;
191 typedef std::string TOpenFileName;
192 typedef std::string TSaveFileName;
193 typedef std::string TPathName;
195 typedef std::pair< Self::Type, std::string > TParameter;
196 typedef std::map< std::string, TParameter > TParameters;
200 itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
202 cpPlugins_Parameters_Configure( String );
203 cpPlugins_Parameters_Configure( Bool );
204 cpPlugins_Parameters_Configure( Int );
205 cpPlugins_Parameters_Configure( Uint );
206 cpPlugins_Parameters_Configure( Real );
207 cpPlugins_Parameters_Configure( OpenFileName );
208 cpPlugins_Parameters_Configure( SaveFileName );
209 cpPlugins_Parameters_Configure( PathName );
210 cpPlugins_Parameters_Configure( StringList );
211 cpPlugins_Parameters_Configure( BoolList );
212 cpPlugins_Parameters_Configure( IntList );
213 cpPlugins_Parameters_Configure( UintList );
214 cpPlugins_Parameters_Configure( RealList );
215 cpPlugins_Parameters_Configure( OpenFileNameList );
216 cpPlugins_Parameters_Configure( SaveFileNameList );
217 cpPlugins_Parameters_Configure( PathNameList );
218 cpPlugins_Parameters_Configure( Choices );
220 cpPlugins_Parameters_GetSet( Bool );
221 cpPlugins_Parameters_GetSet( Int );
222 cpPlugins_Parameters_GetSet( Uint );
223 cpPlugins_Parameters_GetSet( Real );
224 cpPlugins_Parameters_GetSet( OpenFileName );
225 cpPlugins_Parameters_GetSet( SaveFileName );
226 cpPlugins_Parameters_GetSet( PathName );
228 cpPlugins_Parameters_GetSetList( String );
229 cpPlugins_Parameters_GetSetList( Bool );
230 cpPlugins_Parameters_GetSetList( Int );
231 cpPlugins_Parameters_GetSetList( Uint );
232 cpPlugins_Parameters_GetSetList( Real );
233 cpPlugins_Parameters_GetSetList( OpenFileName );
234 cpPlugins_Parameters_GetSetList( SaveFileName );
235 cpPlugins_Parameters_GetSetList( PathName );
238 // To impact pipeline
239 virtual ProcessObject* GetProcessObject( );
240 virtual const ProcessObject* GetProcessObject( ) const;
241 virtual void SetProcessObject( ProcessObject* v );
242 virtual void Modified( ) const;
244 // Parameters container configuration
248 void GetNames( std::vector< std::string >& container ) const;
249 Type GetType( const std::string& name ) const;
250 std::string GetTypeAsString( const std::string& name ) const;
251 static Type GetTypeFromString( const std::string& t );
253 // Base string methods
254 std::string GetString(
255 const std::string& name, bool force = true
258 const std::string& name, const std::string& v, bool force = true
261 void ConfigureAsChoices(
262 const std::string& name, const std::vector< std::string >& choices
264 std::vector< std::string > GetChoices( const std::string& name ) const;
265 std::string GetSelectedChoice( const std::string& name ) const;
266 bool SetSelectedChoice(
267 const std::string& name, const std::string& choice
270 std::string GetAcceptedFileExtensions( const std::string& name ) const;
271 void SetAcceptedFileExtensions(
272 const std::string& name, const std::string& extensions
276 bool ToXML( TiXmlElement* parent_elem ) const;
277 bool FromXML( const TiXmlElement* filter_elem );
281 virtual ~Parameters( );
282 void PrintSelf( std::ostream& os, itk::Indent indent ) const;
284 TParameters& GetRawParameters( );
285 const TParameters& GetRawParameters( ) const;
288 // Purposely not implemented
289 Parameters( const Self& other );
290 Self& operator=( const Self& other );
293 TParameters m_Parameters;
294 std::map< std::string, std::string > m_AcceptedFileExtensions;
295 ProcessObject* m_Process;
302 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__