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 ); \
22 bool Has##Y( const std::string& name ) const
24 // -------------------------------------------------------------------------
25 #define cpPlugins_BaseObjects_Parameters_GetSet( Y ) \
26 T##Y Get##Y( const std::string& name ) const; \
27 void Set##Y( const std::string& name, const T##Y& v )
29 // -------------------------------------------------------------------------
30 #define cpPlugins_BaseObjects_Parameters_GetSetList( Y ) \
31 std::vector< T##Y > Get##Y##List( const std::string& name ) const; \
32 void AddTo##Y##List( const std::string& name, const T##Y& v ); \
33 void Clear##Y##List( const std::string& name )
35 // -------------------------------------------------------------------------
38 namespace QT { class ParametersDialog; }
44 class cpPlugins_EXPORT Parameters
46 // Frienship with forward declaration to improve Qt dialog execution
47 friend class cpPlugins::QT::ParametersDialog;
48 friend std::ostream& operator<<( std::ostream& o, const Parameters& p )
51 auto i = p.m_Parameters.begin( );
52 i != p.m_Parameters.end( );
55 o << i->first << ": ("
56 << i->second.first << " | "
57 << i->second.second << ")"
63 typedef Parameters Self;
68 Uint , Real , OpenFileName ,
69 SaveFileName , PathName , StringList ,
70 BoolList , IntList , UintList ,
71 RealList , OpenFileNameList , SaveFileNameList ,
72 PathNameList , Choices , NoType
77 typedef unsigned long TUint;
79 typedef std::string TString;
80 typedef std::string TOpenFileName;
81 typedef std::string TSaveFileName;
82 typedef std::string TPathName;
84 typedef std::pair< Self::Type, std::string > TParameter;
85 typedef std::map< std::string, TParameter > TParameters;
88 cpPlugins_BaseObjects_Parameters_Configure( String );
89 cpPlugins_BaseObjects_Parameters_Configure( Bool );
90 cpPlugins_BaseObjects_Parameters_Configure( Int );
91 cpPlugins_BaseObjects_Parameters_Configure( Uint );
92 cpPlugins_BaseObjects_Parameters_Configure( Real );
93 cpPlugins_BaseObjects_Parameters_Configure( OpenFileName );
94 cpPlugins_BaseObjects_Parameters_Configure( SaveFileName );
95 cpPlugins_BaseObjects_Parameters_Configure( PathName );
96 cpPlugins_BaseObjects_Parameters_Configure( StringList );
97 cpPlugins_BaseObjects_Parameters_Configure( BoolList );
98 cpPlugins_BaseObjects_Parameters_Configure( IntList );
99 cpPlugins_BaseObjects_Parameters_Configure( UintList );
100 cpPlugins_BaseObjects_Parameters_Configure( RealList );
101 cpPlugins_BaseObjects_Parameters_Configure( OpenFileNameList );
102 cpPlugins_BaseObjects_Parameters_Configure( SaveFileNameList );
103 cpPlugins_BaseObjects_Parameters_Configure( PathNameList );
104 cpPlugins_BaseObjects_Parameters_Configure( Choices );
106 cpPlugins_BaseObjects_Parameters_GetSet( Bool );
107 cpPlugins_BaseObjects_Parameters_GetSet( Int );
108 cpPlugins_BaseObjects_Parameters_GetSet( Uint );
109 cpPlugins_BaseObjects_Parameters_GetSet( Real );
110 cpPlugins_BaseObjects_Parameters_GetSet( OpenFileName );
111 cpPlugins_BaseObjects_Parameters_GetSet( SaveFileName );
112 cpPlugins_BaseObjects_Parameters_GetSet( PathName );
114 cpPlugins_BaseObjects_Parameters_GetSetList( String );
115 cpPlugins_BaseObjects_Parameters_GetSetList( Bool );
116 cpPlugins_BaseObjects_Parameters_GetSetList( Int );
117 cpPlugins_BaseObjects_Parameters_GetSetList( Uint );
118 cpPlugins_BaseObjects_Parameters_GetSetList( Real );
119 cpPlugins_BaseObjects_Parameters_GetSetList( OpenFileName );
120 cpPlugins_BaseObjects_Parameters_GetSetList( SaveFileName );
121 cpPlugins_BaseObjects_Parameters_GetSetList( PathName );
125 virtual ~Parameters( );
127 virtual void Modified( ) const;
128 virtual itk::ModifiedTimeType GetMTime( ) const;
130 // Parameters container configuration
134 void GetNames( std::vector< std::string >& container ) const;
135 Type GetType( const std::string& name ) const;
136 std::string GetTypeAsString( const std::string& name ) const;
137 static Type GetTypeFromString( const std::string& t );
139 // Base string methods
140 std::string GetString(
141 const std::string& name, bool force = true
144 const std::string& name, const std::string& v, bool force = true
147 void ConfigureAsChoices(
148 const std::string& name, const std::vector< std::string >& choices
150 std::vector< std::string > GetChoices( const std::string& name ) const;
151 std::string GetSelectedChoice( const std::string& name ) const;
152 bool SetSelectedChoice(
153 const std::string& name, const std::string& choice
156 std::string GetAcceptedFileExtensions( const std::string& name ) const;
157 void SetAcceptedFileExtensions(
158 const std::string& name, const std::string& extensions
163 tinyxml2::XMLDocument* doc,
164 tinyxml2::XMLElement* parent_elem
166 bool FromXML( const tinyxml2::XMLElement* filter_elem );
169 TParameters& GetRawParameters( );
170 const TParameters& GetRawParameters( ) const;
172 template< unsigned int _Enum >
173 inline void _Configure( const std::string& name );
175 template< unsigned int _Enum >
176 inline bool _Has( const std::string& name ) const;
178 template< class _Type, unsigned int _Enum >
179 inline _Type _Get( const std::string& name ) const;
181 template< class _Type, unsigned int _Enum >
182 inline void _Set( const std::string& name, const _Type& v );
184 template< class _Type, unsigned int _Enum >
185 inline std::vector< _Type > _GetList( const std::string& name ) const;
187 template< class _Type, unsigned int _Enum >
188 inline void _AddToList( const std::string& name, const _Type& v );
190 template< unsigned int _Enum >
191 inline void _ClearList( const std::string& name );
194 // Purposely not implemented
195 Parameters( const Self& other );
196 Self& operator=( const Self& other );
199 mutable itk::TimeStamp m_TimeStamp;
200 TParameters m_Parameters;
201 std::map< std::string, std::string > m_AcceptedFileExtensions;
208 #endif // __cpPlugins__BaseObjects__Parameters__h__