#ifndef __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
#define __CPPLUGINS__INTERFACE__PARAMETERS__HXX__
+#include <cstdlib>
+#include <iostream>
#include <sstream>
// -------------------------------------------------------------------------
-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( ) );
-}
+#define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \
+ template< class T > \
+ T cpPlugins::Interface::Parameters:: \
+ GetValueAs##NAME( const TString& name ) const \
+ { \
+ 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_SetIndexOrPointMacro( Index, long );
+cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double );
// -------------------------------------------------------------------------
template< class I >
void cpPlugins::Interface::Parameters::
-GetValueAsIndexList( std::vector< I >& lst, const std::string& name ) const
+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
}
// -------------------------------------------------------------------------
template< class P >
void cpPlugins::Interface::Parameters::
-GetValueAsPointList( std::vector< P >& lst, const std::string& name ) const
+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__