]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.cxx
Simplified parameters
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.cxx
1 #include <cpPlugins/Interface/Parameters.h>
2 #include <cstdarg>
3 #include <cstdlib>
4 #include <sstream>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::Interface::Parameters::
8 Parameters( )
9 {
10   this->m_Parameters.clear( );
11 }
12
13 // -------------------------------------------------------------------------
14 cpPlugins::Interface::Parameters::
15 Parameters( const Self& other )
16 {
17   this->m_Parameters = other.m_Parameters;
18 }
19
20 // -------------------------------------------------------------------------
21 cpPlugins::Interface::Parameters::
22 ~Parameters( )
23 {
24   this->m_Parameters.clear( );
25 }
26
27 // -------------------------------------------------------------------------
28 cpPlugins::Interface::Parameters::
29 Self& cpPlugins::Interface::Parameters::
30 operator=( const Self& other )
31 {
32   this->m_Parameters = other.m_Parameters;
33   return( *this );
34 }
35
36 // -------------------------------------------------------------------------
37 void cpPlugins::Interface::Parameters::
38 Configure( const Self::Type& type, const std::string& name )
39 {
40   this->m_Parameters[ name ] = TParameter( type, "" );
41 }
42
43 // -------------------------------------------------------------------------
44 void cpPlugins::Interface::Parameters::
45 SetValueAsString( const std::string& name, const std::string& v )
46 {
47   TParameters::iterator pIt = this->m_Parameters.find( name );
48   if( pIt == this->m_Parameters.end( ) )
49     return;
50   if( pIt->second.first != Self::String )
51     return;
52
53   pIt->second.second = v;
54 }
55
56 // -------------------------------------------------------------------------
57 void cpPlugins::Interface::Parameters::
58 SetValueAsInt( const std::string& name, const TInt& v )
59 {
60   TParameters::iterator pIt = this->m_Parameters.find( name );
61   if( pIt == this->m_Parameters.end( ) )
62     return;
63   if( pIt->second.first != Self::Int )
64     return;
65
66   std::stringstream ss;
67   ss << v;
68   pIt->second.second = ss.str( );
69 }
70
71 // -------------------------------------------------------------------------
72 void cpPlugins::Interface::Parameters::
73 SetValueAsUint( const std::string& name, const TUint& v )
74 {
75   TParameters::iterator pIt = this->m_Parameters.find( name );
76   if( pIt == this->m_Parameters.end( ) )
77     return;
78   if( pIt->second.first != Self::Uint )
79     return;
80
81   std::stringstream ss;
82   ss << v;
83   pIt->second.second = ss.str( );
84 }
85
86 // -------------------------------------------------------------------------
87 void cpPlugins::Interface::Parameters::
88 SetValueAsReal( const std::string& name, const TReal& v )
89 {
90   TParameters::iterator pIt = this->m_Parameters.find( name );
91   if( pIt == this->m_Parameters.end( ) )
92     return;
93   if( pIt->second.first != Self::Real )
94     return;
95
96   std::stringstream ss;
97   ss << v;
98   pIt->second.second = ss.str( );
99 }
100
101 // -------------------------------------------------------------------------
102 void cpPlugins::Interface::Parameters::
103 SetValueAsIndex( const std::string& name, const TUint& n, ... )
104 {
105   TParameters::iterator pIt = this->m_Parameters.find( name );
106   if( pIt == this->m_Parameters.end( ) )
107     return;
108   if( pIt->second.first != Self::Index )
109     return;
110
111   va_list v_lst;
112   va_start( v_lst, n );
113
114   std::stringstream ss;
115   for( TUint i = 0; i < n; ++i )
116     ss << va_arg( v_lst, long ) << ":";
117   va_end( v_lst );
118
119   pIt->second.second = ss.str( );
120 }
121
122 // -------------------------------------------------------------------------
123 void cpPlugins::Interface::Parameters::
124 SetValueAsPoint( const std::string& name, const TUint& n, ... )
125 {
126   TParameters::iterator pIt = this->m_Parameters.find( name );
127   if( pIt == this->m_Parameters.end( ) )
128     return;
129   if( pIt->second.first != Self::Point )
130     return;
131
132   va_list v_lst;
133   va_start( v_lst, n );
134
135   std::stringstream ss;
136   for( TUint i = 0; i < n; ++i )
137     ss << va_arg( v_lst, double ) << ":";
138   va_end( v_lst );
139
140   pIt->second.second = ss.str( );
141 }
142
143 // -------------------------------------------------------------------------
144 const std::string& cpPlugins::Interface::Parameters::
145 GetValueAsString( const std::string& name ) const
146 {
147   static const std::string null_str = "";
148   TParameters::const_iterator pIt = this->m_Parameters.find( name );
149   if( pIt == this->m_Parameters.end( ) )
150     return( null_str );
151   if( pIt->second.first != Self::String )
152     return( null_str );
153
154   return( pIt->second.second );
155 }
156
157 // -------------------------------------------------------------------------
158 cpPlugins::Interface::Parameters::
159 TInt cpPlugins::Interface::Parameters::
160 GetValueAsInt( const std::string& name ) const
161 {
162   static const std::string null_str = "";
163   TParameters::const_iterator pIt = this->m_Parameters.find( name );
164   if( pIt == this->m_Parameters.end( ) )
165     return( TInt( 0 ) );
166   if( pIt->second.first != Self::Int )
167     return( TInt( 0 ) );
168
169   return( std::atoi( pIt->second.second.c_str( ) ) );
170 }
171
172 // -------------------------------------------------------------------------
173 cpPlugins::Interface::Parameters::
174 TUint cpPlugins::Interface::Parameters::
175 GetValueAsUint( const std::string& name ) const
176 {
177   static const std::string null_str = "";
178   TParameters::const_iterator pIt = this->m_Parameters.find( name );
179   if( pIt == this->m_Parameters.end( ) )
180     return( TUint( 0 ) );
181   if( pIt->second.first != Self::Uint )
182     return( TUint( 0 ) );
183
184   return( std::atoi( pIt->second.second.c_str( ) ) );
185 }
186
187 // -------------------------------------------------------------------------
188 cpPlugins::Interface::Parameters::
189 TReal cpPlugins::Interface::Parameters::
190 GetValueAsReal( const std::string& name ) const
191 {
192   static const std::string null_str = "";
193   TParameters::const_iterator pIt = this->m_Parameters.find( name );
194   if( pIt == this->m_Parameters.end( ) )
195     return( TReal( 0 ) );
196   if( pIt->second.first != Self::Real )
197     return( TReal( 0 ) );
198
199   return( std::atof( pIt->second.second.c_str( ) ) );
200 }
201
202 // -------------------------------------------------------------------------
203 void cpPlugins::Interface::Parameters::
204 GetValueAsStringList(
205   std::vector< std::string >& lst, const std::string& name
206   ) const
207 {
208 }
209
210 // -------------------------------------------------------------------------
211 void cpPlugins::Interface::Parameters::
212 GetValueAsIntList( std::vector< TInt >& lst, const std::string& name ) const
213 {
214 }
215
216 // -------------------------------------------------------------------------
217 void cpPlugins::Interface::Parameters::
218 GetValueAsUintList( std::vector< TUint >& lst, const std::string& name ) const
219 {
220 }
221
222 // -------------------------------------------------------------------------
223 void cpPlugins::Interface::Parameters::
224 GetValueAsRealList( std::vector< TReal >& lst, const std::string& name ) const
225 {
226 }
227
228 // eof - $RCSfile$