]> Creatis software - cpPlugins.git/commitdiff
Parameters improved
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 26 Jan 2015 23:04:42 +0000 (18:04 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 26 Jan 2015 23:04:42 +0000 (18:04 -0500)
appli/examples/CMakeLists.txt
appli/examples/example_TestParameters.cxx [new file with mode: 0644]
lib/cpPlugins/Interface/Parameters.cxx
lib/cpPlugins/Interface/Parameters.h
lib/cpPlugins/Interface/Parameters.hxx

index e210337ed72e46518f0a82f32e1ac614b3f207b8..3a795782084f8aa01e75028c0e9087ea766f22fc 100644 (file)
@@ -5,6 +5,7 @@
 
 SET(
   EXAMPLES_PROGRAMS
+  example_TestParameters
   example_LoadPlugins
   example_ReadWriteImage
   example_ReadImageSeriesWriteImage
diff --git a/appli/examples/example_TestParameters.cxx b/appli/examples/example_TestParameters.cxx
new file mode 100644 (file)
index 0000000..58711af
--- /dev/null
@@ -0,0 +1,3 @@
+#error ACA VOY
+
+// eof - $RCSfile$
index a42582cbec15148dcb39fd4fdd378b0d3415ba77..b8d358b5103891ed27eed7bf590cfd50865604da 100644 (file)
@@ -19,6 +19,7 @@
   }
 
 cpPlugins_Interface_Parameters_SetMacro( String );
+cpPlugins_Interface_Parameters_SetMacro( Bool );
 cpPlugins_Interface_Parameters_SetMacro( Int );
 cpPlugins_Interface_Parameters_SetMacro( Uint );
 cpPlugins_Interface_Parameters_SetMacro( Real );
@@ -127,6 +128,19 @@ GetValueAsString( const TString& name ) const
   return( pIt->second.second );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Parameters::
+TBool cpPlugins::Interface::Parameters::
+GetValueAsBool( const TString& name ) const
+{
+  TParameters::const_iterator pIt = this->m_Parameters.find( name );
+  if( pIt == this->m_Parameters.end( ) )
+    return( TBool( false ) );
+  if( pIt->second.first != Self::Int )
+    return( TBool( false ) );
+  return( TBool( std::atoi( pIt->second.second.c_str( ) ) == 1 ) );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Parameters::
 TInt cpPlugins::Interface::Parameters::
@@ -174,6 +188,12 @@ GetValueAsStringList(
 {
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Parameters::
+GetValueAsBoolList( std::vector< TBool >& lst, const TString& name ) const
+{
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::Parameters::
 GetValueAsIntList( std::vector< TInt >& lst, const TString& name ) const
index 9ad706ec36572a2b6a37344703dcd846b3130135..bbf9dfcb47b12bf0ee89b741a257bbfb6867ca35 100644 (file)
@@ -19,12 +19,14 @@ namespace cpPlugins
       enum Type
       {
         String = 0,
+        Bool,
         Int,
         Uint,
         Real,
         Index,
         Point,
         StringList,
+        BoolList,
         IntList,
         UintList,
         RealList,
@@ -33,6 +35,7 @@ namespace cpPlugins
         NoType
       };
 
+      typedef bool          TBool;
       typedef long          TInt;
       typedef unsigned long TUint;
       typedef double        TReal;
@@ -51,6 +54,7 @@ namespace cpPlugins
       void Clear( );
       void Configure( const Self::Type& type, const TString& name );
       void SetValueAsString( const TString& name, const TString& v );
+      void SetValueAsBool( const TString& name, const TBool& v );
       void SetValueAsInt( const TString& name, const TInt& v );
       void SetValueAsUint( const TString& name, const TUint& v );
       void SetValueAsReal( const TString& name, const TReal& v );
@@ -62,6 +66,11 @@ namespace cpPlugins
         const TString& name, const I& b, const I& e
         );
 
+      template< class I >
+      void SetValueAsBoolList(
+        const TString& name, const I& b, const I& e
+        );
+
       template< class I >
       void SetValueAsIntList(
         const TString& name, const I& b, const I& e
@@ -90,6 +99,7 @@ namespace cpPlugins
       std::vector< TString > GetParameters( ) const;
       Self::Type GetParameterType( const TString& name ) const;
       const TString& GetValueAsString( const TString& name ) const;
+      TBool GetValueAsBool( const TString& name ) const;
       TInt GetValueAsInt( const TString& name ) const;
       TUint GetValueAsUint( const TString& name ) const;
       TReal GetValueAsReal( const TString& name ) const;
@@ -103,6 +113,9 @@ namespace cpPlugins
       void GetValueAsStringList(
         std::vector< TString >& lst, const TString& name
         ) const;
+      void GetValueAsBoolList(
+        std::vector< TBool >& lst, const TString& name
+        ) const;
       void GetValueAsIntList(
         std::vector< TInt >& lst, const TString& name
         ) const;
index 0a73b373b2ca558f7a3ed21a81a2eb8cf51f455a..9afcc3224184ee2326b8128f3fb86da890d60126 100644 (file)
@@ -23,6 +23,7 @@
   }
 
 cpPlugins_Interface_Parameters_SetListMacro( String );
+cpPlugins_Interface_Parameters_SetListMacro( Bool );
 cpPlugins_Interface_Parameters_SetListMacro( Int );
 cpPlugins_Interface_Parameters_SetListMacro( Uint );
 cpPlugins_Interface_Parameters_SetListMacro( Real );
@@ -30,58 +31,33 @@ cpPlugins_Interface_Parameters_SetListMacro( Index );
 cpPlugins_Interface_Parameters_SetListMacro( Point );
 
 // -------------------------------------------------------------------------
-template< class I >
-I cpPlugins::Interface::Parameters::
-GetValueAsIndex( const TString& name ) const
-{
-  I idx;
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt != this->m_Parameters.end( ) )
-  {
-    if( pIt->second.first == Self::Index )
-    {
-      std::istringstream ss( pIt->second.second );
-      std::string token;
-      unsigned int i = 0;
-      while( std::getline( ss, token, ',' ) )
-      {
-        if( token != "" )
-          idx[ i++ ] = std::atoi( token.c_str( ) );
-
-      } // elihw
-
-    } // fi
-
-  } // fi
-  return( idx );
-}
-
-// -------------------------------------------------------------------------
-template< class P >
-P cpPlugins::Interface::Parameters::
-GetValueAsPoint( const TString& name ) const
-{
-  P pnt;
-  TParameters::iterator pIt = this->m_Parameters.find( name );
-  if( pIt != this->m_Parameters.end( ) )
-  {
-    if( pIt->second.first == Self::Point )
-    {
-      std::istringstream ss( pIt->second.second );
-      std::string token;
-      unsigned int i = 0;
-      while( std::getline( ss, token, ',' ) )
-      {
-        if( token != "" )
-          pnt[ i++ ] = std::atof( token.c_str( ) );
-
-      } // elihw
-
-    } // fi
+#define cpPlugins_Interface_Parameters_SetIndexOrPointMacro( NAME, TYPE ) \
+  template< class T >                                                   \
+  T cpPlugins::Interface::Parameters::                                  \
+  GetValueAs##NAME( const TString& name ) const                         \
+  {                                                                     \
+    T val;                                                              \
+    TParameters::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 );                                                      \
+  }
 
-  } // fi
-  return( pnt );
-}
+cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Index, long );
+cpPlugins_Interface_Parameters_SetIndexOrPointMacro( Point, double );
 
 // -------------------------------------------------------------------------
 template< class I >