]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.hxx
More on parameters simplification
[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 <sstream>
6
7 // -------------------------------------------------------------------------
8 #define cpPlugins_Interface_Parameters_SetListMacro( TYPE )             \
9   template< class I >                                                   \
10   void cpPlugins::Interface::Parameters::                               \
11   SetValueAs##TYPE##List( const TString& name, const I& b, const I& e ) \
12   {                                                                     \
13     TParameters::iterator pIt = this->m_Parameters.find( name );        \
14     if( pIt == this->m_Parameters.end( ) )                              \
15       return;                                                           \
16     if( pIt->second.first != Self::TYPE##List )                         \
17       return;                                                           \
18     std::stringstream ss;                                               \
19     for( I i = b; i != e; ++i )                                         \
20       ss << *i << ":";                                                  \
21     pIt->second = ss.str( );                                            \
22   }
23
24 cpPlugins_Interface_Parameters_SetListMacro( String );
25 cpPlugins_Interface_Parameters_SetListMacro( Int );
26 cpPlugins_Interface_Parameters_SetListMacro( Uint );
27 cpPlugins_Interface_Parameters_SetListMacro( Real );
28 cpPlugins_Interface_Parameters_SetListMacro( Index );
29 cpPlugins_Interface_Parameters_SetListMacro( Point );
30
31 // -------------------------------------------------------------------------
32 template< class I >
33 I cpPlugins::Interface::Parameters::
34 GetValueAsIndex( const TString& name ) const
35 {
36   I idx;
37   TParameters::iterator pIt = this->m_Parameters.find( name );
38   if( pIt != this->m_Parameters.end( ) )
39   {
40     if( pIt->second.first == Self::Index )
41     {
42       std::istringstream ss( pIt->second.second );
43       std::string token;
44       unsigned int i = 0;
45       while( std::getline( ss, token, ',' ) )
46       {
47         if( token != "" )
48           idx[ i++ ] = std::atoi( token.c_str( ) );
49
50       } // elihw
51
52     } // fi
53
54   } // fi
55   return( idx );
56 }
57
58 // -------------------------------------------------------------------------
59 template< class P >
60 P cpPlugins::Interface::Parameters::
61 GetValueAsPoint( const TString& name ) const
62 {
63   P pnt;
64   TParameters::iterator pIt = this->m_Parameters.find( name );
65   if( pIt != this->m_Parameters.end( ) )
66   {
67     if( pIt->second.first == Self::Point )
68     {
69       std::istringstream ss( pIt->second.second );
70       std::string token;
71       unsigned int i = 0;
72       while( std::getline( ss, token, ',' ) )
73       {
74         if( token != "" )
75           pnt[ i++ ] = std::atof( token.c_str( ) );
76
77       } // elihw
78
79     } // fi
80
81   } // fi
82   return( pnt );
83 }
84
85 // -------------------------------------------------------------------------
86 template< class I >
87 void cpPlugins::Interface::Parameters::
88 GetValueAsIndexList( std::vector< I >& lst, const TString& name ) const
89 {
90   lst.clear( );
91   TParameters::iterator pIt = this->m_Parameters.find( name );
92   if( pIt == this->m_Parameters.end( ) )
93     return;
94   if( pIt->second.first != Self::IndexList )
95     return;
96
97   // TODO:
98 }
99
100 // -------------------------------------------------------------------------
101 template< class P >
102 void cpPlugins::Interface::Parameters::
103 GetValueAsPointList( std::vector< P >& lst, const TString& name ) const
104 {
105   lst.clear( );
106   TParameters::iterator pIt = this->m_Parameters.find( name );
107   if( pIt == this->m_Parameters.end( ) )
108     return;
109   if( pIt->second.first != Self::PointList )
110     return;
111
112   // TODO:
113 }
114
115 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
116
117 // eof - $RCSfile$