]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Parameters.cxx
...
[cpPlugins.git] / lib / cpPlugins / Parameters.cxx
index c805327b681aa445bfdbb450a967ef087a59deb2..4da3ec38802aeee50341714ef1937c885bd396bb 100644 (file)
@@ -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$