]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.h
ef8e3b31f08a2f4bb8793e494db861d1ed8f3077
[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     , StringList , BoolList ,
37         IntList   , UintList   , RealList ,
38         IndexList , PointList  , Choices  ,
39         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
82       void ConfigureAsStringList( const TString& name );
83       void ConfigureAsBoolList( const TString& name );
84       void ConfigureAsIntList( const TString& name );
85       void ConfigureAsUintList( const TString& name );
86       void ConfigureAsRealList( const TString& name );
87       void ConfigureAsIndexList( const TString& name );
88       void ConfigureAsPointList( const TString& name );
89       void ConfigureAsChoices(
90         const TString& name, const std::vector< TString >& choices
91         );
92
93       // Get methods
94       void GetNames( std::vector< TString >& container ) const;
95       Type GetType( const TString& name ) const;
96
97       bool HasString( const TString& name ) const;
98       bool HasBool( const TString& name ) const;
99       bool HasInt( const TString& name ) const;
100       bool HasUint( const TString& name ) const;
101       bool HasReal( const TString& name ) const;
102       bool HasIndex( const TString& name ) const;
103       bool HasPoint( const TString& name ) const;
104       bool HasStringList( const TString& name ) const;
105       bool HasBoolList( const TString& name ) const;
106       bool HasIntList( const TString& name ) const;
107       bool HasUintList( const TString& name ) const;
108       bool HasRealList( const TString& name ) const;
109       bool HasIndexList( const TString& name ) const;
110       bool HasPointList( const TString& name ) const;
111       bool HasChoices( const TString& name ) const;
112
113       TString GetString( const TString& name ) const;
114       TBool GetBool( const TString& name ) const;
115       TInt GetInt( const TString& name ) const;
116       TUint GetUint( const TString& name ) const;
117       TReal GetReal( const TString& name ) const;
118
119       void GetStringList(
120         std::vector< TString >& lst, const TString& name
121         ) const;
122       void GetBoolList(
123         std::vector< TBool >& lst, const TString& name
124         ) const;
125       void GetIntList(
126         std::vector< TInt >& lst, const TString& name
127         ) const;
128       void GetUintList(
129         std::vector< TUint >& lst, const TString& name
130         ) const;
131       void GetRealList(
132         std::vector< TReal >& lst, const TString& name
133         ) const;
134
135       void GetChoices(
136         std::vector< TString >& choices, const TString& name
137         ) const;
138       TString GetSelectedChoice( const TString& name ) const;
139
140       template< class I >
141         inline I GetIndex( const TString& name, const TUint& dim ) const;
142       template< class P >
143         inline P GetPoint( const TString& name, const TUint& dim ) const;
144
145       template< class I >
146         inline void GetIndexList(
147           std::vector< I >& lst, const TString& name, const TUint& dim
148           ) const;
149       template< class P >
150         inline void GetPointList(
151           std::vector< P >& lst, const TString& name, const TUint& dim
152           ) const;
153
154       // Set methods
155       void SetString( const TString& name, const TString& v );
156       void SetBool( const TString& name, const TBool& v );
157       void SetInt( const TString& name, const TInt& v );
158       void SetUint( const TString& name, const TUint& v );
159       void SetReal( const TString& name, const TReal& v );
160
161       template< class I >
162         inline void SetIndex(
163           const TString& name, const TUint& dim, const I& v
164           );
165       template< class P >
166         inline void SetPoint(
167           const TString& name, const TUint& dim, const P& v
168           );
169
170       void AddToStringList( const TString& name, const TString& v );
171       void AddToBoolList( const TString& name, const TBool& v );
172       void AddToIntList( const TString& name, const TInt& v );
173       void AddToUintList( const TString& name, const TUint& v );
174       void AddToRealList( const TString& name, const TReal& v );
175
176       template< class I >
177         inline void AddToIndexList(
178           const TString& name, const TUint& dim, const I& v
179           );
180       template< class P >
181         inline void AddToPointList(
182           const TString& name, const TUint& dim, const P& v
183           );
184
185       void ClearStringList( const TString& name );
186       void ClearBoolList( const TString& name );
187       void ClearIntList( const TString& name );
188       void ClearUintList( const TString& name );
189       void ClearRealList( const TString& name );
190       void ClearIndexList( const TString& name );
191       void ClearPointList( const TString& name );
192
193       bool SetSelectedChoice( const TString& name, const TString& choice );
194
195     protected:
196       Parameters( );
197       virtual ~Parameters( );
198       void PrintSelf( std::ostream& os, itk::Indent indent ) const;
199
200     private:
201       // Purposely not implemented
202       Parameters( const Self& other );
203       Self& operator=( const Self& other );
204
205     protected:
206       TParameters m_Parameters;
207       ProcessObject* m_Process;
208     };
209
210   } // ecapseman
211
212 } // ecapseman
213
214 #include <cpPlugins/Interface/Parameters.hxx>
215
216 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__
217
218 // eof - $RCSfile$