1 #ifndef __cpPlugins__BaseObjects__Parameters__h__
2 #define __cpPlugins__BaseObjects__Parameters__h__
4 #include <cpPlugins/Config.h>
10 #include <itkTimeStamp.h>
12 // Some forward declarations
19 // -------------------------------------------------------------------------
20 #define cpPlugins_BaseObjects_Parameters_Configure( Y ) \
21 void ConfigureAs##Y( const std::string& name, const T##Y& init ); \
22 bool Has##Y( const std::string& name ) const
24 // -------------------------------------------------------------------------
25 #define cpPlugins_BaseObjects_Parameters_ConfigureList( Y ) \
26 void ConfigureAs##Y##List( const std::string& name ); \
27 bool Has##Y##List( const std::string& name ) const
29 // -------------------------------------------------------------------------
30 #define cpPlugins_BaseObjects_Parameters_GetSet( Y ) \
31 T##Y Get##Y( const std::string& name ) const; \
32 void Set##Y( const std::string& name, const T##Y& v )
34 // -------------------------------------------------------------------------
35 #define cpPlugins_BaseObjects_Parameters_GetSetList( Y ) \
36 std::vector< T##Y > Get##Y##List( const std::string& name ) const; \
37 void AddTo##Y##List( const std::string& name, const T##Y& v ); \
38 void Clear##Y##List( const std::string& name )
40 // -------------------------------------------------------------------------
43 namespace QT { class ParametersDialog; }
49 class cpPlugins_EXPORT Parameters
51 // Frienship with forward declaration to improve Qt dialog execution
52 friend class cpPlugins::QT::ParametersDialog;
53 friend std::ostream& operator<<( std::ostream& o, const Parameters& p )
56 auto i = p.m_Parameters.begin( );
57 i != p.m_Parameters.end( );
60 o << i->first << ": ("
61 << i->second.first << " | "
62 << i->second.second << ")"
68 typedef Parameters Self;
73 Uint , Real , OpenFileName ,
74 SaveFileName , PathName , StringList ,
75 BoolList , IntList , UintList ,
76 RealList , OpenFileNameList , SaveFileNameList ,
77 PathNameList , Choices , NoType
82 typedef unsigned long TUint;
84 typedef std::string TString;
85 typedef std::string TOpenFileName;
86 typedef std::string TSaveFileName;
87 typedef std::string TPathName;
89 typedef std::pair< Self::Type, std::string > TParameter;
90 typedef std::map< std::string, TParameter > TParameters;
93 cpPlugins_BaseObjects_Parameters_Configure( String );
94 cpPlugins_BaseObjects_Parameters_Configure( Bool );
95 cpPlugins_BaseObjects_Parameters_Configure( Int );
96 cpPlugins_BaseObjects_Parameters_Configure( Uint );
97 cpPlugins_BaseObjects_Parameters_Configure( Real );
98 cpPlugins_BaseObjects_Parameters_Configure( OpenFileName );
99 cpPlugins_BaseObjects_Parameters_Configure( SaveFileName );
100 cpPlugins_BaseObjects_Parameters_Configure( PathName );
102 cpPlugins_BaseObjects_Parameters_ConfigureList( String );
103 cpPlugins_BaseObjects_Parameters_ConfigureList( Bool );
104 cpPlugins_BaseObjects_Parameters_ConfigureList( Int );
105 cpPlugins_BaseObjects_Parameters_ConfigureList( Uint );
106 cpPlugins_BaseObjects_Parameters_ConfigureList( Real );
107 cpPlugins_BaseObjects_Parameters_ConfigureList( OpenFileName );
108 cpPlugins_BaseObjects_Parameters_ConfigureList( SaveFileName );
109 cpPlugins_BaseObjects_Parameters_ConfigureList( PathName );
111 cpPlugins_BaseObjects_Parameters_GetSet( Bool );
112 cpPlugins_BaseObjects_Parameters_GetSet( Int );
113 cpPlugins_BaseObjects_Parameters_GetSet( Uint );
114 cpPlugins_BaseObjects_Parameters_GetSet( Real );
115 cpPlugins_BaseObjects_Parameters_GetSet( OpenFileName );
116 cpPlugins_BaseObjects_Parameters_GetSet( SaveFileName );
117 cpPlugins_BaseObjects_Parameters_GetSet( PathName );
119 cpPlugins_BaseObjects_Parameters_GetSetList( String );
120 cpPlugins_BaseObjects_Parameters_GetSetList( Bool );
121 cpPlugins_BaseObjects_Parameters_GetSetList( Int );
122 cpPlugins_BaseObjects_Parameters_GetSetList( Uint );
123 cpPlugins_BaseObjects_Parameters_GetSetList( Real );
124 cpPlugins_BaseObjects_Parameters_GetSetList( OpenFileName );
125 cpPlugins_BaseObjects_Parameters_GetSetList( SaveFileName );
126 cpPlugins_BaseObjects_Parameters_GetSetList( PathName );
130 virtual ~Parameters( );
132 virtual void Modified( ) const;
133 virtual itk::ModifiedTimeType GetMTime( ) const;
135 // Parameters container configuration
139 void GetNames( std::vector< std::string >& container ) const;
140 Type GetType( const std::string& name ) const;
141 std::string GetTypeAsString( const std::string& name ) const;
142 static Type GetTypeFromString( const std::string& t );
144 // Base string methods
145 std::string GetString(
146 const std::string& name, bool force = true
149 const std::string& name, const std::string& v, bool force = true
152 void ConfigureAsChoices(
153 const std::string& name, const std::vector< std::string >& choices
155 void ConfigureAsRealTypesChoices( const std::string& name );
156 void ConfigureAsIntTypesChoices( const std::string& name );
157 void ConfigureAsScalarTypesChoices( const std::string& name );
158 std::vector< std::string > GetChoices( const std::string& name ) const;
159 std::string GetSelectedChoice( const std::string& name ) const;
160 bool SetSelectedChoice(
161 const std::string& name, const std::string& choice
164 std::string GetAcceptedFileExtensions( const std::string& name ) const;
165 void SetAcceptedFileExtensions(
166 const std::string& name, const std::string& extensions
171 tinyxml2::XMLDocument* doc,
172 tinyxml2::XMLElement* parent_elem
174 bool FromXML( const tinyxml2::XMLElement* filter_elem );
177 TParameters& GetRawParameters( );
178 const TParameters& GetRawParameters( ) const;
180 template< unsigned int _Enum >
181 inline void _Configure( const std::string& name );
183 template< unsigned int _Enum >
184 inline bool _Has( const std::string& name ) const;
186 template< class _Type, unsigned int _Enum >
187 inline _Type _Get( const std::string& name ) const;
189 template< class _Type, unsigned int _Enum >
190 inline void _Set( const std::string& name, const _Type& v );
192 template< class _Type, unsigned int _Enum >
193 inline std::vector< _Type > _GetList( const std::string& name ) const;
195 template< class _Type, unsigned int _Enum >
196 inline void _AddToList( const std::string& name, const _Type& v );
198 template< unsigned int _Enum >
199 inline void _ClearList( const std::string& name );
202 // Purposely not implemented
203 Parameters( const Self& other );
204 Self& operator=( const Self& other );
207 mutable itk::TimeStamp m_TimeStamp;
208 TParameters m_Parameters;
209 std::map< std::string, std::string > m_AcceptedFileExtensions;
216 #endif // __cpPlugins__BaseObjects__Parameters__h__