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 i->second.second = str.str( ); \
77 *( reinterpret_cast< const std::string* >( &v ) ); \
83 // -------------------------------------------------------------------------
84 #define cpPlugins_Parameters_GetSetList( Y ) \
85 std::vector< T##Y > Get##Y##List( const std::string& name ) const \
87 std::vector< T##Y > lst; \
88 std::vector< std::string >* slst = \
89 reinterpret_cast< std::vector< std::string >* >( &lst ); \
90 auto i = this->m_Parameters.find( name ); \
91 if( i != this->m_Parameters.end( ) ) \
93 if( i->second.first == Self::Y##List ) \
95 std::istringstream str( i->second.second ); \
97 while( std::getline( str, token, '#' ) ) \
99 if( typeid( T##Y ) != typeid( std::string ) ) \
101 std::istringstream tok_str( token ); \
104 lst.push_back( v ); \
107 slst->push_back( token ); \
113 void AddTo##Y##List( const std::string& name, const T##Y& v ) \
115 auto i = this->m_Parameters.find( name ); \
116 if( i != this->m_Parameters.end( ) ) \
118 if( i->second.first == Self::Y##List ) \
120 std::stringstream str; \
121 if( i->second.second != "" ) \
122 str << i->second.second << "#"; \
124 i->second.second = str.str( ); \
128 void Clear##Y##List( const std::string& name ) \
130 auto i = this->m_Parameters.find( name ); \
131 if( i != this->m_Parameters.end( ) ) \
133 if( i->second.first == Self::Y##List ) \
134 i->second.second = ""; \
142 // Some forward declarations
144 class ParametersQtDialog;
148 class cpPlugins_Interface_EXPORT Parameters
151 friend class ParametersQtDialog;
154 typedef Parameters Self;
155 typedef itk::Object Superclass;
156 typedef itk::SmartPointer< Self > Pointer;
157 typedef itk::SmartPointer< const Self > ConstPointer;
161 String , Bool , Int ,
162 Uint , Real , OpenFileName ,
163 SaveFileName , PathName , StringList ,
164 BoolList , IntList , UintList ,
165 RealList , OpenFileNameList , SaveFileNameList ,
166 PathNameList , Choices , NoType
171 typedef unsigned long TUint;
172 typedef double TReal;
173 typedef std::string TString;
174 typedef std::string TOpenFileName;
175 typedef std::string TSaveFileName;
176 typedef std::string TPathName;
178 typedef std::pair< Self::Type, std::string > TParameter;
179 typedef std::map< std::string, TParameter > TParameters;
183 itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
185 cpPlugins_Parameters_Configure( String );
186 cpPlugins_Parameters_Configure( Bool );
187 cpPlugins_Parameters_Configure( Int );
188 cpPlugins_Parameters_Configure( Uint );
189 cpPlugins_Parameters_Configure( Real );
190 cpPlugins_Parameters_Configure( OpenFileName );
191 cpPlugins_Parameters_Configure( SaveFileName );
192 cpPlugins_Parameters_Configure( PathName );
193 cpPlugins_Parameters_Configure( StringList );
194 cpPlugins_Parameters_Configure( BoolList );
195 cpPlugins_Parameters_Configure( IntList );
196 cpPlugins_Parameters_Configure( UintList );
197 cpPlugins_Parameters_Configure( RealList );
198 cpPlugins_Parameters_Configure( OpenFileNameList );
199 cpPlugins_Parameters_Configure( SaveFileNameList );
200 cpPlugins_Parameters_Configure( PathNameList );
201 cpPlugins_Parameters_Configure( Choices );
203 cpPlugins_Parameters_GetSet( Bool );
204 cpPlugins_Parameters_GetSet( Int );
205 cpPlugins_Parameters_GetSet( Uint );
206 cpPlugins_Parameters_GetSet( Real );
207 cpPlugins_Parameters_GetSet( OpenFileName );
208 cpPlugins_Parameters_GetSet( SaveFileName );
209 cpPlugins_Parameters_GetSet( PathName );
211 cpPlugins_Parameters_GetSetList( String );
212 cpPlugins_Parameters_GetSetList( Bool );
213 cpPlugins_Parameters_GetSetList( Int );
214 cpPlugins_Parameters_GetSetList( Uint );
215 cpPlugins_Parameters_GetSetList( Real );
216 cpPlugins_Parameters_GetSetList( OpenFileName );
217 cpPlugins_Parameters_GetSetList( SaveFileName );
218 cpPlugins_Parameters_GetSetList( PathName );
221 // To impact pipeline
222 virtual ProcessObject* GetProcessObject( );
223 virtual const ProcessObject* GetProcessObject( ) const;
224 virtual void SetProcessObject( ProcessObject* v );
225 virtual void Modified( ) const;
227 // Parameters container configuration
231 void GetNames( std::vector< std::string >& container ) const;
232 Type GetType( const std::string& name ) const;
233 std::string GetTypeAsString( const std::string& name ) const;
234 static Type GetTypeFromString( const std::string& t );
236 // Base string methods
237 std::string GetString(
238 const std::string& name, bool force = true
241 const std::string& name, const std::string& v, bool force = true
244 void ConfigureAsChoices(
245 const std::string& name, const std::vector< std::string >& choices
247 std::vector< std::string > GetChoices( const std::string& name ) const;
248 std::string GetSelectedChoice( const std::string& name ) const;
249 bool SetSelectedChoice(
250 const std::string& name, const std::string& choice
254 bool ToXML( TiXmlElement* parent_elem ) const;
255 bool FromXML( const TiXmlElement* filter_elem );
259 virtual ~Parameters( );
260 void PrintSelf( std::ostream& os, itk::Indent indent ) const;
262 TParameters& GetRawParameters( );
263 const TParameters& GetRawParameters( ) const;
266 // Purposely not implemented
267 Parameters( const Self& other );
268 Self& operator=( const Self& other );
271 TParameters m_Parameters;
272 ProcessObject* m_Process;
279 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__