]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.h
More on graph editor
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.h
1 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__
2 #define __CPPLUGINS__INTERFACE__PARAMETERS__H__
3
4 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
5
6 #include <map>
7 #include <ostream>
8 #include <string>
9 #include <vector>
10
11 #include <itkObject.h>
12 #include <itkObjectFactory.h>
13
14 namespace cpPlugins
15 {
16   namespace Interface
17   {
18     // Some forward declarations
19     class ProcessObject;
20
21     /**
22      */
23     class cpPlugins_Interface_EXPORT Parameters
24       : public itk::Object
25     {
26     public:
27       typedef Parameters                      Self;
28       typedef itk::Object                     Superclass;
29       typedef itk::SmartPointer< Self >       Pointer;
30       typedef itk::SmartPointer< const Self > ConstPointer;
31
32       enum Type
33       {
34         String     , Bool       , Int        ,
35         Uint       , Real       , Index      ,
36         Point      , Vector     , StringList ,
37         BoolList   , IntList    , UintList   ,
38         RealList   , IndexList  , PointList  ,
39         VectorList , Choices    , NoType
40       };
41
42       typedef bool          TBool;
43       typedef long          TInt;
44       typedef unsigned long TUint;
45       typedef double        TReal;
46       typedef std::string   TString;
47
48       // NOTE: std::pair< default, value >
49       typedef std::pair< TString, TString >    TValues;
50       typedef std::pair< Self::Type, TValues > TParameter;
51       typedef std::map< TString, TParameter >  TParameters;
52
53     public:
54       itkNewMacro( Self );
55       itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
56
57     public:
58       // To impact pipeline
59       virtual ProcessObject* GetProcessObject( );
60       virtual const ProcessObject* GetProcessObject( ) const;
61       virtual void SetProcessObject( ProcessObject* v );
62       virtual void Modified( ) const;
63
64       // Parameters container configuration
65       void Clear( );
66
67       void ConfigureAsString( const TString& name, const TString& v );
68       void ConfigureAsBool( const TString& name, const TBool& v );
69       void ConfigureAsInt( const TString& name, const TInt& v );
70       void ConfigureAsUint( const TString& name, const TUint& v );
71       void ConfigureAsReal( const TString& name, const TReal& v );
72
73       template< class I >
74         inline void ConfigureAsIndex(
75           const TString& name, const TUint& dim, const I& v
76           );
77       template< class P >
78         inline void ConfigureAsPoint(
79           const TString& name, const TUint& dim, const P& v
80           );
81       template< class V >
82         inline void ConfigureAsVector(
83           const TString& name, const TUint& dim, const V& v
84           );
85
86       void ConfigureAsStringList( const TString& name );
87       void ConfigureAsBoolList( const TString& name );
88       void ConfigureAsIntList( const TString& name );
89       void ConfigureAsUintList( const TString& name );
90       void ConfigureAsRealList( const TString& name );
91       void ConfigureAsIndexList( const TString& name );
92       void ConfigureAsPointList( const TString& name );
93       void ConfigureAsVectorList( const TString& name );
94       void ConfigureAsChoices(
95         const TString& name, const std::vector< TString >& choices
96         );
97
98       // Get methods
99       void GetNames( std::vector< TString >& container ) const;
100       Type GetType( const TString& name ) const;
101
102       bool HasString( const TString& name ) const;
103       bool HasBool( const TString& name ) const;
104       bool HasInt( const TString& name ) const;
105       bool HasUint( const TString& name ) const;
106       bool HasReal( const TString& name ) const;
107       bool HasIndex( const TString& name ) const;
108       bool HasPoint( const TString& name ) const;
109       bool HasVector( const TString& name ) const;
110       bool HasStringList( const TString& name ) const;
111       bool HasBoolList( const TString& name ) const;
112       bool HasIntList( const TString& name ) const;
113       bool HasUintList( const TString& name ) const;
114       bool HasRealList( const TString& name ) const;
115       bool HasIndexList( const TString& name ) const;
116       bool HasPointList( const TString& name ) const;
117       bool HasVectorList( const TString& name ) const;
118       bool HasChoices( const TString& name ) const;
119
120       TString GetString( const TString& name, bool force = true ) const;
121       TBool GetBool( const TString& name ) const;
122       TInt GetInt( const TString& name ) const;
123       TUint GetUint( const TString& name ) const;
124       TReal GetReal( const TString& name ) const;
125
126       void GetStringList(
127         std::vector< TString >& lst, const TString& name
128         ) const;
129       void GetBoolList(
130         std::vector< TBool >& lst, const TString& name
131         ) const;
132       void GetIntList(
133         std::vector< TInt >& lst, const TString& name
134         ) const;
135       void GetUintList(
136         std::vector< TUint >& lst, const TString& name
137         ) const;
138       void GetRealList(
139         std::vector< TReal >& lst, const TString& name
140         ) const;
141
142       void GetChoices(
143         std::vector< TString >& choices, const TString& name
144         ) const;
145       TString GetSelectedChoice( const TString& name ) const;
146
147       template< class I >
148         inline I GetIndex( const TString& name, const TUint& dim ) const;
149       template< class P >
150         inline P GetPoint( const TString& name, const TUint& dim ) const;
151       template< class V >
152         inline V GetVector( const TString& name, const TUint& dim ) const;
153
154       template< class I >
155         inline void GetIndexList(
156           std::vector< I >& lst, const TString& name, const TUint& dim
157           ) const;
158       template< class P >
159         inline void GetPointList(
160           std::vector< P >& lst, const TString& name, const TUint& dim
161           ) const;
162       template< class V >
163         inline void GetVectorList(
164           std::vector< V >& lst, const TString& name, const TUint& dim
165           ) const;
166
167       // Set methods
168       void SetString(
169         const TString& name, const TString& v, bool force = true
170         );
171       void SetBool( const TString& name, const TBool& v );
172       void SetInt( const TString& name, const TInt& v );
173       void SetUint( const TString& name, const TUint& v );
174       void SetReal( const TString& name, const TReal& v );
175
176       template< class I >
177         inline void SetIndex(
178           const TString& name, const TUint& dim, const I& v
179           );
180       template< class P >
181         inline void SetPoint(
182           const TString& name, const TUint& dim, const P& v
183           );
184       template< class V >
185         inline void SetVector(
186           const TString& name, const TUint& dim, const V& v
187           );
188
189       void AddToStringList( const TString& name, const TString& v );
190       void AddToBoolList( const TString& name, const TBool& v );
191       void AddToIntList( const TString& name, const TInt& v );
192       void AddToUintList( const TString& name, const TUint& v );
193       void AddToRealList( const TString& name, const TReal& v );
194
195       template< class I >
196         inline void AddToIndexList(
197           const TString& name, const TUint& dim, const I& v
198           );
199       template< class P >
200         inline void AddToPointList(
201           const TString& name, const TUint& dim, const P& v
202           );
203       template< class P >
204         inline void AddToVectorList(
205           const TString& name, const TUint& dim, const P& v
206           );
207
208       void ClearStringList( const TString& name );
209       void ClearBoolList( const TString& name );
210       void ClearIntList( const TString& name );
211       void ClearUintList( const TString& name );
212       void ClearRealList( const TString& name );
213       void ClearIndexList( const TString& name );
214       void ClearPointList( const TString& name );
215       void ClearVectorList( const TString& name );
216
217       bool SetSelectedChoice( const TString& name, const TString& choice );
218
219     protected:
220       Parameters( );
221       virtual ~Parameters( );
222       void PrintSelf( std::ostream& os, itk::Indent indent ) const;
223
224     private:
225       // Purposely not implemented
226       Parameters( const Self& other );
227       Self& operator=( const Self& other );
228
229     protected:
230       TParameters m_Parameters;
231       ProcessObject* m_Process;
232     };
233
234   } // ecapseman
235
236 } // ecapseman
237
238 #include <cpPlugins/Interface/Parameters.hxx>
239
240 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__
241
242 // eof - $RCSfile$