]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.h
...
[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 ) 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( const TString& name, const TString& v );
169       void SetBool( const TString& name, const TBool& v );
170       void SetInt( const TString& name, const TInt& v );
171       void SetUint( const TString& name, const TUint& v );
172       void SetReal( const TString& name, const TReal& v );
173
174       template< class I >
175         inline void SetIndex(
176           const TString& name, const TUint& dim, const I& v
177           );
178       template< class P >
179         inline void SetPoint(
180           const TString& name, const TUint& dim, const P& v
181           );
182       template< class V >
183         inline void SetVector(
184           const TString& name, const TUint& dim, const V& v
185           );
186
187       void AddToStringList( const TString& name, const TString& v );
188       void AddToBoolList( const TString& name, const TBool& v );
189       void AddToIntList( const TString& name, const TInt& v );
190       void AddToUintList( const TString& name, const TUint& v );
191       void AddToRealList( const TString& name, const TReal& v );
192
193       template< class I >
194         inline void AddToIndexList(
195           const TString& name, const TUint& dim, const I& v
196           );
197       template< class P >
198         inline void AddToPointList(
199           const TString& name, const TUint& dim, const P& v
200           );
201       template< class P >
202         inline void AddToVectorList(
203           const TString& name, const TUint& dim, const P& v
204           );
205
206       void ClearStringList( const TString& name );
207       void ClearBoolList( const TString& name );
208       void ClearIntList( const TString& name );
209       void ClearUintList( const TString& name );
210       void ClearRealList( const TString& name );
211       void ClearIndexList( const TString& name );
212       void ClearPointList( const TString& name );
213       void ClearVectorList( const TString& name );
214
215       bool SetSelectedChoice( const TString& name, const TString& choice );
216
217     protected:
218       Parameters( );
219       virtual ~Parameters( );
220       void PrintSelf( std::ostream& os, itk::Indent indent ) const;
221
222     private:
223       // Purposely not implemented
224       Parameters( const Self& other );
225       Self& operator=( const Self& other );
226
227     protected:
228       TParameters m_Parameters;
229       ProcessObject* m_Process;
230     };
231
232   } // ecapseman
233
234 } // ecapseman
235
236 #include <cpPlugins/Interface/Parameters.hxx>
237
238 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__
239
240 // eof - $RCSfile$