]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.h
Widget integration (step 5/6): Interactive plugins now supported, widgets updates...
[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     /**
19      */
20     class cpPlugins_Interface_EXPORT Parameters
21       : public itk::Object
22     {
23     public:
24       typedef Parameters                      Self;
25       typedef itk::Object                     Superclass;
26       typedef itk::SmartPointer< Self >       Pointer;
27       typedef itk::SmartPointer< const Self > ConstPointer;
28
29       enum Type
30       {
31         String    , Bool       , Int      ,
32         Uint      , Real       , Index    ,
33         Point     , StringList , BoolList ,
34         IntList   , UintList   , RealList ,
35         IndexList , PointList  , Choices  ,
36         NoType
37       };
38
39       typedef bool          TBool;
40       typedef long          TInt;
41       typedef unsigned long TUint;
42       typedef double        TReal;
43       typedef std::string   TString;
44
45       // NOTE: std::pair< default, value >
46       typedef std::pair< TString, TString >    TValues;
47       typedef std::pair< Self::Type, TValues > TParameter;
48       typedef std::map< TString, TParameter >  TParameters;
49
50     public:
51       itkNewMacro( Self );
52       itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
53
54     public:
55       // Parameters container configuration
56       void Clear( );
57
58       void ConfigureAsString( const TString& name, const TString& v );
59       void ConfigureAsBool( const TString& name, const TBool& v );
60       void ConfigureAsInt( const TString& name, const TInt& v );
61       void ConfigureAsUint( const TString& name, const TUint& v );
62       void ConfigureAsReal( const TString& name, const TReal& v );
63
64       template< class I >
65         inline void ConfigureAsIndex(
66           const TString& name, const TUint& dim, const I& v
67           );
68       template< class P >
69         inline void ConfigureAsPoint(
70           const TString& name, const TUint& dim, const P& v
71           );
72
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 ConfigureAsChoices(
81         const TString& name, const std::vector< TString >& choices
82         );
83
84       // Get methods
85       void GetNames( std::vector< TString >& container ) const;
86       Type GetType( const TString& name ) const;
87
88       bool HasString( const TString& name ) const;
89       bool HasBool( const TString& name ) const;
90       bool HasInt( const TString& name ) const;
91       bool HasUint( const TString& name ) const;
92       bool HasReal( const TString& name ) const;
93       bool HasIndex( const TString& name ) const;
94       bool HasPoint( const TString& name ) const;
95       bool HasStringList( const TString& name ) const;
96       bool HasBoolList( const TString& name ) const;
97       bool HasIntList( const TString& name ) const;
98       bool HasUintList( const TString& name ) const;
99       bool HasRealList( const TString& name ) const;
100       bool HasIndexList( const TString& name ) const;
101       bool HasPointList( const TString& name ) const;
102       bool HasChoices( const TString& name ) const;
103
104       TString GetString( const TString& name ) const;
105       TBool GetBool( const TString& name ) const;
106       TInt GetInt( const TString& name ) const;
107       TUint GetUint( const TString& name ) const;
108       TReal GetReal( const TString& name ) const;
109
110       void GetStringList(
111         std::vector< TString >& lst, const TString& name
112         ) const;
113       void GetBoolList(
114         std::vector< TBool >& lst, const TString& name
115         ) const;
116       void GetIntList(
117         std::vector< TInt >& lst, const TString& name
118         ) const;
119       void GetUintList(
120         std::vector< TUint >& lst, const TString& name
121         ) const;
122       void GetRealList(
123         std::vector< TReal >& lst, const TString& name
124         ) const;
125
126       void GetChoices(
127         std::vector< TString >& choices, const TString& name
128         ) const;
129       TString GetSelectedChoice( const TString& name ) const;
130
131       template< class I >
132         inline I GetIndex( const TString& name, const TUint& dim ) const;
133       template< class P >
134         inline P GetPoint( const TString& name, const TUint& dim ) const;
135
136       template< class I >
137         inline void GetIndexList(
138           std::vector< I >& lst, const TString& name, const TUint& dim
139           ) const;
140       template< class P >
141         inline void GetPointList(
142           std::vector< P >& lst, const TString& name, const TUint& dim
143           ) const;
144
145       // Set methods
146       void SetString( const TString& name, const TString& v );
147       void SetBool( const TString& name, const TBool& v );
148       void SetInt( const TString& name, const TInt& v );
149       void SetUint( const TString& name, const TUint& v );
150       void SetReal( const TString& name, const TReal& v );
151
152       template< class I >
153         inline void SetIndex(
154           const TString& name, const TUint& dim, const I& v
155           );
156       template< class P >
157         inline void SetPoint(
158           const TString& name, const TUint& dim, const P& v
159           );
160
161       void AddToStringList( const TString& name, const TString& v );
162       void AddToBoolList( const TString& name, const TBool& v );
163       void AddToIntList( const TString& name, const TInt& v );
164       void AddToUintList( const TString& name, const TUint& v );
165       void AddToRealList( const TString& name, const TReal& v );
166
167       template< class I >
168         inline void AddToIndexList(
169           const TString& name, const TUint& dim, const I& v
170           );
171       template< class P >
172         inline void AddToPointList(
173           const TString& name, const TUint& dim, const P& v
174           );
175
176       void ClearStringList( const TString& name );
177       void ClearBoolList( const TString& name );
178       void ClearIntList( const TString& name );
179       void ClearUintList( const TString& name );
180       void ClearRealList( const TString& name );
181       void ClearIndexList( const TString& name );
182       void ClearPointList( const TString& name );
183
184       bool SetSelectedChoice( const TString& name, const TString& choice );
185
186     protected:
187       Parameters( );
188       virtual ~Parameters( );
189       void PrintSelf( std::ostream& os, itk::Indent indent ) const;
190
191     private:
192       // Purposely not implemented
193       Parameters( const Self& other );
194       Self& operator=( const Self& other );
195
196     protected:
197       TParameters m_Parameters;
198     };
199
200   } // ecapseman
201
202 } // ecapseman
203
204 #include <cpPlugins/Interface/Parameters.hxx>
205
206 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__
207
208 // eof - $RCSfile$