]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Pipeline/Parameters.h
...
[cpPlugins.git] / lib / cpPlugins / Pipeline / Parameters.h
1 /* =========================================================================
2  * @author ??? (???@javeriana.edu.co)
3  * @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
4  * =========================================================================
5  */
6 #ifndef __cpPlugins__Pipeline__Parameters__h__
7 #define __cpPlugins__Pipeline__Parameters__h__
8
9 #include <cpPlugins/Config.h>
10
11 #include <map>
12 #include <ostream>
13 #include <vector>
14
15 // -------------------------------------------------------------------------
16 #define cpPlugins_Pipeline_Parameters_Configure( Y )                    \
17   void ConfigureAs##Y( const std::string& name, const T##Y& init );     \
18   bool Has##Y( const std::string& name ) const
19
20 // -------------------------------------------------------------------------
21 #define cpPlugins_Pipeline_Parameters_ConfigureList( Y )                \
22   void ConfigureAs##Y##List( const std::string& name );                 \
23   bool Has##Y##List( const std::string& name ) const
24
25 // -------------------------------------------------------------------------
26 #define cpPlugins_Pipeline_Parameters_GetSet( Y )       \
27   T##Y Get##Y( const std::string& name ) const;         \
28   void Set##Y( const std::string& name, const T##Y& v )
29
30 // -------------------------------------------------------------------------
31 #define cpPlugins_Pipeline_Parameters_GetSetList( Y )                   \
32   std::vector< T##Y > Get##Y##List( const std::string& name ) const;    \
33   void AddTo##Y##List( const std::string& name, const T##Y& v );        \
34   void Clear##Y##List( const std::string& name )
35
36 // -------------------------------------------------------------------------
37 namespace cpPlugins
38 {
39   namespace Pipeline
40   {
41     class ProcessObject;
42
43     /**
44      */
45     class CPPLUGINS_EXPORT Parameters
46     {
47       friend std::ostream& operator<<( std::ostream& o, const Parameters& p )
48         {
49           for(
50             auto i = p.m_Parameters.begin( );
51             i != p.m_Parameters.end( );
52             ++i
53             )
54             o << i->first << ": ("
55               << i->second.first << " | "
56               << i->second.second << ")"
57               << std::endl;
58           return( o );
59         }
60
61     public:
62       typedef Parameters Self;
63
64       enum Type
65       {
66         String       , Bool             , Int              ,
67         Uint         , Real             , OpenFileName     ,
68         SaveFileName , PathName         , StringList       ,
69         BoolList     , IntList          , UintList         ,
70         RealList     , OpenFileNameList , SaveFileNameList ,
71         PathNameList , Choices          , NoType
72       };
73
74       typedef bool          TBool;
75       typedef long          TInt;
76       typedef unsigned long TUint;
77       typedef double        TReal;
78       typedef std::string   TString;
79       typedef std::string   TOpenFileName;
80       typedef std::string   TSaveFileName;
81       typedef std::string   TPathName;
82
83       typedef std::pair< Self::Type, std::string > TParameter;
84       typedef std::map< std::string, TParameter >  TParameters;
85
86     public:
87       cpPlugins_Pipeline_Parameters_Configure( String );
88       cpPlugins_Pipeline_Parameters_Configure( Bool );
89       cpPlugins_Pipeline_Parameters_Configure( Int );
90       cpPlugins_Pipeline_Parameters_Configure( Uint );
91       cpPlugins_Pipeline_Parameters_Configure( Real );
92       cpPlugins_Pipeline_Parameters_Configure( OpenFileName );
93       cpPlugins_Pipeline_Parameters_Configure( SaveFileName );
94       cpPlugins_Pipeline_Parameters_Configure( PathName );
95
96       cpPlugins_Pipeline_Parameters_ConfigureList( String );
97       cpPlugins_Pipeline_Parameters_ConfigureList( Bool );
98       cpPlugins_Pipeline_Parameters_ConfigureList( Int );
99       cpPlugins_Pipeline_Parameters_ConfigureList( Uint );
100       cpPlugins_Pipeline_Parameters_ConfigureList( Real );
101       cpPlugins_Pipeline_Parameters_ConfigureList( OpenFileName );
102       cpPlugins_Pipeline_Parameters_ConfigureList( SaveFileName );
103       cpPlugins_Pipeline_Parameters_ConfigureList( PathName );
104
105       cpPlugins_Pipeline_Parameters_GetSet( Bool );
106       cpPlugins_Pipeline_Parameters_GetSet( Int );
107       cpPlugins_Pipeline_Parameters_GetSet( Uint );
108       cpPlugins_Pipeline_Parameters_GetSet( Real );
109       cpPlugins_Pipeline_Parameters_GetSet( OpenFileName );
110       cpPlugins_Pipeline_Parameters_GetSet( SaveFileName );
111       cpPlugins_Pipeline_Parameters_GetSet( PathName );
112
113       cpPlugins_Pipeline_Parameters_GetSetList( String );
114       cpPlugins_Pipeline_Parameters_GetSetList( Bool );
115       cpPlugins_Pipeline_Parameters_GetSetList( Int );
116       cpPlugins_Pipeline_Parameters_GetSetList( Uint );
117       cpPlugins_Pipeline_Parameters_GetSetList( Real );
118       cpPlugins_Pipeline_Parameters_GetSetList( OpenFileName );
119       cpPlugins_Pipeline_Parameters_GetSetList( SaveFileName );
120       cpPlugins_Pipeline_Parameters_GetSetList( PathName );
121
122     public:
123       Parameters( );
124       virtual ~Parameters( );
125
126       ProcessObject* GetProcessObject( );
127       const ProcessObject* GetProcessObject( ) const;
128       void SetProcessObject( ProcessObject* po );
129       virtual void Modified( ) const;
130
131       // Parameters container configuration
132       void Clear( );
133
134       // Get methods
135       void GetNames( std::vector< std::string >& container ) const;
136       Type GetType( const std::string& name ) const;
137       std::string GetTypeAsString( const std::string& name ) const;
138       static Type GetTypeFromString( const std::string& t );
139
140       // Base string methods
141       std::string GetString(
142         const std::string& name, bool force = true
143         ) const;
144       void SetString(
145         const std::string& name, const std::string& v, bool force = true
146         );
147
148       void ConfigureAsChoices(
149         const std::string& name, const std::vector< std::string >& choices
150         );
151       void ConfigureAsRealTypesChoices( const std::string& name );
152       void ConfigureAsIntTypesChoices( const std::string& name );
153       void ConfigureAsScalarTypesChoices( const std::string& name );
154       std::vector< std::string > GetChoices( const std::string& name ) const;
155       std::string GetSelectedChoice( const std::string& name ) const;
156       bool SetSelectedChoice(
157         const std::string& name, const std::string& choice
158         );
159
160       std::string GetAcceptedFileExtensions( const std::string& name ) const;
161       void SetAcceptedFileExtensions(
162         const std::string& name, const std::string& extensions
163         );
164
165     protected:
166       TParameters& GetRawParameters( );
167       const TParameters& GetRawParameters( ) const;
168
169       template< unsigned int _Enum >
170       inline void _Configure( const std::string& name );
171
172       template< unsigned int _Enum >
173       inline bool _Has( const std::string& name ) const;
174
175       template< class _Type, unsigned int _Enum >
176       inline _Type _Get( const std::string& name ) const;
177
178       template< class _Type, unsigned int _Enum >
179       inline void _Set( const std::string& name, const _Type& v );
180
181       template< class _Type, unsigned int _Enum >
182       inline std::vector< _Type > _GetList( const std::string& name ) const;
183
184       template< class _Type, unsigned int _Enum >
185       inline void _AddToList( const std::string& name, const _Type& v );
186
187       template< unsigned int _Enum >
188       inline void _ClearList( const std::string& name );
189
190     private:
191       // Purposely not implemented
192       Parameters( const Self& other );
193       Self& operator=( const Self& other );
194
195     protected:
196       ProcessObject*                       m_ProcessObject;
197       TParameters                          m_Parameters;
198       std::map< std::string, std::string > m_AcceptedFileExtensions;
199     };
200
201   } // ecapseman
202
203 } // ecapseman
204
205 #endif // __cpPlugins__Pipeline__Parameters__h__
206
207 // eof - $RCSfile$