]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Parameters.hxx
9afcc3224184ee2326b8128f3fb86da890d60126
[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( Bool );
27 cpPlugins_Interface_Parameters_SetListMacro( Int );
28 cpPlugins_Interface_Parameters_SetListMacro( Uint );
29 cpPlugins_Interface_Parameters_SetListMacro( Real );
30 cpPlugins_Interface_Parameters_SetListMacro( Index );
31 cpPlugins_Interface_Parameters_SetListMacro( Point );
32
33 // -------------------------------------------------------------------------
34 #define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \
35   template< class T >                                                   \
36   T cpPlugins::Interface::Parameters::                                  \
37   GetValueAs##NAME( const TString& name ) const                         \
38   {                                                                     \
39     T val;                                                              \
40     TParameters::iterator pIt = this->m_Parameters.find( name );        \
41     if( pIt != this->m_Parameters.end( ) )                              \
42     {                                                                   \
43       if( pIt->second.first == Self::NAME )                             \
44       {                                                                 \
45         std::istringstream ss( pIt->second.second );                    \
46         std::string token;                                              \
47         unsigned int i = 0;                                             \
48         while( std::getline( ss, token, ',' ) )                         \
49         {                                                               \
50          if( token != "" )                                              \
51             val[ i++ ] = TYPE( std::atof( token.c_str( ) ) );           \
52                                                                         \
53         }                                                               \
54       }                                                                 \
55     }                                                                   \
56     return( val );                                                      \
57   }
58
59 cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long );
60 cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double );
61
62 // -------------------------------------------------------------------------
63 template< class I >
64 void cpPlugins::Interface::Parameters::
65 GetValueAsIndexList( std::vector< I >& lst, const TString& name ) const
66 {
67   lst.clear( );
68   TParameters::iterator pIt = this->m_Parameters.find( name );
69   if( pIt == this->m_Parameters.end( ) )
70     return;
71   if( pIt->second.first != Self::IndexList )
72     return;
73
74   // TODO:
75   std::cerr << "TODO GetValueAsIndexList" << std::endl;
76 }
77
78 // -------------------------------------------------------------------------
79 template< class P >
80 void cpPlugins::Interface::Parameters::
81 GetValueAsPointList( std::vector< P >& lst, const TString& name ) const
82 {
83   lst.clear( );
84   TParameters::iterator pIt = this->m_Parameters.find( name );
85   if( pIt == this->m_Parameters.end( ) )
86     return;
87   if( pIt->second.first != Self::PointList )
88     return;
89
90   // TODO:
91   std::cerr << "TODO GetValueAsPointList" << std::endl;
92 }
93
94 #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
95
96 // eof - $RCSfile$