]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 17 May 2016 16:28:52 +0000 (11:28 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 17 May 2016 16:28:52 +0000 (11:28 -0500)
lib/cpPlugins/Parameters.cxx
lib/cpPlugins/Parameters.h
lib/cpPlugins/ParametersQtDialog.h

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$
index 5393d03bcae4bf82f149f375d97767365a5d0a60..dc0ea52478d2c24115a581bb4a0c012cefcbed49 100644 (file)
@@ -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 );
index 8c769845124cdf4896872968cd66f8fb4d90a6eb..0d732d798f4aad8de943bf3f6869c5789b853900 100644 (file)
@@ -32,7 +32,7 @@ namespace cpPlugins
     virtual ~ParametersQtDialog( );
 
     ProcessObject* getProcessObject( ) const;
-    bool setProcessObject( ProcessObject* obj );
+    virtual bool setProcessObject( ProcessObject* obj );
 
     virtual int exec( );