From 94eb6861708c5878691fc2b002decdc169693e6a Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 17 May 2016 11:28:52 -0500 Subject: [PATCH] ... --- lib/cpPlugins/Parameters.cxx | 233 +++++++++++++++++++++++++++++ lib/cpPlugins/Parameters.h | 156 ++++--------------- lib/cpPlugins/ParametersQtDialog.h | 2 +- 3 files changed, 262 insertions(+), 129 deletions(-) diff --git a/lib/cpPlugins/Parameters.cxx b/lib/cpPlugins/Parameters.cxx index c805327..4da3ec3 100644 --- a/lib/cpPlugins/Parameters.cxx +++ b/lib/cpPlugins/Parameters.cxx @@ -345,4 +345,237 @@ GetRawParameters( ) const return( this->m_Parameters ); } +// ------------------------------------------------------------------------- +#define cpPlugins_Parameters_Configure_Code( Y ) \ + void cpPlugins::Parameters::ConfigureAs##Y( const std::string& name ) \ + { this->_Configure< Y >( name ); } \ + bool cpPlugins::Parameters::Has##Y( const std::string& name ) const \ + { return( this->_Has< Y >( name ) ); } + +// ------------------------------------------------------------------------- +#define cpPlugins_Parameters_GetSet_Code( Y ) \ + cpPlugins::Parameters::T##Y \ + cpPlugins::Parameters::Get##Y( const std::string& name ) const \ + { return( this->_Get< T##Y, Y >( name ) ); } \ + void cpPlugins::Parameters::Set##Y( \ + const std::string& name, const T##Y& v \ + ) \ + { this->_Set< T##Y, Y >( name, v ); } + +// ------------------------------------------------------------------------- +#define cpPlugins_Parameters_GetSetList_Code( Y ) \ + std::vector< cpPlugins::Parameters::T##Y > \ + cpPlugins::Parameters::Get##Y##List( const std::string& name ) const \ + { return( this->_GetList< T##Y, Y##List >( name ) ); } \ + void cpPlugins::Parameters::AddTo##Y##List( \ + const std::string& name, const cpPlugins::Parameters::T##Y& v \ + ) \ + { this->_AddToList< T##Y, Y##List >( name, v ); } \ + void cpPlugins::Parameters::Clear##Y##List( const std::string& name ) \ + { this->_ClearList< Y##List >( name ); } + +// ------------------------------------------------------------------------- +cpPlugins_Parameters_Configure_Code( String ); +cpPlugins_Parameters_Configure_Code( Bool ); +cpPlugins_Parameters_Configure_Code( Int ); +cpPlugins_Parameters_Configure_Code( Uint ); +cpPlugins_Parameters_Configure_Code( Real ); +cpPlugins_Parameters_Configure_Code( OpenFileName ); +cpPlugins_Parameters_Configure_Code( SaveFileName ); +cpPlugins_Parameters_Configure_Code( PathName ); +cpPlugins_Parameters_Configure_Code( StringList ); +cpPlugins_Parameters_Configure_Code( BoolList ); +cpPlugins_Parameters_Configure_Code( IntList ); +cpPlugins_Parameters_Configure_Code( UintList ); +cpPlugins_Parameters_Configure_Code( RealList ); +cpPlugins_Parameters_Configure_Code( OpenFileNameList ); +cpPlugins_Parameters_Configure_Code( SaveFileNameList ); +cpPlugins_Parameters_Configure_Code( PathNameList ); +cpPlugins_Parameters_Configure_Code( Choices ); +cpPlugins_Parameters_GetSet_Code( Bool ); +cpPlugins_Parameters_GetSet_Code( Int ); +cpPlugins_Parameters_GetSet_Code( Uint ); +cpPlugins_Parameters_GetSet_Code( Real ); +cpPlugins_Parameters_GetSet_Code( OpenFileName ); +cpPlugins_Parameters_GetSet_Code( SaveFileName ); +cpPlugins_Parameters_GetSet_Code( PathName ); +cpPlugins_Parameters_GetSetList_Code( String ); +cpPlugins_Parameters_GetSetList_Code( Bool ); +cpPlugins_Parameters_GetSetList_Code( Int ); +cpPlugins_Parameters_GetSetList_Code( Uint ); +cpPlugins_Parameters_GetSetList_Code( Real ); +cpPlugins_Parameters_GetSetList_Code( OpenFileName ); +cpPlugins_Parameters_GetSetList_Code( SaveFileName ); +cpPlugins_Parameters_GetSetList_Code( PathName ); + +// ------------------------------------------------------------------------- +template< unsigned int _Enum > +void cpPlugins::Parameters:: +_Configure( const std::string& name ) +{ + this->m_Parameters[ name ] = TParameter( ( Self::Type )( _Enum ), "" ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _Enum > +bool cpPlugins::Parameters:: +_Has( const std::string& name ) const +{ + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + return( i->second.first == ( Self::Type )( _Enum ) ); + else + return( false ); +} + +// ------------------------------------------------------------------------- +template< class _Type, unsigned int _Enum > +_Type cpPlugins::Parameters:: +_Get( const std::string& name ) const +{ + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == ( Self::Type )( _Enum ) ) + { + if( typeid( _Type ) != typeid( std::string ) ) + { + std::istringstream tok_str( i->second.second ); + _Type v; + tok_str >> v; + return( v ); + } + else + { + const _Type* ptr = + reinterpret_cast< const _Type* >( &( i->second.second ) ); + return( *ptr ); + + } // fi + + } // fi + + } // fi + return( _Type( 0 ) ); +} + +// ------------------------------------------------------------------------- +template< class _Type, unsigned int _Enum > +void cpPlugins::Parameters:: +_Set( const std::string& name, const _Type& v ) +{ + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == ( Self::Type )( _Enum ) ) + { + if( typeid( _Type ) != typeid( std::string ) ) + { + std::stringstream str; + str << v; + if( i->second.second != str.str( ) ) + { + i->second.second = str.str( ); + this->Modified( ); + + } // fi + } + else + { + const std::string* str = reinterpret_cast< const std::string* >( &v ); + if( i->second.second != *str ) + { + i->second.second = *str; + this->Modified( ); + + } // fi + + } // fi + + } // fi + + } // fi + +} + +// ------------------------------------------------------------------------- +template< class _Type, unsigned int _Enum > +std::vector< _Type > cpPlugins::Parameters:: +_GetList( const std::string& name ) const +{ + std::vector< _Type > lst; + std::vector< std::string >* slst = + reinterpret_cast< std::vector< std::string >* >( &lst ); + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == ( Self::Type )( _Enum ) ) + { + std::vector< std::string > tokens; + cpPlugins::TokenizeString( tokens, i->second.second, "#" ); + for( auto t = tokens.begin( ); t != tokens.end( ); ++t ) + { + if( typeid( _Type ) != typeid( std::string ) ) + { + std::istringstream tok_str( *t ); + _Type v; + tok_str >> v; + lst.push_back( v ); + } + else + slst->push_back( *t ); + + } // rof + + } // fi + + } // fi + return( lst ); +} + +// ------------------------------------------------------------------------- +template< class _Type, unsigned int _Enum > +void cpPlugins::Parameters:: +_AddToList( const std::string& name, const _Type& v ) +{ + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == ( Self::Type )( _Enum ) ) + { + std::stringstream str; + if( i->second.second != "" ) + str << i->second.second << "#"; + str << v; + i->second.second = str.str( ); + this->Modified( ); + + } // fi + + } // fi +} + +// ------------------------------------------------------------------------- +template< unsigned int _Enum > +void cpPlugins::Parameters:: +_ClearList( const std::string& name ) +{ + auto i = this->m_Parameters.find( name ); + if( i != this->m_Parameters.end( ) ) + { + if( i->second.first == ( Self::Type )( _Enum ) ) + { + if( i->second.second != "" ) + { + i->second.second = ""; + this->Modified( ); + + } // fi + + } // fi + + } // fi +} + // eof - $RCSfile$ diff --git a/lib/cpPlugins/Parameters.h b/lib/cpPlugins/Parameters.h index 5393d03..dc0ea52 100644 --- a/lib/cpPlugins/Parameters.h +++ b/lib/cpPlugins/Parameters.h @@ -20,140 +20,19 @@ namespace tinyxml2 // ------------------------------------------------------------------------- #define cpPlugins_Parameters_Configure( Y ) \ - void ConfigureAs##Y( const std::string& name ) \ - { \ - this->m_Parameters[ name ] = TParameter( Self::Y, "" ); \ - this->Modified( ); \ - } \ - bool Has##Y( const std::string& name ) const \ - { \ - auto i = this->m_Parameters.find( name ); \ - if( i != this->m_Parameters.end( ) ) \ - return( i->second.first == Self::Y ); \ - else \ - return( false ); \ - } + void ConfigureAs##Y( const std::string& name ); \ + bool Has##Y( const std::string& name ) const // ------------------------------------------------------------------------- #define cpPlugins_Parameters_GetSet( Y ) \ - T##Y Get##Y( const std::string& name ) const \ - { \ - auto i = this->m_Parameters.find( name ); \ - if( i != this->m_Parameters.end( ) ) \ - { \ - if( i->second.first == Self::Y ) \ - { \ - if( typeid( T##Y ) != typeid( std::string ) ) \ - { \ - std::istringstream tok_str( i->second.second ); \ - T##Y v; \ - tok_str >> v; \ - return( v ); \ - } \ - else \ - { \ - const T##Y* ptr = \ - reinterpret_cast< const T##Y* >( \ - &( i->second.second ) \ - ); \ - return( *ptr ); \ - } \ - } \ - } \ - return( T##Y( 0 ) ); \ - } \ - void Set##Y( const std::string& name, const T##Y& v ) \ - { \ - auto i = this->m_Parameters.find( name ); \ - if( i != this->m_Parameters.end( ) ) \ - { \ - if( i->second.first == Self::Y ) \ - { \ - if( typeid( T##Y ) != typeid( std::string ) ) \ - { \ - std::stringstream str; \ - str << v; \ - if( i->second.second != str.str( ) ) \ - { \ - i->second.second = str.str( ); \ - this->Modified( ); \ - } \ - } \ - else \ - { \ - const std::string* str = \ - reinterpret_cast< const std::string* >( &v ); \ - if( i->second.second != *str ) \ - { \ - i->second.second = *str; \ - this->Modified( ); \ - } \ - } \ - } \ - } \ - } + T##Y Get##Y( const std::string& name ) const; \ + void Set##Y( const std::string& name, const T##Y& v ) // ------------------------------------------------------------------------- #define cpPlugins_Parameters_GetSetList( Y ) \ - std::vector< T##Y > Get##Y##List( const std::string& name ) const \ - { \ - std::vector< T##Y > lst; \ - std::vector< std::string >* slst = \ - reinterpret_cast< std::vector< std::string >* >( &lst ); \ - auto i = this->m_Parameters.find( name ); \ - if( i != this->m_Parameters.end( ) ) \ - { \ - if( i->second.first == Self::Y##List ) \ - { \ - std::istringstream str( i->second.second ); \ - std::string token; \ - while( std::getline( str, token, '#' ) ) \ - { \ - if( typeid( T##Y ) != typeid( std::string ) ) \ - { \ - std::istringstream tok_str( token ); \ - T##Y v; \ - tok_str >> v; \ - lst.push_back( v ); \ - } \ - else \ - slst->push_back( token ); \ - } \ - } \ - } \ - return( lst ); \ - } \ - void AddTo##Y##List( const std::string& name, const T##Y& v ) \ - { \ - auto i = this->m_Parameters.find( name ); \ - if( i != this->m_Parameters.end( ) ) \ - { \ - if( i->second.first == Self::Y##List ) \ - { \ - std::stringstream str; \ - if( i->second.second != "" ) \ - str << i->second.second << "#"; \ - str << v; \ - i->second.second = str.str( ); \ - this->Modified( ); \ - } \ - } \ - } \ - void Clear##Y##List( const std::string& name ) \ - { \ - auto i = this->m_Parameters.find( name ); \ - if( i != this->m_Parameters.end( ) ) \ - { \ - if( i->second.first == Self::Y##List ) \ - { \ - if( i->second.second != "" ) \ - { \ - i->second.second = ""; \ - this->Modified( ); \ - } \ - } \ - } \ - } + std::vector< T##Y > Get##Y##List( const std::string& name ) const; \ + void AddTo##Y##List( const std::string& name, const T##Y& v ); \ + void Clear##Y##List( const std::string& name ) namespace cpPlugins { @@ -290,6 +169,27 @@ namespace cpPlugins TParameters& GetRawParameters( ); const TParameters& GetRawParameters( ) const; + template< unsigned int _Enum > + inline void _Configure( const std::string& name ); + + template< unsigned int _Enum > + inline bool _Has( const std::string& name ) const; + + template< class _Type, unsigned int _Enum > + inline _Type _Get( const std::string& name ) const; + + template< class _Type, unsigned int _Enum > + inline void _Set( const std::string& name, const _Type& v ); + + template< class _Type, unsigned int _Enum > + inline std::vector< _Type > _GetList( const std::string& name ) const; + + template< class _Type, unsigned int _Enum > + inline void _AddToList( const std::string& name, const _Type& v ); + + template< unsigned int _Enum > + inline void _ClearList( const std::string& name ); + private: // Purposely not implemented Parameters( const Self& other ); diff --git a/lib/cpPlugins/ParametersQtDialog.h b/lib/cpPlugins/ParametersQtDialog.h index 8c76984..0d732d7 100644 --- a/lib/cpPlugins/ParametersQtDialog.h +++ b/lib/cpPlugins/ParametersQtDialog.h @@ -32,7 +32,7 @@ namespace cpPlugins virtual ~ParametersQtDialog( ); ProcessObject* getProcessObject( ) const; - bool setProcessObject( ProcessObject* obj ); + virtual bool setProcessObject( ProcessObject* obj ); virtual int exec( ); -- 2.47.1