]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.hxx
Parameters finished
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.hxx
1 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
2 #define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
3
4 #include <cstdlib>
5 #include <iostream>
6 #include <sstream>
7
8 // -------------------------------------------------------------------------
9 #define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \
10   template< class T >                                                   \
11   T cpPlugins::Interface::Parameters::                                  \
12   GetValueAs##NAME( const TString& name ) const                         \
13   {                                                                     \
14     T val;                                                              \
15     TParameters::const_iterator pIt = this->m_Parameters.find( name );  \
16     if( pIt != this->m_Parameters.end( ) )                              \
17     {                                                                   \
18       if( pIt->second.first == Self::NAME )                             \
19       {                                                                 \
20         std::istringstream ss( pIt->second.second );                    \
21         std::string token;                                              \
22         unsigned int i = 0;                                             \
23         while( std::getline( ss, token, ',' ) )                         \
24         {                                                               \
25           if( token != "" )                                             \
26             val[ i++ ] = TYPE( std::atof( token.c_str( ) ) );           \
27         }                                                               \
28       }                                                                 \
29     }                                                                   \
30     return( val );                                                      \
31   }
32
33 cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long );
34 cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double );
35
36 // -------------------------------------------------------------------------
37 template< class I >
38 void cpPlugins::Interface::Parameters::
39 GetValueAsIndexList( std::vector< I >& lst, const TString& name ) const
40 {
41   lst.clear( );
42   TParameters::const_iterator pIt = this->m_Parameters.find( name );
43   if( pIt == this->m_Parameters.end( ) )
44     return;
45   if( pIt->second.first != Self::IndexList )
46     return;
47
48   std::istringstream ss( pIt->second.second );
49   std::string token;
50   while( std::getline( ss, token, ':' ) )
51   {
52     if( token != "" )
53     {
54       std::istringstream ts( token );
55       std::string text;
56       unsigned int i = 0;
57       I idx;
58       while( std::getline( ts, text, ',' ) )
59         if( text != "" )
60           idx[ i++ ] = std::atoi( text.c_str( ) );
61       lst.push_back( idx );
62
63     } // fi
64
65   } // elihw
66 }
67
68 // -------------------------------------------------------------------------
69 template< class P >
70 void cpPlugins::Interface::Parameters::
71 GetValueAsPointList( std::vector< P >& lst, const TString& name ) const
72 {
73   lst.clear( );
74   TParameters::const_iterator pIt = this->m_Parameters.find( name );
75   if( pIt == this->m_Parameters.end( ) )
76     return;
77   if( pIt->second.first != Self::PointList )
78     return;
79
80   std::istringstream ss( pIt->second.second );
81   std::string token;
82   while( std::getline( ss, token, ':' ) )
83   {
84     if( token != "" )
85     {
86       std::istringstream ts( token );
87       std::string text;
88       unsigned int i = 0;
89       P pnt;
90       while( std::getline( ts, text, ',' ) )
91         if( text != "" )
92           pnt[ i++ ] = std::atof( text.c_str( ) );
93       lst.push_back( pnt );
94
95     } // fi
96
97   } // elihw
98 }
99
100 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
101
102 // eof - $RCSfile$