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