]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/Parameters.h
Widget integration (step 5/6): Interactive plugins now supported, widgets updates...
[cpPlugins.git] / lib / cpPlugins / Interface / Parameters.h
index 0e54f0f7fdfae594e9fd9a55cb7042fde4a22a10..abde990d0759714b422a594c28fe9722c938abf8 100644 (file)
@@ -1,11 +1,15 @@
 #ifndef __CPPLUGINS__INTERFACE__PARAMETERS__H__
 #define __CPPLUGINS__INTERFACE__PARAMETERS__H__
 
+#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+
 #include <map>
 #include <ostream>
 #include <string>
 #include <vector>
-#include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
+
+#include <itkObject.h>
+#include <itkObjectFactory.h>
 
 namespace cpPlugins
 {
@@ -14,28 +18,13 @@ namespace cpPlugins
     /**
      */
     class cpPlugins_Interface_EXPORT Parameters
+      : public itk::Object
     {
-      // -------------------------------------------------------------------
-      friend std::ostream& operator<<(
-        std::ostream& os, const Parameters& p
-        )
-      {
-        Parameters::TParameters::const_iterator pIt =
-          p.m_Parameters.begin( );
-        for( ; pIt != p.m_Parameters.end( ); ++pIt )
-        {
-          os
-            << pIt->first << ": ("
-            << pIt->second.first << ", "
-            << pIt->second.second << ")"
-            << std::endl;
-
-        } // rof
-        return( os );
-      }
-
     public:
-      typedef Parameters Self;
+      typedef Parameters                      Self;
+      typedef itk::Object                     Superclass;
+      typedef itk::SmartPointer< Self >       Pointer;
+      typedef itk::SmartPointer< const Self > ConstPointer;
 
       enum Type
       {
@@ -43,7 +32,8 @@ namespace cpPlugins
         Uint      , Real       , Index    ,
         Point     , StringList , BoolList ,
         IntList   , UintList   , RealList ,
-        IndexList , PointList  , NoType
+        IndexList , PointList  , Choices  ,
+        NoType
       };
 
       typedef bool          TBool;
@@ -52,97 +42,156 @@ namespace cpPlugins
       typedef double        TReal;
       typedef std::string   TString;
 
-      typedef std::pair< Self::Type, TString > TParameter;
+      // NOTE: std::pair< default, value >
+      typedef std::pair< TString, TString >    TValues;
+      typedef std::pair< Self::Type, TValues > TParameter;
       typedef std::map< TString, TParameter >  TParameters;
 
     public:
-      Parameters( );
-      Parameters( const Self& other );
-      virtual ~Parameters( );
-
-      Self& operator=( const Self& other );
+      itkNewMacro( Self );
+      itkTypeMacro( cpPlugins::Interface::Parameters, itk::Object );
 
+    public:
+      // Parameters container configuration
       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 );
-      void SetValueAsIndex( const TString& name, const TUint& n, ... );
-      void SetValueAsPoint( const TString& name, const TUint& n, ... );
-
-      void AddValueToStringList( const TString& name, const TString& v );
-      void AddValueToBoolList( const TString& name, const TBool& v );
-      void AddValueToIntList( const TString& name, const TInt& v );
-      void AddValueToUintList( const TString& name, const TUint& v );
-      void AddValueToRealList( const TString& name, const TReal& v );
-      void AddValueToIndexList( const TString& name, const TUint& n, ... );
-      void AddValueToPointList( const TString& name, const TUint& n, ... );
 
-      void ClearStringList( const TString& name );
-      void ClearBoolList( const TString& name );
-      void ClearIntList( const TString& name );
-      void ClearUintList( const TString& name );
-      void ClearRealList( const TString& name );
-      void ClearIndexList( const TString& name );
-      void ClearPointList( const TString& name );
-      
-      std::vector< TString > GetParameters( ) const;
-      Self::Type GetParameterType( const TString& name ) const;
-      const TString& GetRawValue( 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;
+      void ConfigureAsString( const TString& name, const TString& v );
+      void ConfigureAsBool( const TString& name, const TBool& v );
+      void ConfigureAsInt( const TString& name, const TInt& v );
+      void ConfigureAsUint( const TString& name, const TUint& v );
+      void ConfigureAsReal( const TString& name, const TReal& v );
 
       template< class I >
-      I GetValueAsIndex( const TString& name ) const;
-
+        inline void ConfigureAsIndex(
+          const TString& name, const TUint& dim, const I& v
+          );
       template< class P >
-      P GetValueAsPoint( const TString& name ) const;
-
-      void GetValueAsStringList(
+        inline void ConfigureAsPoint(
+          const TString& name, const TUint& dim, const P& v
+          );
+
+      void ConfigureAsStringList( const TString& name );
+      void ConfigureAsBoolList( const TString& name );
+      void ConfigureAsIntList( const TString& name );
+      void ConfigureAsUintList( const TString& name );
+      void ConfigureAsRealList( const TString& name );
+      void ConfigureAsIndexList( const TString& name );
+      void ConfigureAsPointList( const TString& name );
+      void ConfigureAsChoices(
+        const TString& name, const std::vector< TString >& choices
+        );
+
+      // Get methods
+      void GetNames( std::vector< TString >& container ) const;
+      Type GetType( const TString& name ) const;
+
+      bool HasString( const TString& name ) const;
+      bool HasBool( const TString& name ) const;
+      bool HasInt( const TString& name ) const;
+      bool HasUint( const TString& name ) const;
+      bool HasReal( const TString& name ) const;
+      bool HasIndex( const TString& name ) const;
+      bool HasPoint( const TString& name ) const;
+      bool HasStringList( const TString& name ) const;
+      bool HasBoolList( const TString& name ) const;
+      bool HasIntList( const TString& name ) const;
+      bool HasUintList( const TString& name ) const;
+      bool HasRealList( const TString& name ) const;
+      bool HasIndexList( const TString& name ) const;
+      bool HasPointList( const TString& name ) const;
+      bool HasChoices( const TString& name ) const;
+
+      TString GetString( const TString& name ) const;
+      TBool GetBool( const TString& name ) const;
+      TInt GetInt( const TString& name ) const;
+      TUint GetUint( const TString& name ) const;
+      TReal GetReal( const TString& name ) const;
+
+      void GetStringList(
         std::vector< TString >& lst, const TString& name
         ) const;
-      void GetValueAsBoolList(
+      void GetBoolList(
         std::vector< TBool >& lst, const TString& name
         ) const;
-      void GetValueAsIntList(
+      void GetIntList(
         std::vector< TInt >& lst, const TString& name
         ) const;
-      void GetValueAsUintList(
+      void GetUintList(
         std::vector< TUint >& lst, const TString& name
         ) const;
-      void GetValueAsRealList(
+      void GetRealList(
         std::vector< TReal >& lst, const TString& name
         ) const;
 
-      template< class I >
-      void GetValueAsIndexList(
-        std::vector< I >& lst, const TString& name
+      void GetChoices(
+        std::vector< TString >& choices, const TString& name
         ) const;
+      TString GetSelectedChoice( const TString& name ) const;
 
+      template< class I >
+        inline I GetIndex( const TString& name, const TUint& dim ) const;
       template< class P >
-      void GetValueAsPointList(
-        std::vector< P >& lst, const TString& name
-        ) const;
+        inline P GetPoint( const TString& name, const TUint& dim ) const;
+
+      template< class I >
+        inline void GetIndexList(
+          std::vector< I >& lst, const TString& name, const TUint& dim
+          ) const;
+      template< class P >
+        inline void GetPointList(
+          std::vector< P >& lst, const TString& name, const TUint& dim
+          ) const;
+
+      // Set methods
+      void SetString( const TString& name, const TString& v );
+      void SetBool( const TString& name, const TBool& v );
+      void SetInt( const TString& name, const TInt& v );
+      void SetUint( const TString& name, const TUint& v );
+      void SetReal( const TString& name, const TReal& v );
+
+      template< class I >
+        inline void SetIndex(
+          const TString& name, const TUint& dim, const I& v
+          );
+      template< class P >
+        inline void SetPoint(
+          const TString& name, const TUint& dim, const P& v
+          );
+
+      void AddToStringList( const TString& name, const TString& v );
+      void AddToBoolList( const TString& name, const TBool& v );
+      void AddToIntList( const TString& name, const TInt& v );
+      void AddToUintList( const TString& name, const TUint& v );
+      void AddToRealList( const TString& name, const TReal& v );
 
-      bool HasStringValue( const TString& name ) const;
-      bool HasBoolValue( const TString& name ) const;
-      bool HasIntValue( const TString& name ) const;
-      bool HasUintValue( const TString& name ) const;
-      bool HasRealValue( const TString& name ) const;
-      bool HasIndexValue( const TString& name ) const;
-      bool HasPointValue( const TString& name ) const;
-      bool HasStringListValue( const TString& name ) const;
-      bool HasBoolListValue( const TString& name ) const;
-      bool HasIntListValue( const TString& name ) const;
-      bool HasUintListValue( const TString& name ) const;
-      bool HasRealListValue( const TString& name ) const;
-      bool HasIndexListValue( const TString& name ) const;
-      bool HasPointListValue( const TString& name ) const;
+      template< class I >
+        inline void AddToIndexList(
+          const TString& name, const TUint& dim, const I& v
+          );
+      template< class P >
+        inline void AddToPointList(
+          const TString& name, const TUint& dim, const P& v
+          );
+
+      void ClearStringList( const TString& name );
+      void ClearBoolList( const TString& name );
+      void ClearIntList( const TString& name );
+      void ClearUintList( const TString& name );
+      void ClearRealList( const TString& name );
+      void ClearIndexList( const TString& name );
+      void ClearPointList( const TString& name );
+
+      bool SetSelectedChoice( const TString& name, const TString& choice );
+
+    protected:
+      Parameters( );
+      virtual ~Parameters( );
+      void PrintSelf( std::ostream& os, itk::Indent indent ) const;
+
+    private:
+      // Purposely not implemented
+      Parameters( const Self& other );
+      Self& operator=( const Self& other );
 
     protected:
       TParameters m_Parameters;