]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Parameters.h
...
[cpPlugins.git] / lib / cpPlugins / Parameters.h
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 );