From: Leonardo Florez-Valencia Date: Mon, 29 Dec 2014 21:52:51 +0000 (+0100) Subject: Simplified parameters X-Git-Tag: v0.1~426 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=320afa917228a86723477e0b60a7cd6ce87e5fe9;p=cpPlugins.git Simplified parameters --- diff --git a/lib/cpPlugins/Interface/Parameters.cxx b/lib/cpPlugins/Interface/Parameters.cxx new file mode 100644 index 0000000..dd8cece --- /dev/null +++ b/lib/cpPlugins/Interface/Parameters.cxx @@ -0,0 +1,228 @@ +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +Parameters( ) +{ + this->m_Parameters.clear( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +Parameters( const Self& other ) +{ + this->m_Parameters = other.m_Parameters; +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +~Parameters( ) +{ + this->m_Parameters.clear( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +Self& cpPlugins::Interface::Parameters:: +operator=( const Self& other ) +{ + this->m_Parameters = other.m_Parameters; + return( *this ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +Configure( const Self::Type& type, const std::string& name ) +{ + this->m_Parameters[ name ] = TParameter( type, "" ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +SetValueAsString( const std::string& name, const std::string& v ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::String ) + return; + + pIt->second.second = v; +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +SetValueAsInt( const std::string& name, const TInt& v ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::Int ) + return; + + std::stringstream ss; + ss << v; + pIt->second.second = ss.str( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +SetValueAsUint( const std::string& name, const TUint& v ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::Uint ) + return; + + std::stringstream ss; + ss << v; + pIt->second.second = ss.str( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +SetValueAsReal( const std::string& name, const TReal& v ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::Real ) + return; + + std::stringstream ss; + ss << v; + pIt->second.second = ss.str( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +SetValueAsIndex( const std::string& name, const TUint& n, ... ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::Index ) + return; + + va_list v_lst; + va_start( v_lst, n ); + + std::stringstream ss; + for( TUint i = 0; i < n; ++i ) + ss << va_arg( v_lst, long ) << ":"; + va_end( v_lst ); + + pIt->second.second = ss.str( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +SetValueAsPoint( const std::string& name, const TUint& n, ... ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::Point ) + return; + + va_list v_lst; + va_start( v_lst, n ); + + std::stringstream ss; + for( TUint i = 0; i < n; ++i ) + ss << va_arg( v_lst, double ) << ":"; + va_end( v_lst ); + + pIt->second.second = ss.str( ); +} + +// ------------------------------------------------------------------------- +const std::string& cpPlugins::Interface::Parameters:: +GetValueAsString( const std::string& name ) const +{ + static const std::string null_str = ""; + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( null_str ); + if( pIt->second.first != Self::String ) + return( null_str ); + + return( pIt->second.second ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +TInt cpPlugins::Interface::Parameters:: +GetValueAsInt( const std::string& name ) const +{ + static const std::string null_str = ""; + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( TInt( 0 ) ); + if( pIt->second.first != Self::Int ) + return( TInt( 0 ) ); + + return( std::atoi( pIt->second.second.c_str( ) ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +TUint cpPlugins::Interface::Parameters:: +GetValueAsUint( const std::string& name ) const +{ + static const std::string null_str = ""; + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( TUint( 0 ) ); + if( pIt->second.first != Self::Uint ) + return( TUint( 0 ) ); + + return( std::atoi( pIt->second.second.c_str( ) ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::Parameters:: +TReal cpPlugins::Interface::Parameters:: +GetValueAsReal( const std::string& name ) const +{ + static const std::string null_str = ""; + TParameters::const_iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( TReal( 0 ) ); + if( pIt->second.first != Self::Real ) + return( TReal( 0 ) ); + + return( std::atof( pIt->second.second.c_str( ) ) ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +GetValueAsStringList( + std::vector< std::string >& lst, const std::string& name + ) const +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +GetValueAsIntList( std::vector< TInt >& lst, const std::string& name ) const +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +GetValueAsUintList( std::vector< TUint >& lst, const std::string& name ) const +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::Parameters:: +GetValueAsRealList( std::vector< TReal >& lst, const std::string& name ) const +{ +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Parameters.h b/lib/cpPlugins/Interface/Parameters.h new file mode 100644 index 0000000..a806ee7 --- /dev/null +++ b/lib/cpPlugins/Interface/Parameters.h @@ -0,0 +1,133 @@ +#ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__ +#define __CPPLUGINS__INTERFACE__PARAMETERS__H__ + +#include +#include +#include + +namespace cpPlugins +{ + namespace Interface + { + /** + */ + class Parameters + { + public: + typedef Parameters Self; + + enum Type + { + String = 0, + Int, + Uint, + Real, + Index, + Point, + StringList, + IntList, + UintList, + RealList, + IndexList, + PointList + }; + + typedef std::pair< Self::Type, std::string > TParameter; + typedef std::map< std::string, TParameter > TParameters; + typedef long TInt; + typedef unsigned long TUint; + typedef double TReal; + + public: + Parameters( ); + Parameters( const Self& other ); + virtual ~Parameters( ); + + Self& operator=( const Self& other ); + + void Configure( const Self::Type& type, const std::string& name ); + void SetValueAsString( const std::string& name, const std::string& v ); + void SetValueAsInt( const std::string& name, const TInt& v ); + void SetValueAsUint( const std::string& name, const TUint& v ); + void SetValueAsReal( const std::string& name, const TReal& v ); + void SetValueAsIndex( const std::string& name, const TUint& n, ... ); + void SetValueAsPoint( const std::string& name, const TUint& n, ... ); + + template< class I > + void SetValueAsStringList( + const std::string& name, const I& b, const I& e + ); + + template< class I > + void SetValueAsIntList( + const std::string& name, const I& b, const I& e + ); + + template< class I > + void SetValueAsUintList( + const std::string& name, const I& b, const I& e + ); + + template< class I > + void SetValueAsRealList( + const std::string& name, const I& b, const I& e + ); + + template< class I > + void SetValueAsIndexList( + const std::string& name, const I& b, const I& e + ); + + template< class I > + void SetValueAsPointList( + const std::string& name, const I& b, const I& e + ); + + const std::string& GetValueAsString( const std::string& name ) const; + TInt GetValueAsInt( const std::string& name ) const; + TUint GetValueAsUint( const std::string& name ) const; + TReal GetValueAsReal( const std::string& name ) const; + + template< class I > + I GetValueAsIndex( const std::string& name ) const; + + template< class P > + P GetValueAsPoint( const std::string& name ) const; + + void GetValueAsStringList( + std::vector< std::string >& lst, const std::string& name + ) const; + void GetValueAsIntList( + std::vector< TInt >& lst, const std::string& name + ) const; + void GetValueAsUintList( + std::vector< TUint >& lst, const std::string& name + ) const; + void GetValueAsRealList( + std::vector< TReal >& lst, const std::string& name + ) const; + + template< class I > + void GetValueAsIndexList( + std::vector< I >& lst, const std::string& name + ) const; + + template< class P > + void GetValueAsPointList( + std::vector< P >& lst, const std::string& name + ) const; + + + protected: + TParameters m_Parameters; + }; + + } // ecapseman + +} // ecapseman + +#include + +#endif // __CPPLUGINS__INTERFACE__PARAMETERS__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/Parameters.hxx b/lib/cpPlugins/Interface/Parameters.hxx new file mode 100644 index 0000000..ac30bc9 --- /dev/null +++ b/lib/cpPlugins/Interface/Parameters.hxx @@ -0,0 +1,152 @@ +#ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ +#define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ + +#include + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +SetValueAsStringList( const std::string& name, const I& b, const I& e ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::StringList ) + return; + + std::stringstream ss; + for( I i = b; i != e; ++i ) + ss << *i << ":"; + pIt->second = ss.str( ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +SetValueAsIntList( const std::string& name, const I& b, const I& e ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::IntList ) + return; + + std::stringstream ss; + for( I i = b; i != e; ++i ) + ss << *i << ":"; + pIt->second = ss.str( ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +SetValueAsUintList( const std::string& name, const I& b, const I& e ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::UintList ) + return; + + std::stringstream ss; + for( I i = b; i != e; ++i ) + ss << *i << ":"; + pIt->second = ss.str( ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +SetValueAsRealList( const std::string& name, const I& b, const I& e ) +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::RealList ) + return; + + std::stringstream ss; + for( I i = b; i != e; ++i ) + ss << *i << ":"; + pIt->second = ss.str( ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +SetValueAsIndexList( const std::string& name, const I& b, const I& e ) +{ + // TODO +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +SetValueAsPointList( const std::string& name, const I& b, const I& e ) +{ + // TODO +} + +// ------------------------------------------------------------------------- +template< class I > +I cpPlugins::Interface::Parameters:: +GetValueAsIndex( const std::string& name ) const +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( I( ) ); + if( pIt->second.first != Self::Index ) + return( I( ) ); + + // TODO: + return( I( ) ); +} + +// ------------------------------------------------------------------------- +template< class P > +P cpPlugins::Interface::Parameters:: +GetValueAsPoint( const std::string& name ) const +{ + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return( P( ) ); + if( pIt->second.first != Self::Point ) + return( P( ) ); + + // TODO: + return( P( ) ); +} + +// ------------------------------------------------------------------------- +template< class I > +void cpPlugins::Interface::Parameters:: +GetValueAsIndexList( std::vector< I >& lst, const std::string& name ) const +{ + lst.clear( ); + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::IndexList ) + return; + + // TODO: +} + +// ------------------------------------------------------------------------- +template< class P > +void cpPlugins::Interface::Parameters:: +GetValueAsPointList( std::vector< P >& lst, const std::string& name ) const +{ + lst.clear( ); + TParameters::iterator pIt = this->m_Parameters.find( name ); + if( pIt == this->m_Parameters.end( ) ) + return; + if( pIt->second.first != Self::PointList ) + return; + + // TODO: +} + +#endif // __CPPLUGINS__INTERFACE__PARAMETERS__HXX__ + +// eof - $RCSfile$