X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParameters.hxx;h=e47b799c7616e2c85ea7148bb4eb4fe2956e22a4;hb=7c7bc497af96e7b5845be9a2fc277036ec752be9;hp=f0c3a27e8d99b0ab17e95af7a02f33fc35a946e6;hpb=d33ff8f25fd903eca28c2f088adc8f68e7738135;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Parameters.hxx b/lib/cpPlugins/Interface/Parameters.hxx index f0c3a27..e47b799 100644 --- a/lib/cpPlugins/Interface/Parameters.hxx +++ b/lib/cpPlugins/Interface/Parameters.hxx @@ -2,85 +2,36 @@ #define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ #include +#include #include // ------------------------------------------------------------------------- -#define cpPlugins_Interface_Parameters_SetListMacro( TYPE ) \ - template< class I > \ - void cpPlugins::Interface::Parameters:: \ - SetValueAs##TYPE##List( const TString& name, const I& b, const I& e ) \ +#define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \ + template< class T > \ + T cpPlugins::Interface::Parameters:: \ + GetValueAs##NAME( const TString& name ) const \ { \ - TParameters::iterator pIt = this->m_Parameters.find( name ); \ - if( pIt == this->m_Parameters.end( ) ) \ - return; \ - if( pIt->second.first != Self::TYPE##List ) \ - return; \ - std::stringstream ss; \ - for( I i = b; i != e; ++i ) \ - ss << *i << ":"; \ - pIt->second = ss.str( ); \ + T val; \ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); \ + if( pIt != this->m_Parameters.end( ) ) \ + { \ + if( pIt->second.first == Self::NAME ) \ + { \ + std::istringstream ss( pIt->second.second ); \ + std::string token; \ + unsigned int i = 0; \ + while( std::getline( ss, token, ',' ) ) \ + { \ + if( token != "" ) \ + val[ i++ ] = TYPE( std::atof( token.c_str( ) ) ); \ + } \ + } \ + } \ + return( val ); \ } -cpPlugins_Interface_Parameters_SetListMacro( String ); -cpPlugins_Interface_Parameters_SetListMacro( Int ); -cpPlugins_Interface_Parameters_SetListMacro( Uint ); -cpPlugins_Interface_Parameters_SetListMacro( Real ); -cpPlugins_Interface_Parameters_SetListMacro( Index ); -cpPlugins_Interface_Parameters_SetListMacro( Point ); - -// ------------------------------------------------------------------------- -template< class I > -I cpPlugins::Interface::Parameters:: -GetValueAsIndex( const TString& name ) const -{ - I idx; - TParameters::iterator pIt = this->m_Parameters.find( name ); - if( pIt != this->m_Parameters.end( ) ) - { - if( pIt->second.first == Self::Index ) - { - std::istringstream ss( pIt->second.second ); - std::string token; - unsigned int i = 0; - while( std::getline( ss, token, ',' ) ) - { - if( token != "" ) - idx[ i++ ] = std::atoi( token.c_str( ) ); - - } // elihw - - } // fi - - } // fi - return( idx ); -} - -// ------------------------------------------------------------------------- -template< class P > -P cpPlugins::Interface::Parameters:: -GetValueAsPoint( const TString& name ) const -{ - P pnt; - TParameters::iterator pIt = this->m_Parameters.find( name ); - if( pIt != this->m_Parameters.end( ) ) - { - if( pIt->second.first == Self::Point ) - { - std::istringstream ss( pIt->second.second ); - std::string token; - unsigned int i = 0; - while( std::getline( ss, token, ',' ) ) - { - if( token != "" ) - pnt[ i++ ] = std::atof( token.c_str( ) ); - - } // elihw - - } // fi - - } // fi - return( pnt ); -} +cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long ); +cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double ); // ------------------------------------------------------------------------- template< class I > @@ -88,13 +39,30 @@ void cpPlugins::Interface::Parameters:: GetValueAsIndexList( std::vector< I >& lst, const TString& name ) const { lst.clear( ); - TParameters::iterator pIt = this->m_Parameters.find( name ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); if( pIt == this->m_Parameters.end( ) ) return; if( pIt->second.first != Self::IndexList ) return; - // TODO: + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, ':' ) ) + { + if( token != "" ) + { + std::istringstream ts( token ); + std::string text; + unsigned int i = 0; + I idx; + while( std::getline( ts, text, ',' ) ) + if( text != "" ) + idx[ i++ ] = std::atoi( text.c_str( ) ); + lst.push_back( idx ); + + } // fi + + } // elihw } // ------------------------------------------------------------------------- @@ -103,13 +71,30 @@ void cpPlugins::Interface::Parameters:: GetValueAsPointList( std::vector< P >& lst, const TString& name ) const { lst.clear( ); - TParameters::iterator pIt = this->m_Parameters.find( name ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); if( pIt == this->m_Parameters.end( ) ) return; if( pIt->second.first != Self::PointList ) return; - // TODO: + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, ':' ) ) + { + if( token != "" ) + { + std::istringstream ts( token ); + std::string text; + unsigned int i = 0; + P pnt; + while( std::getline( ts, text, ',' ) ) + if( text != "" ) + pnt[ i++ ] = std::atof( text.c_str( ) ); + lst.push_back( pnt ); + + } // fi + + } // elihw } #endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__