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