X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FParameters.cxx;h=38a5f14af0b02729b9298d1290265e586cb20a51;hb=7c7bc497af96e7b5845be9a2fc277036ec752be9;hp=b8d358b5103891ed27eed7bf590cfd50865604da;hpb=a3fd8b70054c862446ed7e3fabf2fd24cfe2ad92;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx index b8d358b..38a5f14 100644 --- a/lib/cpPlugins/Interface/Parameters.cxx +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -43,9 +43,75 @@ cpPlugins_Interface_Parameters_SetMacro( Real ); pIt->second.second = ss.str( ); \ } -cpPlugins_Interface_Parameters_SetArrayMacro( Index, long ); +cpPlugins_Interface_Parameters_SetArrayMacro( Index, int ); cpPlugins_Interface_Parameters_SetArrayMacro( Point, double ); +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_Parameters_SetListMacro( TYPE ) \ + void cpPlugins::Interface::Parameters:: \ + AddValueTo##TYPE##List( const TString& name, const T##TYPE& v ) \ + { \ + 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; \ + ss << pIt->second.second << v << "#"; \ + pIt->second.second = ss.str( ); \ + } + +cpPlugins_Interface_Parameters_SetListMacro( String ); +cpPlugins_Interface_Parameters_SetListMacro( Bool ); +cpPlugins_Interface_Parameters_SetListMacro( Int ); +cpPlugins_Interface_Parameters_SetListMacro( Uint ); +cpPlugins_Interface_Parameters_SetListMacro( Real ); + +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_Parameters_SetArrayListMacro( TYPE, ATYPE ) \ + void cpPlugins::Interface::Parameters:: \ + AddValueTo##TYPE##List( const TString& name, const TUint& n, ... ) \ + { \ + TParameters::iterator pIt = this->m_Parameters.find( name ); \ + if( pIt == this->m_Parameters.end( ) ) \ + return; \ + if( pIt->second.first != Self::TYPE##List ) \ + return; \ + va_list v_lst; \ + va_start( v_lst, n ); \ + std::stringstream ss; \ + ss << pIt->second.second; \ + for( TUint i = 0; i < n; ++i ) \ + ss << va_arg( v_lst, ATYPE ) << ","; \ + va_end( v_lst ); \ + ss << "#"; \ + pIt->second.second = ss.str( ); \ + } + +cpPlugins_Interface_Parameters_SetArrayListMacro( Index, int ); +cpPlugins_Interface_Parameters_SetArrayListMacro( Point, double ); + +// ------------------------------------------------------------------------- +#define cpPlugins_Interface_Parameters_ClearListMacro( TYPE ) \ + void cpPlugins::Interface::Parameters:: \ + Clear##TYPE##List( const TString& name ) \ + { \ + TParameters::iterator pIt = this->m_Parameters.find( name ); \ + if( pIt == this->m_Parameters.end( ) ) \ + return; \ + if( pIt->second.first != Self::TYPE##List ) \ + return; \ + pIt->second.second = ""; \ + } + +cpPlugins_Interface_Parameters_ClearListMacro( String ); +cpPlugins_Interface_Parameters_ClearListMacro( Bool ); +cpPlugins_Interface_Parameters_ClearListMacro( Int ); +cpPlugins_Interface_Parameters_ClearListMacro( Uint ); +cpPlugins_Interface_Parameters_ClearListMacro( Real ); +cpPlugins_Interface_Parameters_ClearListMacro( Index ); +cpPlugins_Interface_Parameters_ClearListMacro( Point ); + // ------------------------------------------------------------------------- cpPlugins::Interface::Parameters:: Parameters( ) @@ -113,6 +179,18 @@ GetParameterType( const TString& name ) const return( pIt->second.first ); } +// ------------------------------------------------------------------------- +const cpPlugins::Interface::Parameters:: +TString& cpPlugins::Interface::Parameters:: +GetRawValue( const TString& name ) const +{ + static const TString null_str = ""; + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( null_str ); + return( pIt->second.second ); +} + // ------------------------------------------------------------------------- const cpPlugins::Interface::Parameters:: TString& cpPlugins::Interface::Parameters:: @@ -136,7 +214,7 @@ GetValueAsBool( const TString& name ) const TParameters::const_iterator pIt = this->m_Parameters.find( name ); if( pIt == this->m_Parameters.end( ) ) return( TBool( false ) ); - if( pIt->second.first != Self::Int ) + if( pIt->second.first != Self::Bool ) return( TBool( false ) ); return( TBool( std::atoi( pIt->second.second.c_str( ) ) == 1 ) ); } @@ -186,30 +264,230 @@ GetValueAsStringList( std::vector< TString >& lst, const TString& name ) const { + lst.clear( ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::StringList ) + return; + + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, '#' ) ) + if( token != "" ) + lst.push_back( token ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: GetValueAsBoolList( std::vector< TBool >& lst, const TString& name ) const { + lst.clear( ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::BoolList ) + return; + + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, '#' ) ) + if( token != "" ) + lst.push_back( TBool( std::atoi( token.c_str( ) ) == 1 ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const { + lst.clear( ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::IntList ) + return; + + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, '#' ) ) + if( token != "" ) + lst.push_back( TInt( std::atoi( token.c_str( ) ) ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: GetValueAsUintList( std::vector< TUint >& lst, const TString& name ) const { + lst.clear( ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::UintList ) + return; + + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, '#' ) ) + if( token != "" ) + lst.push_back( TUint( std::atoi( token.c_str( ) ) ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: GetValueAsRealList( std::vector< TReal >& lst, const TString& name ) const { + lst.clear( ); + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::RealList ) + return; + + std::istringstream ss( pIt->second.second ); + std::string token; + while( std::getline( ss, token, '#' ) ) + if( token != "" ) + lst.push_back( TReal( std::atof( token.c_str( ) ) ) ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasStringValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::String ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasBoolValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::Bool ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasIntValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::Int ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasUintValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::Uint ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasRealValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::Real ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasIndexValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::Index ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasPointValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::Point ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasStringListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::StringList ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasBoolListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::BoolList ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasIntListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::IntList ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasUintListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::UintList ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasRealListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::RealList ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasIndexListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::IndexList ); + return( false ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::Parameters:: +HasPointListValue( const TString& name ) const +{ + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt != this->m_Parameters.end( ) ) + return( pIt->second.first == Self::PointList ); + return( false ); } // eof - $RCSfile$