]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.h
Kind of bored: graph editor debugged
[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       typedef std::pair< Self::Type, TString > TParameter;
49       typedef std::map< TString, TParameter >  TParameters;
50
51     public:
52       itkNewMacro( Self );
53       itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
54
55     public:
56       // To impact pipeline
57       virtual ProcessObject* GetProcessObject( );
58       virtual const ProcessObject* GetProcessObject( ) const;
59       virtual void SetProcessObject( ProcessObject* v );
60       virtual void Modified( ) const;
61
62       // Parameters container configuration
63       void Clear( );
64
65       void ConfigureAsString( const TString& name );
66       void ConfigureAsBool( const TString& name );
67       void ConfigureAsInt( const TString& name );
68       void ConfigureAsUint( const TString& name );
69       void ConfigureAsReal( const TString& name );
70       void ConfigureAsIndex( const TString& name );
71       void ConfigureAsPoint( const TString& name );
72       void ConfigureAsVector( const TString& name );
73       void ConfigureAsStringList( const TString& name );
74       void ConfigureAsBoolList( const TString& name );
75       void ConfigureAsIntList( const TString& name );
76       void ConfigureAsUintList( const TString& name );
77       void ConfigureAsRealList( const TString& name );
78       void ConfigureAsIndexList( const TString& name );
79       void ConfigureAsPointList( const TString& name );
80       void ConfigureAsVectorList( const TString& name );
81       void ConfigureAsChoices( const TString& name );
82       void ConfigureAsChoices(
83         const TString& name, const std::vector< TString >& choices
84         );
85
86       // Get methods
87       void GetNames( std::vector< TString >& container ) const;
88       Type GetType( const TString& name ) const;
89
90       bool HasString( const TString& name ) const;
91       bool HasBool( const TString& name ) const;
92       bool HasInt( const TString& name ) const;
93       bool HasUint( const TString& name ) const;
94       bool HasReal( const TString& name ) const;
95       bool HasIndex( const TString& name ) const;
96       bool HasPoint( const TString& name ) const;
97       bool HasVector( const TString& name ) const;
98       bool HasStringList( const TString& name ) const;
99       bool HasBoolList( const TString& name ) const;
100       bool HasIntList( const TString& name ) const;
101       bool HasUintList( const TString& name ) const;
102       bool HasRealList( const TString& name ) const;
103       bool HasIndexList( const TString& name ) const;
104       bool HasPointList( const TString& name ) const;
105       bool HasVectorList( const TString& name ) const;
106       bool HasChoices( const TString& name ) const;
107
108       TString GetString( const TString& name, bool force = true ) const;
109       TBool GetBool( const TString& name ) const;
110       TInt GetInt( const TString& name ) const;
111       TUint GetUint( const TString& name ) const;
112       TReal GetReal( const TString& name ) const;
113
114       void GetStringList(
115         std::vector< TString >& lst, const TString& name
116         ) const;
117       void GetBoolList(
118         std::vector< TBool >& lst, const TString& name
119         ) const;
120       void GetIntList(
121         std::vector< TInt >& lst, const TString& name
122         ) const;
123       void GetUintList(
124         std::vector< TUint >& lst, const TString& name
125         ) const;
126       void GetRealList(
127         std::vector< TReal >& lst, const TString& name
128         ) const;
129
130       void GetChoices(
131         std::vector< TString >& choices, const TString& name
132         ) const;
133       TString GetSelectedChoice( const TString& name ) const;
134
135       template< class I >
136         inline I GetIndex( const TString& name, const TUint& dim ) const;
137       template< class P >
138         inline P GetPoint( const TString& name, const TUint& dim ) const;
139       template< class V >
140         inline V GetVector( const TString& name, const TUint& dim ) const;
141
142       template< class I >
143         inline void GetIndexList(
144           std::vector< I >& lst, const TString& name, const TUint& dim
145           ) const;
146       template< class P >
147         inline void GetPointList(
148           std::vector< P >& lst, const TString& name, const TUint& dim
149           ) const;
150       template< class V >
151         inline void GetVectorList(
152           std::vector< V >& lst, const TString& name, const TUint& dim
153           ) const;
154
155       // Set methods
156       void SetString(
157         const TString& name, const TString& v, bool force = true
158         );
159       void SetBool( const TString& name, const TBool& v );
160       void SetInt( const TString& name, const TInt& v );
161       void SetUint( const TString& name, const TUint& v );
162       void SetReal( const TString& name, const TReal& v );
163
164       template< class I >
165         inline void SetIndex(
166           const TString& name, const TUint& dim, const I& v
167           );
168       template< class P >
169         inline void SetPoint(
170           const TString& name, const TUint& dim, const P& v
171           );
172       template< class V >
173         inline void SetVector(
174           const TString& name, const TUint& dim, const V& v
175           );
176
177       void AddToStringList( const TString& name, const TString& v );
178       void AddToBoolList( const TString& name, const TBool& v );
179       void AddToIntList( const TString& name, const TInt& v );
180       void AddToUintList( const TString& name, const TUint& v );
181       void AddToRealList( const TString& name, const TReal& v );
182
183       template< class I >
184         inline void AddToIndexList(
185           const TString& name, const TUint& dim, const I& v
186           );
187       template< class P >
188         inline void AddToPointList(
189           const TString& name, const TUint& dim, const P& v
190           );
191       template< class P >
192         inline void AddToVectorList(
193           const TString& name, const TUint& dim, const P& v
194           );
195
196       void ClearStringList( const TString& name );
197       void ClearBoolList( const TString& name );
198       void ClearIntList( const TString& name );
199       void ClearUintList( const TString& name );
200       void ClearRealList( const TString& name );
201       void ClearIndexList( const TString& name );
202       void ClearPointList( const TString& name );
203       void ClearVectorList( const TString& name );
204
205       bool SetSelectedChoice( const TString& name, const TString& choice );
206
207     protected:
208       Parameters( );
209       virtual ~Parameters( );
210       void PrintSelf( std::ostream& os, itk::Indent indent ) const;
211
212     private:
213       // Purposely not implemented
214       Parameters( const Self& other );
215       Self& operator=( const Self& other );
216
217     protected:
218       TParameters m_Parameters;
219       ProcessObject* m_Process;
220     };
221
222   } // ecapseman
223
224 } // ecapseman
225
226 #include <cpPlugins/Interface/Parameters.hxx>
227
228 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__
229
230 // eof - $RCSfile$