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