]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.h
...
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.h
1 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__
2 #define __CPPLUGINS__INTERFACE__PARAMETERS__H__
3
4 #include <map>
5 #include <ostream>
6 #include <string>
7 #include <vector>
8 #include <cpPlugins/cpPlugins_Export.h>
9
10 namespace cpPlugins
11 {
12   namespace Interface
13   {
14     /**
15      */
16     class cpPlugins_EXPORT Parameters
17     {
18       // -------------------------------------------------------------------
19       friend std::ostream& operator<<(
20         std::ostream& os, const Parameters& p
21         )
22       {
23         Parameters::TParameters::const_iterator pIt =
24           p.m_Parameters.begin( );
25         for( ; pIt != p.m_Parameters.end( ); ++pIt )
26         {
27           os
28             << pIt->first << ": ("
29             << pIt->second.first << ", "
30             << pIt->second.second << ")"
31             << std::endl;
32
33         } // rof
34         return( os );
35       }
36
37     public:
38       typedef Parameters Self;
39
40       enum Type
41       {
42         String    , Bool       , Int      ,
43         Uint      , Real       , Index    ,
44         Point     , StringList , BoolList ,
45         IntList   , UintList   , RealList ,
46         IndexList , PointList  , NoType
47       };
48
49       typedef bool          TBool;
50       typedef long          TInt;
51       typedef unsigned long TUint;
52       typedef double        TReal;
53       typedef std::string   TString;
54
55       typedef std::pair< Self::Type, TString > TParameter;
56       typedef std::map< TString, TParameter >  TParameters;
57
58     public:
59       Parameters( );
60       Parameters( const Self& other );
61       virtual ~Parameters( );
62
63       Self& operator=( const Self& other );
64
65       void Clear( );
66       void Configure( const Self::Type& type, const TString& name );
67       void SetValueAsString( const TString& name, const TString& v );
68       void SetValueAsBool( const TString& name, const TBool& v );
69       void SetValueAsInt( const TString& name, const TInt& v );
70       void SetValueAsUint( const TString& name, const TUint& v );
71       void SetValueAsReal( const TString& name, const TReal& v );
72       void SetValueAsIndex( const TString& name, const TUint& n, ... );
73       void SetValueAsPoint( const TString& name, const TUint& n, ... );
74
75       void AddValueToStringList( const TString& name, const TString& v );
76       void AddValueToBoolList( const TString& name, const TBool& v );
77       void AddValueToIntList( const TString& name, const TInt& v );
78       void AddValueToUintList( const TString& name, const TUint& v );
79       void AddValueToRealList( const TString& name, const TReal& v );
80       void AddValueToIndexList( const TString& name, const TUint& n, ... );
81       void AddValueToPointList( const TString& name, const TUint& n, ... );
82
83       void ClearStringList( const TString& name );
84       void ClearBoolList( const TString& name );
85       void ClearIntList( const TString& name );
86       void ClearUintList( const TString& name );
87       void ClearRealList( const TString& name );
88       void ClearIndexList( const TString& name );
89       void ClearPointList( const TString& name );
90       
91       std::vector< TString > GetParameters( ) const;
92       Self::Type GetParameterType( const TString& name ) const;
93       const TString& GetRawValue( const TString& name ) const;
94       const TString& GetValueAsString( const TString& name ) const;
95       TBool GetValueAsBool( const TString& name ) const;
96       TInt GetValueAsInt( const TString& name ) const;
97       TUint GetValueAsUint( const TString& name ) const;
98       TReal GetValueAsReal( const TString& name ) const;
99
100       template< class I >
101       I GetValueAsIndex( const TString& name ) const;
102
103       template< class P >
104       P GetValueAsPoint( const TString& name ) const;
105
106       void GetValueAsStringList(
107         std::vector< TString >& lst, const TString& name
108         ) const;
109       void GetValueAsBoolList(
110         std::vector< TBool >& lst, const TString& name
111         ) const;
112       void GetValueAsIntList(
113         std::vector< TInt >& lst, const TString& name
114         ) const;
115       void GetValueAsUintList(
116         std::vector< TUint >& lst, const TString& name
117         ) const;
118       void GetValueAsRealList(
119         std::vector< TReal >& lst, const TString& name
120         ) const;
121
122       template< class I >
123       void GetValueAsIndexList(
124         std::vector< I >& lst, const TString& name
125         ) const;
126
127       template< class P >
128       void GetValueAsPointList(
129         std::vector< P >& lst, const TString& name
130         ) const;
131
132       bool HasStringValue( const TString& name ) const;
133       bool HasBoolValue( const TString& name ) const;
134       bool HasIntValue( const TString& name ) const;
135       bool HasUintValue( const TString& name ) const;
136       bool HasRealValue( const TString& name ) const;
137       bool HasIndexValue( const TString& name ) const;
138       bool HasPointValue( const TString& name ) const;
139       bool HasStringListValue( const TString& name ) const;
140       bool HasBoolListValue( const TString& name ) const;
141       bool HasIntListValue( const TString& name ) const;
142       bool HasUintListValue( const TString& name ) const;
143       bool HasRealListValue( const TString& name ) const;
144       bool HasIndexListValue( const TString& name ) const;
145       bool HasPointListValue( const TString& name ) const;
146
147     protected:
148       TParameters m_Parameters;
149     };
150
151   } // ecapseman
152
153 } // ecapseman
154
155 #include <cpPlugins/Interface/Parameters.hxx>
156
157 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__
158
159 // eof - $RCSfile$