itom 2.2.1
K:/git-itom/sources/itom/common/param.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet Stuttgart, Germany
00006 
00007     This file is part of itom and its software development toolkit (SDK).
00008 
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013    
00014     In addition, as a special exception, the Institut fuer Technische
00015     Optik (ITO) gives you certain additional rights.
00016     These rights are described in the ITO LGPL Exception version 1.0,
00017     which can be found in the file LGPL_EXCEPTION.txt in this package.
00018 
00019     itom is distributed in the hope that it will be useful, but
00020     WITHOUT ANY WARRANTY; without even the implied warranty of
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00022     General Public Licence for more details.
00023 
00024     You should have received a copy of the GNU Library General Public License
00025     along with itom. If not, see <http://www.gnu.org/licenses/>.
00026 *********************************************************************** */
00027 
00028 #ifndef PARAM_H
00029 #define PARAM_H
00030 
00031 /* includes */
00032 
00033 #include "commonGlobal.h"
00034 #include "typeDefs.h"
00035 #include "byteArray.h"
00036 #include "retVal.h"
00037 #include "paramMeta.h"
00038 
00039 #include <string.h>
00040 #include <stdlib.h>
00041 #include <stdio.h>
00042 #include <stdarg.h>
00043 #include <limits>
00044 #include <stdexcept>
00045 
00046 /* definition and macros */
00047 /* global variables (avoid) */
00048 /* content */
00049 
00050 namespace ito
00051 {
00052     class Param;
00053     class ParamHelper;
00054     template<typename _Tp> struct ItomParamHelper;
00055 
00056     const uint32 paramFlagMask = 0xFFFF0000; 
00057     const uint32 paramTypeMask = 0x0000FFFF; 
00058 
00060     struct ITOMCOMMON_EXPORT complex128_
00061     {
00062         complex128_(float64 r, float64 i) : real(r), imag(i) {};
00063         float64 real;
00064         float64 imag;
00065     };
00066 
00067     class ITOMCOMMON_EXPORT ParamBase
00068     {
00069     protected:
00070         uint32 m_type;
00071         ByteArray m_name;      
00072 
00073         void inOutCheck();
00074 
00075         static inline uint32 typeFilter(uint32 type) { return type & paramTypeMask; }
00076 
00077     private:
00078         complex128_ m_dVal;    
00079         ito::int32 m_iVal;         
00080         char *m_cVal;         
00081 
00082     public:
00083         enum Type {
00084             //flags (bit 17-32)
00085             NoAutosave      = 0x010000,
00086             Readonly        = 0x020000, // this flag is not used inside Param but you can check for it
00087             In              = 0x040000,
00088             Out             = 0x080000,
00089 
00090             //type (bit 1-16)
00091             Pointer         = 0x000001,
00092             Char            = 0x000002,
00093             Int             = 0x000004,
00094             Double          = 0x000008,
00095             Complex         = 0x000400,
00096             DObjPtr         = 0x000010 | Pointer | NoAutosave,
00097             String          = 0x000020 | Pointer,
00098             HWRef           = 0x000040 | Pointer | NoAutosave,
00099             CharArray       = Char     | Pointer,
00100             IntArray        = Int      | Pointer,
00101             DoubleArray     = Double   | Pointer,
00102             ComplexArray    = Complex  | Pointer,
00103             PointCloudPtr   = 0x000080 | Pointer | NoAutosave,
00104             PointPtr        = 0x000100 | Pointer | NoAutosave,
00105             PolygonMeshPtr  = 0x000200 | Pointer | NoAutosave
00106         };
00107 
00108         
00109         //--------------------------------------------------------------------------------------------
00110         //  CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
00111         //--------------------------------------------------------------------------------------------
00113         ParamBase() : m_type(0), m_name(NULL), m_dVal(0.0, 0.0), m_iVal(0), m_cVal(NULL) {}
00114         ParamBase(const ByteArray &name);                                                                  // type-less ParamBase with name only
00115         ParamBase(const ByteArray &name, const uint32 type);                                               // constructor with type and name
00116         ParamBase(const ByteArray &name, const uint32 type, const char *val);                              // constructor with name and type and char val
00117         ParamBase(const ByteArray &name, const uint32 type, const float64 val);                            // constructor with name and type and float64 val
00118         ParamBase(const ByteArray &name, const uint32 type, const int32 val);                              // constructor with name and type and int32 val
00119         ParamBase(const ByteArray &name, const uint32 type, const complex128 val);                         // constructor with name and type and complex128 val
00120         ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const char *values);        // array constructor with name and type, size and array
00121         ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const int32 *values);       // array constructor with name and type, size and array
00122         ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const float64 *values);     // array constructor with name and type, size and array
00123         ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const complex128 *values);  // array constructor with name and type, size and array
00124         virtual ~ParamBase(); //Destructor
00125         ParamBase(const ParamBase &copyConstr); //Copy-Constructor
00126 
00127         //--------------------------------------------------------------------------------------------
00128         //  ASSIGNMENT AND OPERATORS
00129         //--------------------------------------------------------------------------------------------
00130         const ParamBase operator [] (const int num) const;     
00131         ParamBase& operator = (const ParamBase &rhs);          
00132         ito::RetVal copyValueFrom(const ito::ParamBase *rhs);  
00133 
00134         //--------------------------------------------------------------------------------------------
00135         // COMPARISON OPERATORS (two values are equal if both their type and the content is equal)
00136         //--------------------------------------------------------------------------------------------
00137         bool operator ==(const ParamBase &rhs) const;
00138 
00139         inline bool operator !=(const ParamBase &rhs) const
00140         {
00141             return !(*this == rhs);
00142         }
00143 
00144         //--------------------------------------------------------------------------------------------
00145         //  SET/GET FURTHER PROPERTIES
00146         //--------------------------------------------------------------------------------------------
00147 
00149         inline bool isNumeric(void) const
00150         {
00151             static int numericTypeMask = ito::ParamBase::Char | ParamBase::Int | ParamBase::Double | ParamBase::Complex;
00152             return ((m_type & numericTypeMask) > 0) && !(m_type & ito::ParamBase::Pointer);
00153         }
00154 
00156         inline bool isNumericArray(void) const
00157         {
00158             static int numericTypeMask = ito::ParamBase::Char | ParamBase::Int | ParamBase::Double | ParamBase::Complex;
00159             return (m_type & (numericTypeMask | ito::ParamBase::Pointer)) > 0;
00160         }
00161 
00163         inline bool isValid(void) const { return m_type != 0; }
00164 
00166         inline uint32 getType(bool filterFlags = true) const
00167         {
00168             if (filterFlags)
00169                 return m_type & paramTypeMask;
00170             else
00171                 return m_type;
00172         }
00173 
00175         inline uint32 getFlags(void) const { return m_type & paramFlagMask; }
00176         
00178         inline void setFlags(const uint32 flags) { m_type = getType() | (flags & paramFlagMask); }
00179    
00181         inline const char* getName(void) const { return m_name.data(); }
00182 
00185         inline bool getAutosave(void) const { return (m_type & NoAutosave) > 0; }
00186 
00189         inline void setAutosave(const bool autosave) { m_type = autosave ? (m_type & ~NoAutosave) : (m_type | NoAutosave); }
00190 
00192         int getLen(void) const;
00193         
00194             
00201         template<typename _Tp> inline ito::RetVal setVal(_Tp val)
00202         {
00203             return ItomParamHelper<_Tp>::setVal(getType(), m_cVal, m_iVal, m_dVal, val, 0);
00204         }
00205 
00213         template<typename _Tp> inline ito::RetVal setVal(_Tp val, int len)
00214         {
00215             return ItomParamHelper<_Tp>::setVal(getType(), m_cVal, m_iVal, m_dVal, val, len);
00216         }
00217 
00224         template<typename _Tp> inline _Tp getVal(void) const
00225         {
00226             int len = 0;
00227             return ItomParamHelper<_Tp>::getVal(getType(), m_cVal, m_iVal, m_dVal, len);
00228         }
00229 
00236         template<typename _Tp> inline _Tp getVal(int &len) const
00237         {
00238             return ItomParamHelper<_Tp>::getVal(getType(), m_cVal, m_iVal, m_dVal, len);
00239         }
00240 
00241     };
00242 
00243     //----------------------------------------------------------------------------------------------------------------------------------
00250     class ITOMCOMMON_EXPORT Param : public ParamBase
00251     {
00252         private:
00253             ParamMeta *m_pMeta;
00254             ByteArray m_info;
00255 
00256         public:
00257 
00258             //--------------------------------------------------------------------------------------------
00259             //  CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
00260             //--------------------------------------------------------------------------------------------
00262             Param() : ParamBase(), m_pMeta(NULL), m_info(NULL) {}
00263             Param(const ByteArray &name) : ParamBase(name), m_pMeta(NULL), m_info(NULL) {}                         // type-less Param with name only
00264             Param(const ByteArray &name, const uint32 type) : ParamBase(name, type), m_pMeta(NULL), m_info(NULL) {}   // constructor with type and name
00265             Param(const ByteArray &name, const uint32 type, const char *val, const char *info);                        // constructor with name and type, char val and optional info
00266             Param(const ByteArray &name, const uint32 type, const char minVal, const char maxVal, const char val, const char *info); // constructor with name and type, int val, int minVal, int maxVal and optional info
00267             Param(const ByteArray &name, const uint32 type, const int32 minVal, const int32 maxVal, const int32 val, const char *info); // constructor with name and type, int val, int minVal, int maxVal and optional info
00268             Param(const ByteArray &name, const uint32 type, const float64 minVal, const float64 maxVal, const float64 val, const char *info); // constructor with name and type, double val, double minVal, double maxVal and optional info
00269             Param(const ByteArray &name, const uint32 type, const unsigned int size, const char *values, const char *info);  // array constructor with name and type, size and array
00270             Param(const ByteArray &name, const uint32 type, const unsigned int size, const int32 *values, const char *info);   // array constructor with name and type, size and array
00271             Param(const ByteArray &name, const uint32 type, const unsigned int size, const float64 *values, const char *info);// array constructor with name and type, size and array
00272             Param(const ByteArray &name, const uint32 type, const unsigned int size, const complex128 *values, const char *info);// array constructor with name and type, size and array
00273             Param(const ByteArray &name, const uint32 type, const char val, ParamMeta *meta, const char *info);
00274             Param(const ByteArray &name, const uint32 type, const int32 val, ParamMeta *meta, const char *info);
00275             Param(const ByteArray &name, const uint32 type, const float64 val, ParamMeta *meta, const char *info);
00276             Param(const ByteArray &name, const uint32 type, const complex128 val, ParamMeta *meta, const char *info);
00277             Param(const ByteArray &name, const uint32 type, const unsigned int size, const char *values, ParamMeta *meta, const char *info);
00278             Param(const ByteArray &name, const uint32 type, const unsigned int size, const int32 *values, ParamMeta *meta, const char *info);
00279             Param(const ByteArray &name, const uint32 type, const unsigned int size, const float64 *values, ParamMeta *meta, const char *info);
00280             Param(const ByteArray &name, const uint32 type, const unsigned int size, const complex128 *values, ParamMeta *meta, const char *info);
00281             ~Param();                        
00282             Param(const Param &copyConstr); 
00283 
00284             //--------------------------------------------------------------------------------------------
00285             //  ASSIGNMENT AND OPERATORS
00286             //--------------------------------------------------------------------------------------------
00287             const Param operator [] (const int num) const;    
00288             Param& operator = (const Param &rhs);             
00289             ito::RetVal copyValueFrom(const ParamBase *rhs);  
00290 
00291             //--------------------------------------------------------------------------------------------
00292             //  SET/GET FURTHER PROPERTIES
00293             //--------------------------------------------------------------------------------------------
00295             inline const char * getInfo(void) const { return m_info.data(); }
00296 
00298             inline void setInfo(const char *info)
00299             {
00300                 m_info = info;
00301             }
00302 
00303             inline void setInfo(const ByteArray &info)
00304             {
00305                 m_info = info;
00306             }
00307 
00308             inline const ParamMeta* getMeta(void) const { return m_pMeta; } 
00309             inline ParamMeta* getMeta(void) { return m_pMeta; }                
00310 
00312 
00317             void setMeta(ParamMeta* meta, bool takeOwnership = false);
00318 
00319             float64 getMin() const;
00320             float64 getMax() const;
00321     };
00322 
00323     //---------------------------------------------------------------------------------------------------------------------
00324     template<typename _Tp>
00325     struct ItomParamHelper
00326     {
00327         static ito::RetVal setVal(uint32 type, char *&cVal, int32 &iVal, complex128_ &/*dVal*/, const _Tp val, int len = 0)
00328         {
00329             switch (type & paramTypeMask)
00330             {
00331                 case (ito::ParamBase::HWRef & paramTypeMask):
00332                 case (ito::ParamBase::DObjPtr & paramTypeMask):
00333                 case ito::ParamBase::PointCloudPtr & paramTypeMask:
00334                 case ito::ParamBase::PointPtr & paramTypeMask:
00335                 case ito::ParamBase::PolygonMeshPtr & paramTypeMask:
00336 //                case ito::ParamBase::Pointer & paramTypeMask:
00337                     cVal = (char*)(reinterpret_cast<const char*>(val));
00338                     return ito::retOk;
00339 
00340                 case ito::ParamBase::String & paramTypeMask:
00341                     {
00342                         char *cVal_ = cVal;
00343                         if (val)
00344                         {
00345                             cVal = _strdup((const char*)val);
00346                             iVal = static_cast<int>(strlen(cVal));
00347                         }
00348                         else
00349                         {
00350                             cVal = 0;
00351                             iVal = -1;
00352                         }
00353                         if (cVal_)
00354                         {
00355                             free(cVal_);
00356                         }
00357                     }
00358                     return ito::retOk;
00359 
00360                 case ito::ParamBase::CharArray & ito::paramTypeMask:
00361                     {
00362                         char *cVal_ = cVal;
00363                         if ((val) && (len > 0))
00364                         {
00365                             cVal = (char*)malloc(len * sizeof(char));
00366                             memcpy(cVal, val, len * sizeof(char));
00367                             iVal = len;
00368                         }
00369                         else
00370                         {
00371                             cVal = NULL;
00372                             iVal = -1;
00373                         }
00374                         if (cVal_)
00375                         {
00376                             free(cVal_);
00377                         }
00378                     }
00379                     return ito::retOk;
00380 
00381                 case ito::ParamBase::IntArray & ito::paramTypeMask:
00382                     {
00383                         char *cVal_ = cVal;
00384                         if ((val) && (len > 0))
00385                         {
00386                             cVal = (char*)malloc(len * sizeof(ito::int32));
00387                             memcpy(cVal, val, len * sizeof(ito::int32));
00388                             iVal = len;
00389                         }
00390                         else
00391                         {
00392                             cVal = NULL;
00393                             iVal = -1;
00394                         }
00395                         if (cVal_)
00396                         {
00397                             free(cVal_);
00398                         }
00399                     }
00400                     return ito::retOk;
00401 
00402                 case ito::ParamBase::DoubleArray & ito::paramTypeMask:
00403                     {
00404                         char *cVal_ = cVal;
00405                         if ((val) && (len > 0))
00406                         {
00407                             cVal = (char*)malloc(len * sizeof(ito::float64));
00408                             memcpy(cVal, val, len * sizeof(ito::float64));
00409                             iVal = len;
00410                         }
00411                         else
00412                         {
00413                             cVal = NULL;
00414                             iVal = -1;
00415                         }
00416                         if (cVal_)
00417                         {
00418                             free(cVal_);
00419                         }
00420                     }
00421                     return ito::retOk;
00422 
00423                 case ito::ParamBase::ComplexArray & ito::paramTypeMask:
00424                     {
00425                         char *cVal_ = cVal;
00426                         if ((val) && (len > 0))
00427                         {
00428                             cVal = (char*)malloc(len * sizeof(ito::complex128));
00429                             memcpy(cVal, val, len * sizeof(ito::complex128));
00430                             iVal = len;
00431                         }
00432                         else
00433                         {
00434                             cVal = NULL;
00435                             iVal = -1;
00436                         }
00437                         if (cVal_)
00438                         {
00439                             free(cVal_);
00440                         }
00441                     }
00442                     return ito::retOk;
00443 
00444                 default:
00445                     return ito::RetVal(ito::retError, 0, "_Tp parameter of setVal<_Tp> does not match the type of the parameter");
00446             }
00447         }
00448 
00449         static _Tp getVal(const uint32 type, const char *cVal, const int32 &iVal, const complex128_ &/*dVal*/, int &len)
00450         {
00451             switch (type & paramTypeMask)
00452             {
00453                 case ito::ParamBase::String & paramTypeMask:
00454                     if (cVal)
00455                     {
00456                         len = static_cast<int>(strlen(cVal));
00457                         return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
00458                     }
00459                     else
00460                     {
00461                         len = 0;
00462                         return 0;
00463                     }
00464 
00465                 case ito::ParamBase::CharArray & ito::paramTypeMask:
00466                 case ito::ParamBase::IntArray & ito::paramTypeMask:
00467                 case ito::ParamBase::DoubleArray & ito::paramTypeMask:
00468                 case ito::ParamBase::ComplexArray & ito::paramTypeMask:
00469                     if (cVal)
00470                     {
00471                         len = iVal;
00472                         return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
00473                     }
00474                     else
00475                     {
00476                         len = 0;
00477                         return 0;
00478                     }
00479 
00480                 case (ito::ParamBase::HWRef & paramTypeMask):
00481                 case (ito::ParamBase::DObjPtr & paramTypeMask):
00482                 case ito::ParamBase::PointCloudPtr & paramTypeMask:
00483                 case ito::ParamBase::PointPtr & paramTypeMask:
00484                 case ito::ParamBase::PolygonMeshPtr & paramTypeMask:
00485                     return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
00486 
00487                 default:
00488                     throw std::logic_error("Param::getVal<_Tp>: Non-matching type!");
00489             }
00490         }
00491     };
00492 
00493     template<>
00494     struct ItomParamHelper<float64>
00495     {
00496         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, float64 val, int /*len = 0*/)
00497         {
00498             switch (type & paramTypeMask)
00499             {
00500                 case ito::ParamBase::Complex & ito::paramTypeMask:
00501                 case ito::ParamBase::Double & ito::paramTypeMask:
00502                     dVal.real = static_cast<float64>(val);
00503                     dVal.imag = 0.0;
00504                     return ito::retOk;
00505 
00506                 case ito::ParamBase::Int & ito::paramTypeMask:
00507                 case ito::ParamBase::Char & ito::paramTypeMask:
00508                     iVal = static_cast<int32>(val);
00509                     return ito::retOk;
00510 
00511                 default:
00512                     return ito::RetVal(ito::retError, 0, "float64 value passed to setVal<float64> does not match the type of the parameter");
00513             }
00514         }
00515 
00516         static float64 getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
00517         {
00518             switch (type & paramTypeMask)
00519             {
00520                 case ito::ParamBase::Int & ito::paramTypeMask:
00521                 case ito::ParamBase::Char & ito::paramTypeMask:
00522                     return static_cast<float64>(iVal);
00523                 
00524                 case ito::ParamBase::Complex & ito::paramTypeMask:
00525                 case ito::ParamBase::Double & ito::paramTypeMask:
00526                     return dVal.real;
00527 
00528                 default:
00529                     throw std::logic_error("Param::getVal<float64>: Non-matching type!");
00530             }
00531         }
00532     };
00533 
00534     template<>
00535     struct ItomParamHelper<int32>
00536     {
00537         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, int32 val, int /*len = 0*/)
00538         {
00539             switch (type & paramTypeMask)
00540             {
00541                 case ito::ParamBase::Complex & ito::paramTypeMask:
00542                 case ito::ParamBase::Double & ito::paramTypeMask:
00543                     dVal.real = static_cast<float64>(val);
00544                     dVal.imag = 0.0;
00545                     return ito::retOk;
00546 
00547                 case ito::ParamBase::Int & ito::paramTypeMask:
00548                 case ito::ParamBase::Char & ito::paramTypeMask:
00549                     iVal = val;
00550                     return ito::retOk;
00551 
00552                 default:
00553                     return ito::RetVal(ito::retError, 0, "int32 value passed to setVal<int32> does not match the type of the parameter");
00554             }
00555         }
00556 
00557         static int32 getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
00558         {
00559             switch (type & paramTypeMask)
00560             {
00561                 case ito::ParamBase::Int & ito::paramTypeMask:
00562                 case ito::ParamBase::Char & ito::paramTypeMask:
00563                     return iVal;
00564 
00565                 case ito::ParamBase::Complex & ito::paramTypeMask:
00566                 case ito::ParamBase::Double & ito::paramTypeMask:
00567                     return static_cast<int32>(dVal.real);
00568 
00569                 case 0:
00570                     throw std::invalid_argument("Param::getVal<int32>: non existent parameter");
00571 
00572                 default:
00573                     throw std::logic_error("Param::getVal<int32>: Non-matching type!");
00574             }
00575         }
00576     };
00577 
00578     template<>
00579     struct ItomParamHelper<char>
00580     {
00581         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, char val, int /*len = 0*/)
00582         {
00583             switch (type & paramTypeMask)
00584             {
00585                 case ito::ParamBase::Complex & ito::paramTypeMask:
00586                 case ito::ParamBase::Double & ito::paramTypeMask:
00587                     dVal.real = static_cast<float64>(val);
00588                     dVal.imag = 0.0;
00589                     return ito::retOk;
00590 
00591                 case ito::ParamBase::Int & ito::paramTypeMask:
00592                 case ito::ParamBase::Char & ito::paramTypeMask:
00593                     iVal = static_cast<char>(val);
00594                     return ito::retOk;
00595 
00596                 default:
00597                     return ito::RetVal(ito::retError, 0, "char value passed to setVal<char> does not match the type of the parameter");
00598             }
00599         }
00600 
00601         static char getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
00602         {
00603             switch (type & paramTypeMask)
00604             {
00605                 case ito::ParamBase::Int & ito::paramTypeMask:
00606                 case ito::ParamBase::Char & ito::paramTypeMask:
00607                     return static_cast<char>(iVal);
00608 
00609                 case ito::ParamBase::Complex & ito::paramTypeMask:
00610                 case ito::ParamBase::Double & ito::paramTypeMask:
00611                     return static_cast<char>(dVal.real);
00612 
00613                 case 0:
00614                     throw std::invalid_argument("Param::getVal<char>: non existent parameter");
00615 
00616                 default:
00617                     throw std::logic_error("Param::getVal<char>: Non-matching type!");
00618             }
00619         }
00620     };
00621 
00622     template<>
00623     struct ItomParamHelper<unsigned char>
00624     {
00625         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, char val, int /*len = 0*/)
00626         {
00627             switch (type & paramTypeMask)
00628             {
00629                 case ito::ParamBase::Complex & ito::paramTypeMask:
00630                 case ito::ParamBase::Double & ito::paramTypeMask:
00631                     dVal.real = static_cast<float64>(val);
00632                     dVal.imag = 0.0;
00633                     return ito::retOk;
00634 
00635                 case ito::ParamBase::Int & ito::paramTypeMask:
00636                 case ito::ParamBase::Char & ito::paramTypeMask:
00637                     iVal = static_cast<unsigned char>(val);
00638                     return ito::retOk;
00639 
00640                 default:
00641                     return ito::RetVal(ito::retError, 0, "unsigned char value passed to setVal<unsigned char> does not match the type of the parameter");
00642             }
00643         }
00644 
00645         static char getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
00646         {
00647             switch (type & paramTypeMask)
00648             {
00649                 case ito::ParamBase::Int & ito::paramTypeMask:
00650                 case ito::ParamBase::Char & ito::paramTypeMask:
00651                     return static_cast<unsigned char>(iVal);
00652 
00653                 case ito::ParamBase::Complex & ito::paramTypeMask:
00654                 case ito::ParamBase::Double & ito::paramTypeMask:
00655                     return static_cast<unsigned char>(dVal.real);
00656 
00657                 case 0:
00658                     throw std::invalid_argument("Param::getVal<uchar>: non existent parameter");
00659 
00660                 default:
00661                     throw std::logic_error("Param::getVal<uchar>: Non-matching type!");
00662             }
00663         }
00664     };
00665 
00666     template<>
00667     struct ItomParamHelper<complex128>
00668     {
00669         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, complex128 val, int /*len = 0*/)
00670         {
00671             switch (type & paramTypeMask)
00672             {
00673                 case ito::ParamBase::Complex & ito::paramTypeMask:
00674                     dVal.real = val.real();
00675                     dVal.imag = val.imag();
00676                     return ito::retOk;
00677 
00678                 default:
00679                     return ito::RetVal(ito::retError, 0, "complex128 value passed to setVal<complex128> does not match the type of the parameter");
00680             }
00681         }
00682 
00683         static complex128 getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
00684         {
00685             switch (type & paramTypeMask)
00686             {
00687                 case ito::ParamBase::Int & ito::paramTypeMask:
00688                 case ito::ParamBase::Char & ito::paramTypeMask:
00689                     return complex128(iVal, 0.0);
00690                 
00691                 case ito::ParamBase::Complex & ito::paramTypeMask:
00692                     return complex128(dVal.real, dVal.imag);
00693 
00694                 case ito::ParamBase::Double & ito::paramTypeMask:
00695                     return dVal.real;
00696 
00697                 default:
00698                     throw std::logic_error("Param::getVal<complex128>: Non-matching type!");
00699             }
00700         }
00701     };
00702 
00703 } //end namespace ito
00704 
00705 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends