]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BaseObjects/Parameters.cxx
227898cddc843e4dadfd8750b4a4caf3e8822e98
[cpPlugins.git] / lib / cpPlugins / BaseObjects / Parameters.cxx
1 #include <cpPlugins/BaseObjects/Parameters.h>
2 #include <cpPlugins/BaseObjects/ProcessObject.h>
3 #include <cpPlugins/Utility.h>
4 #include <tinyxml2/tinyxml2.h>
5
6 // -------------------------------------------------------------------------
7 cpPlugins::BaseObjects::Parameters::
8 Parameters( )
9   : m_ProcessObject( NULL )
10 {
11   this->Clear( );
12 }
13
14 // -------------------------------------------------------------------------
15 cpPlugins::BaseObjects::Parameters::
16 ~Parameters( )
17 {
18 }
19
20 // -------------------------------------------------------------------------
21 cpPlugins::BaseObjects::ProcessObject* cpPlugins::BaseObjects::Parameters::
22 GetProcessObject( )
23 {
24   return( this->m_ProcessObject );
25 }
26
27 // -------------------------------------------------------------------------
28 const
29 cpPlugins::BaseObjects::ProcessObject* cpPlugins::BaseObjects::Parameters::
30 GetProcessObject( ) const
31 {
32   return( this->m_ProcessObject );
33 }
34
35 // -------------------------------------------------------------------------
36 void cpPlugins::BaseObjects::Parameters::
37 SetProcessObject( cpPlugins::BaseObjects::ProcessObject* po )
38 {
39   this->m_ProcessObject = po;
40 }
41
42 // -------------------------------------------------------------------------
43 void cpPlugins::BaseObjects::Parameters::
44 Modified( ) const
45 {
46   if( this->m_ProcessObject != NULL )
47     this->m_ProcessObject->Modified( );
48 }
49
50 // -------------------------------------------------------------------------
51 void cpPlugins::BaseObjects::Parameters::
52 Clear( )
53 {
54   this->m_Parameters.clear( );
55   this->Modified( );
56 }
57
58 // -------------------------------------------------------------------------
59 void cpPlugins::BaseObjects::Parameters::
60 GetNames( std::vector< std::string >& container ) const
61 {
62   container.clear( );
63   TParameters::const_iterator i = this->m_Parameters.begin( );
64   for( ; i != this->m_Parameters.end( ); ++i )
65     container.push_back( i->first );
66 }
67
68 // -------------------------------------------------------------------------
69 cpPlugins::BaseObjects::Parameters::
70 Type cpPlugins::BaseObjects::Parameters::
71 GetType( const std::string& name ) const
72 {
73   auto i = this->m_Parameters.find( name );
74   if( i != this->m_Parameters.end( ) )
75     return( i->second.first );
76   else
77     return( Self::NoType );
78 }
79
80 // -------------------------------------------------------------------------
81 #define cpPlugins_BaseObjects_Parameters_TypeAsString( Y )      \
82   if( i->second.first == Self::Y )                              \
83     return( #Y )
84
85 std::string cpPlugins::BaseObjects::Parameters::
86 GetTypeAsString( const std::string& name ) const
87 {
88   auto i = this->m_Parameters.find( name );
89   cpPlugins_BaseObjects_Parameters_TypeAsString( String );
90   else cpPlugins_BaseObjects_Parameters_TypeAsString( Bool );
91   else cpPlugins_BaseObjects_Parameters_TypeAsString( Int );
92   else cpPlugins_BaseObjects_Parameters_TypeAsString( Uint );
93   else cpPlugins_BaseObjects_Parameters_TypeAsString( Real );
94   else cpPlugins_BaseObjects_Parameters_TypeAsString( OpenFileName );
95   else cpPlugins_BaseObjects_Parameters_TypeAsString( SaveFileName );
96   else cpPlugins_BaseObjects_Parameters_TypeAsString( PathName );
97   else cpPlugins_BaseObjects_Parameters_TypeAsString( StringList );
98   else cpPlugins_BaseObjects_Parameters_TypeAsString( BoolList );
99   else cpPlugins_BaseObjects_Parameters_TypeAsString( IntList );
100   else cpPlugins_BaseObjects_Parameters_TypeAsString( UintList );
101   else cpPlugins_BaseObjects_Parameters_TypeAsString( RealList );
102   else cpPlugins_BaseObjects_Parameters_TypeAsString( OpenFileNameList );
103   else cpPlugins_BaseObjects_Parameters_TypeAsString( SaveFileNameList );
104   else cpPlugins_BaseObjects_Parameters_TypeAsString( PathNameList );
105   else cpPlugins_BaseObjects_Parameters_TypeAsString( Choices );
106   else return( "NoType" );
107 }
108
109 // -------------------------------------------------------------------------
110 #define cpPlugins_BaseObjects_Parameters_TypeFromString( Y, str )   \
111   if( str == std::string( #Y ) )                                    \
112     return( Self::Y )
113
114 cpPlugins::BaseObjects::Parameters::
115 Type cpPlugins::BaseObjects::Parameters::
116 GetTypeFromString( const std::string& t )
117 {
118   cpPlugins_BaseObjects_Parameters_TypeFromString( String, t );
119   else cpPlugins_BaseObjects_Parameters_TypeFromString( Bool, t );
120   else cpPlugins_BaseObjects_Parameters_TypeFromString( Int, t );
121   else cpPlugins_BaseObjects_Parameters_TypeFromString( Uint, t );
122   else cpPlugins_BaseObjects_Parameters_TypeFromString( Real, t );
123   else cpPlugins_BaseObjects_Parameters_TypeFromString( OpenFileName, t );
124   else cpPlugins_BaseObjects_Parameters_TypeFromString( SaveFileName, t );
125   else cpPlugins_BaseObjects_Parameters_TypeFromString( PathName, t );
126   else cpPlugins_BaseObjects_Parameters_TypeFromString( StringList, t );
127   else cpPlugins_BaseObjects_Parameters_TypeFromString( BoolList, t );
128   else cpPlugins_BaseObjects_Parameters_TypeFromString( IntList, t );
129   else cpPlugins_BaseObjects_Parameters_TypeFromString( UintList, t );
130   else cpPlugins_BaseObjects_Parameters_TypeFromString( RealList, t );
131   else cpPlugins_BaseObjects_Parameters_TypeFromString( OpenFileNameList, t );
132   else cpPlugins_BaseObjects_Parameters_TypeFromString( SaveFileNameList, t );
133   else cpPlugins_BaseObjects_Parameters_TypeFromString( PathNameList, t );
134   else cpPlugins_BaseObjects_Parameters_TypeFromString( Choices, t );
135   else return( Self::NoType );
136 }
137
138 // -------------------------------------------------------------------------
139 std::string cpPlugins::BaseObjects::Parameters::
140 GetString( const std::string& name, bool force ) const
141 {
142   auto i = this->m_Parameters.find( name );
143   if( i != this->m_Parameters.end( ) )
144   {
145     if( i->second.first == Self::String || force )
146       return( i->second.second );
147     else
148       return( "" );
149   }
150   else
151     return( "" );
152 }
153
154 // -------------------------------------------------------------------------
155 void cpPlugins::BaseObjects::Parameters::
156 SetString( const std::string& name, const std::string& v, bool force )
157 {
158   auto i = this->m_Parameters.find( name );
159   if( i != this->m_Parameters.end( ) )
160   {
161     if( i->second.first == Self::String || force )
162     {
163       if( i->second.second != v )
164       {
165         i->second.second = v;
166         this->Modified( );
167
168       } // fi
169
170     } // fi
171
172   } // fi
173 }
174
175 // -------------------------------------------------------------------------
176 void cpPlugins::BaseObjects::Parameters::
177 ConfigureAsChoices(
178   const std::string& name, const std::vector< std::string >& choices
179   )
180 {
181   // It is invalid not to give choices when configuring
182   if( choices.size( ) == 0 )
183     return;
184
185   std::stringstream str_choices;
186   str_choices << choices[ 0 ];
187   for( unsigned int i = 1; i < choices.size( ); ++i )
188     str_choices << "#" << choices[ i ];
189   str_choices << "@";
190   this->m_Parameters[ name ] =
191     TParameter( Self::Choices, str_choices.str( ) );
192   this->Modified( );
193 }
194
195 // -------------------------------------------------------------------------
196 void cpPlugins::BaseObjects::Parameters::
197 ConfigureAsRealTypesChoices( const std::string& name )
198 {
199   std::vector< std::string > choices;
200 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
201   choices.push_back( "float" );
202 #endif // cpPlugins_CONFIG_REAL_TYPES_float
203 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
204   choices.push_back( "double" );
205 #endif // cpPlugins_CONFIG_REAL_TYPES_double
206   this->ConfigureAsChoices( name, choices );
207 }
208
209 // -------------------------------------------------------------------------
210 void cpPlugins::BaseObjects::Parameters::
211 ConfigureAsIntTypesChoices( const std::string& name )
212 {
213   std::vector< std::string > choices;
214 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
215   choices.push_back( "char" );
216   choices.push_back( "uchar" );
217 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
218 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
219   choices.push_back( "short" );
220   choices.push_back( "ushort" );
221 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
222 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
223   choices.push_back( "int" );
224   choices.push_back( "uint" );
225 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
226 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
227   choices.push_back( "long" );
228   choices.push_back( "ulong" );
229 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
230   this->ConfigureAsChoices( name, choices );
231 }
232
233 // -------------------------------------------------------------------------
234 void cpPlugins::BaseObjects::Parameters::
235 ConfigureAsScalarTypesChoices( const std::string& name )
236 {
237   std::vector< std::string > choices;
238 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
239   choices.push_back( "char" );
240   choices.push_back( "uchar" );
241 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
242 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
243   choices.push_back( "short" );
244   choices.push_back( "ushort" );
245 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
246 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
247   choices.push_back( "int" );
248   choices.push_back( "uint" );
249 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
250 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
251   choices.push_back( "long" );
252   choices.push_back( "ulong" );
253 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
254 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
255   choices.push_back( "float" );
256 #endif // cpPlugins_CONFIG_REAL_TYPES_float
257 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
258   choices.push_back( "double" );
259 #endif // cpPlugins_CONFIG_REAL_TYPES_double
260   this->ConfigureAsChoices( name, choices );
261 }
262
263 // -------------------------------------------------------------------------
264 std::vector< std::string > cpPlugins::BaseObjects::Parameters::
265 GetChoices( const std::string& name ) const
266 {
267   std::vector< std::string > choices;
268
269   TParameters::const_iterator i = this->m_Parameters.find( name );
270   if( i != this->m_Parameters.end( ) )
271   {
272     if( i->second.first == Self::Choices )
273     {
274       std::istringstream str_choices( i->second.second );
275       std::string real_choices;
276       std::getline( str_choices, real_choices, '@' );
277       std::istringstream str( real_choices );
278       std::string token;
279       while( std::getline( str, token, '#' ) )
280         choices.push_back( token );
281
282     } // fi
283
284   } // fi
285   return( choices );
286 }
287
288 // -------------------------------------------------------------------------
289 std::string cpPlugins::BaseObjects::Parameters::
290 GetSelectedChoice( const std::string& name ) const
291 {
292   auto i = this->m_Parameters.find( name );
293   if( i != this->m_Parameters.end( ) )
294   {
295     if( i->second.first == Self::Choices )
296     {
297       std::istringstream str_choices( i->second.second );
298       std::string real_choice;
299       std::getline( str_choices, real_choice, '@' );
300       std::getline( str_choices, real_choice, '@' );
301       return( real_choice );
302     }
303     else
304       return( "" );
305   }
306   else
307     return( "" );
308 }
309
310 // -------------------------------------------------------------------------
311 bool cpPlugins::BaseObjects::Parameters::
312 SetSelectedChoice( const std::string& name, const std::string& choice )
313 {
314   auto i = this->m_Parameters.find( name );
315   if( i != this->m_Parameters.end( ) )
316   {
317     if( i->second.first == Self::Choices )
318     {
319       std::istringstream str_choices( i->second.second );
320       std::string choices;
321       std::getline( str_choices, choices, '@' );
322       if( choices.find( choice ) != std::string::npos )
323       {
324         std::stringstream new_choices;
325         new_choices << choices << "@" << choice;
326         i->second.second = new_choices.str( );
327         this->Modified( );
328         return( true );
329       }
330       else
331         return( false );
332     }
333     else
334       return( false );
335   }
336   else
337     return( false );
338 }
339
340 // -------------------------------------------------------------------------
341 std::string cpPlugins::BaseObjects::Parameters::
342 GetAcceptedFileExtensions( const std::string& name ) const
343 {
344   auto i = this->m_AcceptedFileExtensions.find( name );
345   if( i != this->m_AcceptedFileExtensions.end( ) )
346     return( i->second );
347   else
348     return( "" );
349 }
350
351 // -------------------------------------------------------------------------
352 void cpPlugins::BaseObjects::Parameters::
353 SetAcceptedFileExtensions(
354   const std::string& name, const std::string& extensions
355   )
356 {
357   auto i = this->m_Parameters.find( name );
358   if( i != this->m_Parameters.end( ) )
359   {
360     bool is_valid = ( i->second.first == Self::OpenFileName );
361     is_valid     |= ( i->second.first == Self::SaveFileName );
362     is_valid     |= ( i->second.first == Self::OpenFileNameList );
363     is_valid     |= ( i->second.first == Self::SaveFileNameList );
364     if( is_valid )
365       this->m_AcceptedFileExtensions[ name ] = extensions;
366
367   } // fi
368 }
369
370 // -------------------------------------------------------------------------
371 bool cpPlugins::BaseObjects::Parameters::
372 ToXML(
373   tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* parent_elem
374   ) const
375 {
376   if( parent_elem == NULL )
377     return( false );
378
379   auto pIt = this->m_Parameters.begin( );
380   for( ; pIt != this->m_Parameters.end( ); ++pIt )
381   {
382     tinyxml2::XMLElement* p = doc->NewElement( "Parameter" );
383     p->SetAttribute( "Name", pIt->first.c_str( ) );
384     p->SetAttribute( "Value", pIt->second.second.c_str( ) );
385     p->SetAttribute( "Type", this->GetTypeAsString( pIt->first ).c_str( ) );
386     parent_elem->InsertEndChild( p );
387
388   } // rof
389   return( true );
390 }
391
392 // -------------------------------------------------------------------------
393 bool cpPlugins::BaseObjects::Parameters::
394 FromXML( const tinyxml2::XMLElement* filter_elem )
395 {
396   const tinyxml2::XMLElement* param =
397     filter_elem->FirstChildElement( "Parameter" );
398   bool ret = false;
399   while( param != NULL )
400   {
401     const char* param_name = param->Attribute( "Name" );
402     const char* param_type = param->Attribute( "Type" );
403     if( param_name != NULL && param_type != NULL )
404     {
405       TParameter value;
406       value.second = param->Attribute( "Value" );
407       value.first = Self::GetTypeFromString( param_type );
408       this->m_Parameters[ param_name ] = value;
409
410     } // fi
411     param = param->NextSiblingElement( "Parameter" );
412     ret = true;
413
414   } // elihw
415   this->Modified( );
416   return( ret );
417 }
418
419 // -------------------------------------------------------------------------
420 cpPlugins::BaseObjects::Parameters::
421 TParameters& cpPlugins::BaseObjects::Parameters::
422 GetRawParameters( )
423 {
424   return( this->m_Parameters );
425 }
426
427 // -------------------------------------------------------------------------
428 const cpPlugins::BaseObjects::Parameters::
429 TParameters& cpPlugins::BaseObjects::Parameters::
430 GetRawParameters( ) const
431 {
432   return( this->m_Parameters );
433 }
434
435 // -------------------------------------------------------------------------
436 #define cpPlugins_BaseObjects_Parameters_Configure_Code( Y )            \
437   void cpPlugins::BaseObjects::Parameters::                             \
438   ConfigureAs##Y( const std::string& name, const T##Y& init )           \
439   {                                                                     \
440     this->_Configure< Y >( name );                                      \
441     this->Set##Y( name, init );                                         \
442   }                                                                     \
443   bool cpPlugins::BaseObjects::Parameters::                             \
444   Has##Y( const std::string& name ) const                               \
445   { return( this->_Has< Y >( name ) ); }
446
447 // -------------------------------------------------------------------------
448 #define cpPlugins_BaseObjects_Parameters_ConfigureList_Code( Y )        \
449   void cpPlugins::BaseObjects::Parameters::                             \
450   ConfigureAs##Y##List( const std::string& name )                       \
451   { this->_Configure< Y##List >( name ); }                              \
452   bool cpPlugins::BaseObjects::Parameters::                             \
453   Has##Y##List( const std::string& name ) const                         \
454   { return( this->_Has< Y##List >( name ) ); }
455
456 // -------------------------------------------------------------------------
457 #define cpPlugins_BaseObjects_Parameters_GetSet_Code( Y )               \
458   cpPlugins::BaseObjects::Parameters::T##Y                              \
459   cpPlugins::BaseObjects::Parameters::                                  \
460   Get##Y( const std::string& name ) const                               \
461   { return( this->_Get< T##Y, Y >( name ) ); }                          \
462   void cpPlugins::BaseObjects::Parameters::Set##Y(                      \
463     const std::string& name, const T##Y& v                              \
464     )                                                                   \
465   { this->_Set< T##Y, Y >( name, v ); }
466
467 // -------------------------------------------------------------------------
468 #define cpPlugins_BaseObjects_Parameters_GetSetList_Code( Y )           \
469   std::vector< cpPlugins::BaseObjects::Parameters::T##Y >               \
470   cpPlugins::BaseObjects::Parameters::                                  \
471   Get##Y##List( const std::string& name ) const                         \
472   { return( this->_GetList< T##Y, Y##List >( name ) ); }                \
473   void cpPlugins::BaseObjects::Parameters::AddTo##Y##List(              \
474     const std::string& name,                                            \
475     const cpPlugins::BaseObjects::Parameters::T##Y& v                   \
476     )                                                                   \
477   { this->_AddToList< T##Y, Y##List >( name, v ); }                     \
478   void cpPlugins::BaseObjects::Parameters::                             \
479   Clear##Y##List( const std::string& name )                             \
480   { this->_ClearList< Y##List >( name ); }
481
482 // -------------------------------------------------------------------------
483 cpPlugins_BaseObjects_Parameters_Configure_Code( String );
484 cpPlugins_BaseObjects_Parameters_Configure_Code( Bool );
485 cpPlugins_BaseObjects_Parameters_Configure_Code( Int );
486 cpPlugins_BaseObjects_Parameters_Configure_Code( Uint );
487 cpPlugins_BaseObjects_Parameters_Configure_Code( Real );
488 cpPlugins_BaseObjects_Parameters_Configure_Code( OpenFileName );
489 cpPlugins_BaseObjects_Parameters_Configure_Code( SaveFileName );
490 cpPlugins_BaseObjects_Parameters_Configure_Code( PathName );
491
492 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( String );
493 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( Bool );
494 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( Int );
495 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( Uint );
496 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( Real );
497 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( OpenFileName );
498 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( SaveFileName );
499 cpPlugins_BaseObjects_Parameters_ConfigureList_Code( PathName );
500
501 cpPlugins_BaseObjects_Parameters_GetSet_Code( Bool );
502 cpPlugins_BaseObjects_Parameters_GetSet_Code( Int );
503 cpPlugins_BaseObjects_Parameters_GetSet_Code( Uint );
504 cpPlugins_BaseObjects_Parameters_GetSet_Code( Real );
505 cpPlugins_BaseObjects_Parameters_GetSet_Code( OpenFileName );
506 cpPlugins_BaseObjects_Parameters_GetSet_Code( SaveFileName );
507 cpPlugins_BaseObjects_Parameters_GetSet_Code( PathName );
508
509 cpPlugins_BaseObjects_Parameters_GetSetList_Code( String );
510 cpPlugins_BaseObjects_Parameters_GetSetList_Code( Bool );
511 cpPlugins_BaseObjects_Parameters_GetSetList_Code( Int );
512 cpPlugins_BaseObjects_Parameters_GetSetList_Code( Uint );
513 cpPlugins_BaseObjects_Parameters_GetSetList_Code( Real );
514 cpPlugins_BaseObjects_Parameters_GetSetList_Code( PathName );
515
516 // -------------------------------------------------------------------------
517 std::vector< cpPlugins::BaseObjects::Parameters::TOpenFileName >
518 cpPlugins::BaseObjects::Parameters::
519 GetOpenFileNameList( const std::string& name ) const
520 {
521   return( this->_GetList< TOpenFileName, OpenFileNameList >( name ) );
522 }
523
524 // -------------------------------------------------------------------------
525 void cpPlugins::BaseObjects::Parameters::
526 AddToOpenFileNameList(
527   const std::string& name,
528   const cpPlugins::BaseObjects::Parameters::TOpenFileName& v
529   )
530 {
531   auto i = this->m_Parameters.find( name );
532   if( i != this->m_Parameters.end( ) )
533   {
534     if( i->second.first == OpenFileNameList )
535     {
536       auto pos = v.find_last_of( "/\\" );
537       if( i->second.second == "" )
538         i->second.second = v.substr( 0, pos );
539       i->second.second += std::string( "#" );
540       i->second.second += v.substr( pos + 1 );
541       this->Modified( );
542
543     } // fi
544
545   } // fi
546 }
547
548 // -------------------------------------------------------------------------
549 void cpPlugins::BaseObjects::Parameters::
550 ClearOpenFileNameList( const std::string& name )
551 {
552   this->_ClearList< OpenFileNameList >( name );
553 }
554
555 // -------------------------------------------------------------------------
556 std::vector< cpPlugins::BaseObjects::Parameters::TSaveFileName >
557 cpPlugins::BaseObjects::Parameters::
558 GetSaveFileNameList( const std::string& name ) const
559 {
560   return( this->_GetList< TSaveFileName, SaveFileNameList >( name ) );
561 }
562
563 // -------------------------------------------------------------------------
564 void cpPlugins::BaseObjects::Parameters::
565 AddToSaveFileNameList(
566   const std::string& name,
567   const cpPlugins::BaseObjects::Parameters::TSaveFileName& v
568   )
569 {
570   auto i = this->m_Parameters.find( name );
571   if( i != this->m_Parameters.end( ) )
572   {
573     if( i->second.first == SaveFileNameList )
574     {
575       auto pos = v.find_last_of( "/\\" );
576       if( i->second.second == "" )
577         i->second.second = v.substr( 0, pos );
578       i->second.second += std::string( "#" );
579       i->second.second += v.substr( pos + 1 );
580       this->Modified( );
581
582     } // fi
583
584   } // fi
585 }
586
587 // -------------------------------------------------------------------------
588 void cpPlugins::BaseObjects::Parameters::
589 ClearSaveFileNameList( const std::string& name )
590 {
591   this->_ClearList< SaveFileNameList >( name );
592 }
593
594 // -------------------------------------------------------------------------
595 template< unsigned int _Enum >
596 void cpPlugins::BaseObjects::Parameters::
597 _Configure( const std::string& name )
598 {
599   this->m_Parameters[ name ] = TParameter( ( Self::Type )( _Enum ), "" );
600   this->Modified( );
601 }
602
603 // -------------------------------------------------------------------------
604 template< unsigned int _Enum >
605 bool cpPlugins::BaseObjects::Parameters::
606 _Has( const std::string& name ) const
607 {
608   auto i = this->m_Parameters.find( name );
609   if( i != this->m_Parameters.end( ) )
610     return( i->second.first == ( Self::Type )( _Enum ) );
611   else
612     return( false );
613 }
614
615 // -------------------------------------------------------------------------
616 template< class _Type, unsigned int _Enum >
617 _Type cpPlugins::BaseObjects::Parameters::
618 _Get( const std::string& name ) const
619 {
620   auto i = this->m_Parameters.find( name );
621   if( i != this->m_Parameters.end( ) )
622   {
623     if( i->second.first == ( Self::Type )( _Enum ) )
624     {
625       if( typeid( _Type ) != typeid( std::string ) )
626       {
627         std::istringstream tok_str( i->second.second );
628         _Type v;
629         tok_str >> v;
630         return( v );
631       }
632       else
633       {
634         const _Type* ptr =
635           reinterpret_cast< const _Type* >( &( i->second.second ) );
636         return( *ptr );
637
638       } // fi
639
640     } // fi
641
642   } // fi
643   return( _Type( 0 ) );
644 }
645
646 // -------------------------------------------------------------------------
647 template< class _Type, unsigned int _Enum >
648 void cpPlugins::BaseObjects::Parameters::
649 _Set( const std::string& name, const _Type& v )
650 {
651   auto i = this->m_Parameters.find( name );
652   if( i != this->m_Parameters.end( ) )
653   {
654     if( i->second.first == ( Self::Type )( _Enum ) )
655     {
656       if( typeid( _Type ) != typeid( std::string ) )
657       {
658         std::stringstream str;
659         str << v;
660         if( i->second.second != str.str( ) )
661         {
662           i->second.second = str.str( );
663           this->Modified( );
664
665         } // fi
666       }
667       else
668       {
669         const std::string* str = reinterpret_cast< const std::string* >( &v );
670         if( i->second.second != *str )
671         {
672           i->second.second = *str;
673           this->Modified( );
674
675         } // fi
676
677       } // fi
678
679     } // fi
680
681   } // fi
682
683 }
684
685 // -------------------------------------------------------------------------
686 template< class _Type, unsigned int _Enum >
687 std::vector< _Type > cpPlugins::BaseObjects::Parameters::
688 _GetList( const std::string& name ) const
689 {
690   std::vector< _Type > lst;
691   std::vector< std::string >* slst =
692     reinterpret_cast< std::vector< std::string >* >( &lst );
693   auto i = this->m_Parameters.find( name );
694   if( i != this->m_Parameters.end( ) )
695   {
696     if( i->second.first == ( Self::Type )( _Enum ) )
697     {
698       std::vector< std::string > tokens;
699       cpPlugins::Tokenize( tokens, i->second.second, "#" );
700       for( auto t = tokens.begin( ); t != tokens.end( ); ++t )
701       {
702         if( typeid( _Type ) != typeid( std::string ) )
703         {
704           std::istringstream tok_str( *t );
705           _Type v;
706           tok_str >> v;
707           lst.push_back( v );
708         }
709         else
710           slst->push_back( *t );
711
712       } // rof
713
714     } // fi
715
716   } // fi
717   return( lst );
718 }
719
720 // -------------------------------------------------------------------------
721 template< class _Type, unsigned int _Enum >
722 void cpPlugins::BaseObjects::Parameters::
723 _AddToList( const std::string& name, const _Type& v )
724 {
725   auto i = this->m_Parameters.find( name );
726   if( i != this->m_Parameters.end( ) )
727   {
728     if( i->second.first == ( Self::Type )( _Enum ) )
729     {
730       std::stringstream str;
731       if( i->second.second != "" )
732         str << i->second.second << "#";
733       str << v;
734       i->second.second = str.str( );
735       this->Modified( );
736
737     } // fi
738
739   } // fi
740 }
741
742 // -------------------------------------------------------------------------
743 template< unsigned int _Enum >
744 void cpPlugins::BaseObjects::Parameters::
745 _ClearList( const std::string& name )
746 {
747   auto i = this->m_Parameters.find( name );
748   if( i != this->m_Parameters.end( ) )
749   {
750     if( i->second.first == ( Self::Type )( _Enum ) )
751     {
752       if( i->second.second != "" )
753       {
754         i->second.second = "";
755         this->Modified( );
756
757       } // fi
758
759     } // fi
760
761   } // fi
762 }
763
764 // eof - $RCSfile$