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