1 #include <cpPlugins/Interface/Parameters.h>
6 // -------------------------------------------------------------------------
7 #define cpPlugins_Interface_Parameters_SetMacro( TYPE ) \
8 void cpPlugins::Interface::Parameters:: \
9 SetValueAs##TYPE( const TString& name, const T##TYPE& v ) \
11 TParameters::iterator pIt = this->m_Parameters.find( name ); \
12 if( pIt == this->m_Parameters.end( ) ) \
14 if( pIt->second.first != Self::TYPE ) \
16 std::stringstream ss; \
18 pIt->second.second = ss.str( ); \
21 cpPlugins_Interface_Parameters_SetMacro( String );
22 cpPlugins_Interface_Parameters_SetMacro( Bool );
23 cpPlugins_Interface_Parameters_SetMacro( Int );
24 cpPlugins_Interface_Parameters_SetMacro( Uint );
25 cpPlugins_Interface_Parameters_SetMacro( Real );
27 // -------------------------------------------------------------------------
28 #define cpPlugins_Interface_Parameters_SetArrayMacro( TYPE, ATYPE ) \
29 void cpPlugins::Interface::Parameters:: \
30 SetValueAs##TYPE( const TString& name, const TUint& n, ... ) \
32 TParameters::iterator pIt = this->m_Parameters.find( name ); \
33 if( pIt == this->m_Parameters.end( ) ) \
35 if( pIt->second.first != Self::TYPE ) \
38 va_start( v_lst, n ); \
39 std::stringstream ss; \
40 for( TUint i = 0; i < n; ++i ) \
41 ss << va_arg( v_lst, ATYPE ) << ","; \
43 pIt->second.second = ss.str( ); \
46 cpPlugins_Interface_Parameters_SetArrayMacro( Index, int );
47 cpPlugins_Interface_Parameters_SetArrayMacro( Point, double );
49 // -------------------------------------------------------------------------
50 #define cpPlugins_Interface_Parameters_SetListMacro( TYPE ) \
51 void cpPlugins::Interface::Parameters:: \
52 AddValueTo##TYPE##List( const TString& name, const T##TYPE& v ) \
54 TParameters::iterator pIt = this->m_Parameters.find( name ); \
55 if( pIt == this->m_Parameters.end( ) ) \
57 if( pIt->second.first != Self::TYPE##List ) \
59 std::stringstream ss; \
60 ss << pIt->second.second << v << "#"; \
61 pIt->second.second = ss.str( ); \
64 cpPlugins_Interface_Parameters_SetListMacro( String );
65 cpPlugins_Interface_Parameters_SetListMacro( Bool );
66 cpPlugins_Interface_Parameters_SetListMacro( Int );
67 cpPlugins_Interface_Parameters_SetListMacro( Uint );
68 cpPlugins_Interface_Parameters_SetListMacro( Real );
70 // -------------------------------------------------------------------------
71 #define cpPlugins_Interface_Parameters_SetArrayListMacro( TYPE, ATYPE ) \
72 void cpPlugins::Interface::Parameters:: \
73 AddValueTo##TYPE##List( const TString& name, const TUint& n, ... ) \
75 TParameters::iterator pIt = this->m_Parameters.find( name ); \
76 if( pIt == this->m_Parameters.end( ) ) \
78 if( pIt->second.first != Self::TYPE##List ) \
81 va_start( v_lst, n ); \
82 std::stringstream ss; \
83 ss << pIt->second.second; \
84 for( TUint i = 0; i < n; ++i ) \
85 ss << va_arg( v_lst, ATYPE ) << ","; \
88 pIt->second.second = ss.str( ); \
91 cpPlugins_Interface_Parameters_SetArrayListMacro( Index, int );
92 cpPlugins_Interface_Parameters_SetArrayListMacro( Point, double );
94 // -------------------------------------------------------------------------
95 #define cpPlugins_Interface_Parameters_ClearListMacro( TYPE ) \
96 void cpPlugins::Interface::Parameters:: \
97 Clear##TYPE##List( const TString& name ) \
99 TParameters::iterator pIt = this->m_Parameters.find( name ); \
100 if( pIt == this->m_Parameters.end( ) ) \
102 if( pIt->second.first != Self::TYPE##List ) \
104 pIt->second.second = ""; \
107 cpPlugins_Interface_Parameters_ClearListMacro( String );
108 cpPlugins_Interface_Parameters_ClearListMacro( Bool );
109 cpPlugins_Interface_Parameters_ClearListMacro( Int );
110 cpPlugins_Interface_Parameters_ClearListMacro( Uint );
111 cpPlugins_Interface_Parameters_ClearListMacro( Real );
112 cpPlugins_Interface_Parameters_ClearListMacro( Index );
113 cpPlugins_Interface_Parameters_ClearListMacro( Point );
115 // -------------------------------------------------------------------------
116 cpPlugins::Interface::Parameters::
122 // -------------------------------------------------------------------------
123 cpPlugins::Interface::Parameters::
124 Parameters( const Self& other )
126 this->m_Parameters = other.m_Parameters;
129 // -------------------------------------------------------------------------
130 cpPlugins::Interface::Parameters::
136 // -------------------------------------------------------------------------
137 cpPlugins::Interface::Parameters::
138 Self& cpPlugins::Interface::Parameters::
139 operator=( const Self& other )
141 this->m_Parameters = other.m_Parameters;
145 // -------------------------------------------------------------------------
146 void cpPlugins::Interface::Parameters::
149 this->m_Parameters.clear( );
152 // -------------------------------------------------------------------------
153 void cpPlugins::Interface::Parameters::
154 Configure( const Self::Type& type, const TString& name )
156 this->m_Parameters[ name ] = TParameter( type, "" );
159 // -------------------------------------------------------------------------
160 std::vector< cpPlugins::Interface::Parameters::TString >
161 cpPlugins::Interface::Parameters::
162 GetParameters( ) const
164 std::vector< TString > parameters;
165 TParameters::const_iterator pIt = this->m_Parameters.begin( );
166 for( ; pIt != this->m_Parameters.end( ); ++pIt )
167 parameters.push_back( pIt->first );
168 return( parameters );
171 // -------------------------------------------------------------------------
172 cpPlugins::Interface::Parameters::
173 Type cpPlugins::Interface::Parameters::
174 GetParameterType( const TString& name ) const
176 TParameters::const_iterator pIt = this->m_Parameters.find( name );
177 if( pIt == this->m_Parameters.end( ) )
178 return( Self::NoType );
179 return( pIt->second.first );
182 // -------------------------------------------------------------------------
183 const cpPlugins::Interface::Parameters::
184 TString& cpPlugins::Interface::Parameters::
185 GetRawValue( const TString& name ) const
187 static const TString null_str = "";
188 TParameters::const_iterator pIt = this->m_Parameters.find( name );
189 if( pIt == this->m_Parameters.end( ) )
191 return( pIt->second.second );
194 // -------------------------------------------------------------------------
195 const cpPlugins::Interface::Parameters::
196 TString& cpPlugins::Interface::Parameters::
197 GetValueAsString( const TString& name ) const
199 static const TString null_str = "";
200 TParameters::const_iterator pIt = this->m_Parameters.find( name );
201 if( pIt == this->m_Parameters.end( ) )
203 if( pIt->second.first != Self::String )
206 return( pIt->second.second );
209 // -------------------------------------------------------------------------
210 cpPlugins::Interface::Parameters::
211 TBool cpPlugins::Interface::Parameters::
212 GetValueAsBool( const TString& name ) const
214 TParameters::const_iterator pIt = this->m_Parameters.find( name );
215 if( pIt == this->m_Parameters.end( ) )
216 return( TBool( false ) );
217 if( pIt->second.first != Self::Bool )
218 return( TBool( false ) );
219 return( TBool( std::atoi( pIt->second.second.c_str( ) ) == 1 ) );
222 // -------------------------------------------------------------------------
223 cpPlugins::Interface::Parameters::
224 TInt cpPlugins::Interface::Parameters::
225 GetValueAsInt( const TString& name ) const
227 TParameters::const_iterator pIt = this->m_Parameters.find( name );
228 if( pIt == this->m_Parameters.end( ) )
230 if( pIt->second.first != Self::Int )
232 return( TInt( std::atoi( pIt->second.second.c_str( ) ) ) );
235 // -------------------------------------------------------------------------
236 cpPlugins::Interface::Parameters::
237 TUint cpPlugins::Interface::Parameters::
238 GetValueAsUint( const TString& name ) const
240 TParameters::const_iterator pIt = this->m_Parameters.find( name );
241 if( pIt == this->m_Parameters.end( ) )
242 return( TUint( 0 ) );
243 if( pIt->second.first != Self::Uint )
244 return( TUint( 0 ) );
245 return( TUint( std::atoi( pIt->second.second.c_str( ) ) ) );
248 // -------------------------------------------------------------------------
249 cpPlugins::Interface::Parameters::
250 TReal cpPlugins::Interface::Parameters::
251 GetValueAsReal( const TString& name ) const
253 TParameters::const_iterator pIt = this->m_Parameters.find( name );
254 if( pIt == this->m_Parameters.end( ) )
255 return( TReal( 0 ) );
256 if( pIt->second.first != Self::Real )
257 return( TReal( 0 ) );
258 return( TReal( std::atof( pIt->second.second.c_str( ) ) ) );
261 // -------------------------------------------------------------------------
262 void cpPlugins::Interface::Parameters::
263 GetValueAsStringList(
264 std::vector< TString >& lst, const TString& name
268 TParameters::const_iterator pIt = this->m_Parameters.find( name );
269 if( pIt == this->m_Parameters.end( ) )
271 if( pIt->second.first != Self::StringList )
274 std::istringstream ss( pIt->second.second );
276 while( std::getline( ss, token, '#' ) )
278 lst.push_back( token );
281 // -------------------------------------------------------------------------
282 void cpPlugins::Interface::Parameters::
283 GetValueAsBoolList( std::vector< TBool >& lst, const TString& name ) const
286 TParameters::const_iterator pIt = this->m_Parameters.find( name );
287 if( pIt == this->m_Parameters.end( ) )
289 if( pIt->second.first != Self::BoolList )
292 std::istringstream ss( pIt->second.second );
294 while( std::getline( ss, token, '#' ) )
296 lst.push_back( TBool( std::atoi( token.c_str( ) ) == 1 ) );
299 // -------------------------------------------------------------------------
300 void cpPlugins::Interface::Parameters::
301 GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const
304 TParameters::const_iterator pIt = this->m_Parameters.find( name );
305 if( pIt == this->m_Parameters.end( ) )
307 if( pIt->second.first != Self::IntList )
310 std::istringstream ss( pIt->second.second );
312 while( std::getline( ss, token, '#' ) )
314 lst.push_back( TInt( std::atoi( token.c_str( ) ) ) );
317 // -------------------------------------------------------------------------
318 void cpPlugins::Interface::Parameters::
319 GetValueAsUintList( std::vector< TUint >& lst, const TString& name ) const
322 TParameters::const_iterator pIt = this->m_Parameters.find( name );
323 if( pIt == this->m_Parameters.end( ) )
325 if( pIt->second.first != Self::UintList )
328 std::istringstream ss( pIt->second.second );
330 while( std::getline( ss, token, '#' ) )
332 lst.push_back( TUint( std::atoi( token.c_str( ) ) ) );
335 // -------------------------------------------------------------------------
336 void cpPlugins::Interface::Parameters::
337 GetValueAsRealList( std::vector< TReal >& lst, const TString& name ) const
340 TParameters::const_iterator pIt = this->m_Parameters.find( name );
341 if( pIt == this->m_Parameters.end( ) )
343 if( pIt->second.first != Self::RealList )
346 std::istringstream ss( pIt->second.second );
348 while( std::getline( ss, token, '#' ) )
350 lst.push_back( TReal( std::atof( token.c_str( ) ) ) );
353 // -------------------------------------------------------------------------
354 bool cpPlugins::Interface::Parameters::
355 HasStringValue( const TString& name ) const
357 TParameters::const_iterator pIt = this->m_Parameters.find( name );
358 if( pIt != this->m_Parameters.end( ) )
359 return( pIt->second.first == Self::String );
363 // -------------------------------------------------------------------------
364 bool cpPlugins::Interface::Parameters::
365 HasBoolValue( const TString& name ) const
367 TParameters::const_iterator pIt = this->m_Parameters.find( name );
368 if( pIt != this->m_Parameters.end( ) )
369 return( pIt->second.first == Self::Bool );
373 // -------------------------------------------------------------------------
374 bool cpPlugins::Interface::Parameters::
375 HasIntValue( const TString& name ) const
377 TParameters::const_iterator pIt = this->m_Parameters.find( name );
378 if( pIt != this->m_Parameters.end( ) )
379 return( pIt->second.first == Self::Int );
383 // -------------------------------------------------------------------------
384 bool cpPlugins::Interface::Parameters::
385 HasUintValue( const TString& name ) const
387 TParameters::const_iterator pIt = this->m_Parameters.find( name );
388 if( pIt != this->m_Parameters.end( ) )
389 return( pIt->second.first == Self::Uint );
393 // -------------------------------------------------------------------------
394 bool cpPlugins::Interface::Parameters::
395 HasRealValue( const TString& name ) const
397 TParameters::const_iterator pIt = this->m_Parameters.find( name );
398 if( pIt != this->m_Parameters.end( ) )
399 return( pIt->second.first == Self::Real );
403 // -------------------------------------------------------------------------
404 bool cpPlugins::Interface::Parameters::
405 HasIndexValue( const TString& name ) const
407 TParameters::const_iterator pIt = this->m_Parameters.find( name );
408 if( pIt != this->m_Parameters.end( ) )
409 return( pIt->second.first == Self::Index );
413 // -------------------------------------------------------------------------
414 bool cpPlugins::Interface::Parameters::
415 HasPointValue( const TString& name ) const
417 TParameters::const_iterator pIt = this->m_Parameters.find( name );
418 if( pIt != this->m_Parameters.end( ) )
419 return( pIt->second.first == Self::Point );
423 // -------------------------------------------------------------------------
424 bool cpPlugins::Interface::Parameters::
425 HasStringListValue( const TString& name ) const
427 TParameters::const_iterator pIt = this->m_Parameters.find( name );
428 if( pIt != this->m_Parameters.end( ) )
429 return( pIt->second.first == Self::StringList );
433 // -------------------------------------------------------------------------
434 bool cpPlugins::Interface::Parameters::
435 HasBoolListValue( const TString& name ) const
437 TParameters::const_iterator pIt = this->m_Parameters.find( name );
438 if( pIt != this->m_Parameters.end( ) )
439 return( pIt->second.first == Self::BoolList );
443 // -------------------------------------------------------------------------
444 bool cpPlugins::Interface::Parameters::
445 HasIntListValue( const TString& name ) const
447 TParameters::const_iterator pIt = this->m_Parameters.find( name );
448 if( pIt != this->m_Parameters.end( ) )
449 return( pIt->second.first == Self::IntList );
453 // -------------------------------------------------------------------------
454 bool cpPlugins::Interface::Parameters::
455 HasUintListValue( const TString& name ) const
457 TParameters::const_iterator pIt = this->m_Parameters.find( name );
458 if( pIt != this->m_Parameters.end( ) )
459 return( pIt->second.first == Self::UintList );
463 // -------------------------------------------------------------------------
464 bool cpPlugins::Interface::Parameters::
465 HasRealListValue( const TString& name ) const
467 TParameters::const_iterator pIt = this->m_Parameters.find( name );
468 if( pIt != this->m_Parameters.end( ) )
469 return( pIt->second.first == Self::RealList );
473 // -------------------------------------------------------------------------
474 bool cpPlugins::Interface::Parameters::
475 HasIndexListValue( const TString& name ) const
477 TParameters::const_iterator pIt = this->m_Parameters.find( name );
478 if( pIt != this->m_Parameters.end( ) )
479 return( pIt->second.first == Self::IndexList );
483 // -------------------------------------------------------------------------
484 bool cpPlugins::Interface::Parameters::
485 HasPointListValue( const TString& name ) const
487 TParameters::const_iterator pIt = this->m_Parameters.find( name );
488 if( pIt != this->m_Parameters.end( ) )
489 return( pIt->second.first == Self::PointList );