From a3fd8b70054c862446ed7e3fabf2fd24cfe2ad92 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 26 Jan 2015 18:04:42 -0500 Subject: [PATCH] Parameters improved --- appli/examples/CMakeLists.txt | 1 + appli/examples/example_TestParameters.cxx | 3 + lib/cpPlugins/Interface/Parameters.cxx | 20 ++++++ lib/cpPlugins/Interface/Parameters.h | 13 ++++ lib/cpPlugins/Interface/Parameters.hxx | 78 ++++++++--------------- 5 files changed, 64 insertions(+), 51 deletions(-) create mode 100644 appli/examples/example_TestParameters.cxx diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index e210337..3a79578 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -5,6 +5,7 @@ SET( EXAMPLES_PROGRAMS + example_TestParameters example_LoadPlugins example_ReadWriteImage example_ReadImageSeriesWriteImage diff --git a/appli/examples/example_TestParameters.cxx b/appli/examples/example_TestParameters.cxx new file mode 100644 index 0000000..58711af --- /dev/null +++ b/appli/examples/example_TestParameters.cxx @@ -0,0 +1,3 @@ +#error ACA VOY + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx index a42582c..b8d358b 100644 --- a/lib/cpPlugins/Interface/Parameters.cxx +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -19,6 +19,7 @@ } cpPlugins_Interface_Parameters_SetMacro( String ); +cpPlugins_Interface_Parameters_SetMacro( Bool ); cpPlugins_Interface_Parameters_SetMacro( Int ); cpPlugins_Interface_Parameters_SetMacro( Uint ); cpPlugins_Interface_Parameters_SetMacro( Real ); @@ -127,6 +128,19 @@ GetValueAsString( const TString& name ) const return( pIt->second.second ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +TBool cpPlugins::Interface::Parameters:: +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 ) + return( TBool( false ) ); + return( TBool( std::atoi( pIt->second.second.c_str( ) ) == 1 ) ); +} + // ------------------------------------------------------------------------- cpPlugins::Interface::Parameters:: TInt cpPlugins::Interface::Parameters:: @@ -174,6 +188,12 @@ GetValueAsStringList( { } +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +GetValueAsBoolList( std::vector< TBool >& lst, const TString& name ) const +{ +} + // ------------------------------------------------------------------------- void cpPlugins::Interface::Parameters:: GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const diff --git a/lib/cpPlugins/Interface/Parameters.h b/lib/cpPlugins/Interface/Parameters.h index 9ad706e..bbf9dfc 100644 --- a/lib/cpPlugins/Interface/Parameters.h +++ b/lib/cpPlugins/Interface/Parameters.h @@ -19,12 +19,14 @@ namespace cpPlugins enum Type { String = 0, + Bool, Int, Uint, Real, Index, Point, StringList, + BoolList, IntList, UintList, RealList, @@ -33,6 +35,7 @@ namespace cpPlugins NoType }; + typedef bool TBool; typedef long TInt; typedef unsigned long TUint; typedef double TReal; @@ -51,6 +54,7 @@ namespace cpPlugins void Clear( ); void Configure( const Self::Type& type, const TString& name ); void SetValueAsString( const TString& name, const TString& v ); + void SetValueAsBool( const TString& name, const TBool& v ); void SetValueAsInt( const TString& name, const TInt& v ); void SetValueAsUint( const TString& name, const TUint& v ); void SetValueAsReal( const TString& name, const TReal& v ); @@ -62,6 +66,11 @@ namespace cpPlugins const TString& name, const I& b, const I& e ); + template< class I > + void SetValueAsBoolList( + const TString& name, const I& b, const I& e + ); + template< class I > void SetValueAsIntList( const TString& name, const I& b, const I& e @@ -90,6 +99,7 @@ namespace cpPlugins std::vector< TString > GetParameters( ) const; Self::Type GetParameterType( const TString& name ) const; const TString& GetValueAsString( const TString& name ) const; + TBool GetValueAsBool( const TString& name ) const; TInt GetValueAsInt( const TString& name ) const; TUint GetValueAsUint( const TString& name ) const; TReal GetValueAsReal( const TString& name ) const; @@ -103,6 +113,9 @@ namespace cpPlugins void GetValueAsStringList( std::vector< TString >& lst, const TString& name ) const; + void GetValueAsBoolList( + std::vector< TBool >& lst, const TString& name + ) const; void GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const; diff --git a/lib/cpPlugins/Interface/Parameters.hxx b/lib/cpPlugins/Interface/Parameters.hxx index 0a73b37..9afcc32 100644 --- a/lib/cpPlugins/Interface/Parameters.hxx +++ b/lib/cpPlugins/Interface/Parameters.hxx @@ -23,6 +23,7 @@ } 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 ); @@ -30,58 +31,33 @@ 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 +#define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \ + template< class T > \ + T cpPlugins::Interface::Parameters:: \ + GetValueAs##NAME( const TString& name ) const \ + { \ + T val; \ + TParameters::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 ); \ + } - } // fi - return( pnt ); -} +cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long ); +cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double ); // ------------------------------------------------------------------------- template< class I > -- 2.47.1