itom 1.2.0
D:/git-itom/sources/itom/common/param.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2013, Institut für Technische Optik (ITO),
00005     Universität 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 für 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 
00038 #include <string.h>
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 #include <stdarg.h>
00042 #include <limits>
00043 #include <stdexcept>
00044 
00045 /* definition and macros */
00046 /* global variables (avoid) */
00047 /* content */
00048 
00049 namespace ito
00050 {
00051     class Param;
00052     class ParamHelper;
00053     template<typename _Tp> struct ItomParamHelper;
00054 
00055     const uint32 paramFlagMask = 0xFFFF0000; 
00056     const uint32 paramTypeMask = 0x0000FFFF; 
00057 
00058 
00059     class ITOMCOMMON_EXPORT ParamBase
00060     {
00061     protected:
00062         uint32 m_type;
00063         ByteArray m_name;      
00064 
00065         void InOutCheck();
00066 
00067     private:
00068         double m_dVal;      
00069         int m_iVal;         
00070         char *m_cVal;       
00071 
00072     public:
00073         enum Type {
00074             //flags (bit 17-32)
00075             NoAutosave      = 0x010000,
00076             Readonly        = 0x020000, // this flag is not used inside tParam but you can check for it
00077             In              = 0x040000,
00078             Out             = 0x080000,
00079 
00080             //type (bit 1-16)
00081             Pointer         = 0x000001,
00082             Char            = 0x000002,
00083             Int             = 0x000004,
00084             Double          = 0x000008,
00085             //DObj            = 0x000010,
00086             String          = 0x000020 | Pointer,
00087             HWRef           = 0x000040 | Pointer | NoAutosave,
00088             DObjPtr         = 0x000010 | Pointer | NoAutosave,
00089             CharArray       = Char     | Pointer,
00090             IntArray        = Int      | Pointer,
00091             DoubleArray     = Double   | Pointer,
00092             PointCloudPtr   = 0x000080 | Pointer | NoAutosave,
00093             PointPtr        = 0x000100 | Pointer | NoAutosave,
00094             PolygonMeshPtr  = 0x000200 | Pointer | NoAutosave
00095         };
00096 
00097         static inline uint32 typeFilter(uint32 type) { return type & paramTypeMask; }
00098 
00099         //--------------------------------------------------------------------------------------------
00100         //  CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
00101         //--------------------------------------------------------------------------------------------
00103         ParamBase() : m_type(0), m_name(NULL), m_dVal(0.0), m_iVal(0), m_cVal(NULL) {}
00104         ParamBase(const char *name);                                                               // type-less ParamBase with name only
00105         ParamBase(const char *name, const uint32 type);                                               // constructor with type and name
00106         ParamBase(const char *name, const uint32 type, const char *val);                              // constructor with name and type, char val
00107         ParamBase(const char *name, const uint32 type, const double val);                             // constructor with name and type, double val and optional info
00108         ParamBase(const char *name, const uint32 type, const int val);                                // constructor with name and type, int val and optional info
00109         ParamBase(const ByteArray &name, const uint32 type, const char *val);                              // constructor with name and type, char val
00110         ParamBase(const ByteArray &name, const uint32 type, const double val);                             // constructor with name and type, double val and optional info
00111         ParamBase(const ByteArray &name, const uint32 type, const int val);                                // constructor with name and type, int val and optional info
00112         ParamBase(const char *name, const uint32 type, const unsigned int size, const char *values);  // array constructor with name and type, size and array
00113         ParamBase(const char *name, const uint32 type, const unsigned int size, const int *values);   // array constructor with name and type, size and array
00114         ParamBase(const char *name, const uint32 type, const unsigned int size, const double *values);// array constructor with name and type, size and array
00115         virtual ~ParamBase(); //Destructor
00116         ParamBase(const ParamBase &copyConstr); //Copy-Constructor
00117 
00118         //--------------------------------------------------------------------------------------------
00119         //  ASSIGNMENT AND OPERATORS
00120         //--------------------------------------------------------------------------------------------
00121         const ParamBase operator [] (const int num) const;     
00122         ParamBase& operator = (const ParamBase &rhs);          
00123         ito::RetVal copyValueFrom(const ito::ParamBase *rhs);  
00124 
00125         //--------------------------------------------------------------------------------------------
00126         //  SET/GET FURTHER PROPERTIES
00127         //--------------------------------------------------------------------------------------------
00128 
00130         inline bool isNumeric(void) const
00131         {
00132             static int numericTypeMask = ito::ParamBase::Char | ParamBase::Int | ParamBase::Double;
00133             int type = getType();
00134             return (type & numericTypeMask) && !(type & ito::ParamBase::Pointer);
00135         }
00136 
00137         inline ito::RetVal addNameSuffix(const char *suffix) 
00138         { 
00139             if (suffix)  
00140             { 
00141                 m_name.append(suffix);
00142             }
00143             return ito::retWarning;
00144         }
00146         inline bool isValid(void) const { return m_type != 0; }
00147 
00149         inline uint32 getType(bool filterFlags = true) const 
00150         { 
00151             if (filterFlags) 
00152                 return m_type & paramTypeMask; 
00153             else
00154                 return m_type;
00155         }
00156 
00158         inline uint32 getFlags(void) const { return m_type & paramFlagMask; }
00159         
00161         inline uint32 setFlags(const uint32 flags) { m_type = getType() | (flags & paramFlagMask); return 0; }
00162    
00164         inline const char * getName(void) const { return m_name.data(); }
00167         inline uint32 getAutosave(void) const { return ((m_type & NoAutosave) > 0 ? 0 : 1); }
00170         inline void setAutosave(const uint32 autosave) { m_type = autosave > 0 ? m_type & ~NoAutosave : m_type | NoAutosave; return; }
00171 
00172         int getLen(void) const;
00173         
00174             
00181         template<typename _Tp> inline ito::RetVal setVal(_Tp val)
00182         {
00183             return ItomParamHelper<_Tp>::setVal(getType(), m_cVal, m_iVal, m_dVal, val, 0);
00184         }
00185 
00193         template<typename _Tp> inline ito::RetVal setVal(_Tp val, int len)
00194         {
00195             return ItomParamHelper<_Tp>::setVal(getType(), m_cVal, m_iVal, m_dVal, val, len);
00196         }
00197 
00204         template<typename _Tp> inline _Tp getVal(void) const
00205         {
00206             int len = 0;
00207             return ItomParamHelper<_Tp>::getVal(getType(), m_cVal, m_iVal, m_dVal, len);
00208         }
00209 
00216         template<typename _Tp> inline _Tp getVal(int &len) const
00217         {
00218             return ItomParamHelper<_Tp>::getVal(getType(), m_cVal, m_iVal, m_dVal, len);
00219         }
00220 
00221     };
00222 
00228     class ITOMCOMMON_EXPORT ParamMeta
00229     {
00230     public:
00231         ParamMeta() : m_type(0) {}
00232         ParamMeta(uint32 type) : m_type(type) {}
00233         virtual ~ParamMeta() {}
00234         inline uint32 getType() const { return m_type; }
00235     protected:
00236         uint32 m_type;
00237     };
00238 
00244     class ITOMCOMMON_EXPORT CharMeta : public ParamMeta
00245     {
00246     public:
00248         explicit CharMeta(char minVal, char maxVal, char stepSize=1) : ParamMeta(ParamBase::Char), m_minVal(minVal), m_maxVal(maxVal), m_stepSize(stepSize) { if(m_maxVal < m_minVal) std::swap(m_minVal,m_maxVal); }
00249         static CharMeta* all() { return new CharMeta(std::numeric_limits<char>::min(), std::numeric_limits<char>::max() ); } 
00250         inline char getMin() const { return m_minVal; } 
00251         inline char getMax() const { return m_maxVal; } 
00252         inline char getStepSize() const { return m_stepSize; } 
00253 
00255 
00258         inline void setMin(char val) { m_minVal = val; m_maxVal = std::max(m_maxVal,m_minVal); }
00259         
00261 
00264         inline void setMax(char val) { m_maxVal = val; m_minVal = std::min(m_maxVal,m_minVal); }
00265 
00267 
00270         inline void setStepSize(char val) { m_stepSize = val; }
00271     private:
00272         char m_minVal;
00273         char m_maxVal;
00274         char m_stepSize; // >= 1
00275     };
00276 
00282     class ITOMCOMMON_EXPORT IntMeta : public ParamMeta
00283     {
00284     public:
00286         explicit IntMeta(int minVal, int maxVal, int stepSize=1) : ParamMeta(ParamBase::Int), m_minVal(minVal), m_maxVal(maxVal), m_stepSize(stepSize) { if(m_maxVal < m_minVal) std::swap(m_minVal,m_maxVal); }
00287         static IntMeta* all() { return new IntMeta(std::numeric_limits<int>::min(), std::numeric_limits<int>::max() ); } 
00288         inline int getMin() const { return m_minVal; } 
00289         inline int getMax() const { return m_maxVal; } 
00290         inline int getStepSize() const { return m_stepSize; } 
00291         
00293 
00296         inline void setMin(int val) { m_minVal = val; m_maxVal = std::max(m_maxVal,m_minVal); }
00297         
00299 
00302         inline void setMax(int val) { m_maxVal = val; m_minVal = std::min(m_maxVal,m_minVal); }
00303 
00305 
00308         inline void setStepSize(int val) { m_stepSize = val; }
00309     private:
00310         int m_minVal;
00311         int m_maxVal;
00312         int m_stepSize; // >= 1
00313     };
00314 
00320     class ITOMCOMMON_EXPORT DoubleMeta : public ParamMeta
00321     {
00322     public:
00324         explicit DoubleMeta(double minVal, double maxVal, double stepSize=0.0 /*0.0 means no specific step size*/) : ParamMeta(ParamBase::Double), m_minVal(minVal), m_maxVal(maxVal), m_stepSize(stepSize) { if(m_maxVal < m_minVal) std::swap(m_minVal,m_maxVal); }
00325         static DoubleMeta* all() { return new DoubleMeta(-std::numeric_limits<double>::max(), std::numeric_limits<double>::max() ); } 
00326         inline double getMin() const { return m_minVal; } 
00327         inline double getMax() const { return m_maxVal; } 
00328         inline double getStepSize() const { return m_stepSize; } 
00329         
00331 
00334         inline void setMin(double val) { m_minVal = val; m_maxVal = std::max(m_maxVal,m_minVal); }
00335         
00337 
00340         inline void setMax(double val) { m_maxVal = val; m_minVal = std::min(m_maxVal,m_minVal); }
00341 
00343 
00346         inline void setStepSize(double val) { m_stepSize = val; }
00347     private:
00348         double m_minVal;
00349         double m_maxVal;
00350         double m_stepSize; // >= 0, 0.0 means no specific step size
00351     };
00352 
00358     class ITOMCOMMON_EXPORT HWMeta : public ParamMeta
00359     {
00360         public:
00362 
00368             explicit HWMeta(uint32 minType) : ParamMeta(ParamBase::HWRef), m_minType(minType), m_pHWAddInName(NULL) {}
00369 
00371 
00376             explicit HWMeta(const char *HWAddInName) : ParamMeta(ParamBase::HWRef), m_minType(0), m_pHWAddInName(NULL)
00377             {
00378                 if(HWAddInName) m_pHWAddInName = _strdup(HWAddInName);
00379             }
00380             HWMeta(const HWMeta& cpy) : ParamMeta(ParamBase::HWRef), m_minType(cpy.m_minType), m_pHWAddInName(NULL)
00381             {
00382                 if(cpy.m_pHWAddInName) m_pHWAddInName = _strdup(cpy.m_pHWAddInName);
00383             }
00384             ~HWMeta() { if(m_pHWAddInName) free(m_pHWAddInName); }            
00385             inline uint32 getMinType() const { return m_minType; }                
00386             inline char * getHWAddInName() const { return m_pHWAddInName; } 
00387         private:
00388             uint32 m_minType;            
00389             char *m_pHWAddInName;    
00390     };
00391 
00397     class ITOMCOMMON_EXPORT StringMeta : public ParamMeta
00398     {
00399         public:
00400             enum tType {
00401                 String, 
00402                 Wildcard, 
00403                 RegExp    
00404             };
00405 
00407 
00412             StringMeta(tType type) : ParamMeta(ParamBase::String), m_stringType(type), m_len(0), m_val(NULL) {}
00413 
00415 
00421             StringMeta(tType type, const char* val) : ParamMeta(ParamBase::String), m_stringType(type), m_len(1)
00422             {
00423                 if(val)
00424                 {
00425                     m_val = (char**) calloc(1, sizeof(char*));
00426                     m_val[0] = _strdup(val);
00427                 }
00428                 else
00429                 {
00430                     m_len = 0;
00431                     m_val = NULL;
00432                 }
00433             }
00434 
00436             StringMeta(const StringMeta& cpy) : ParamMeta(ParamBase::String), m_stringType(cpy.m_stringType), m_len(cpy.m_len), m_val(NULL)
00437             {
00438                 if(m_len > 0)
00439                 {
00440                     m_val = (char**) calloc(m_len, sizeof(char*));
00441                     for(int i=0;i<m_len;++i) m_val[i] = _strdup(cpy.m_val[i]);
00442                 }
00443             }
00444 
00446             ~StringMeta()
00447             {
00448                 for(int i=0;i<m_len;++i) free(m_val[i]);
00449                 free(m_val);
00450             }
00451 
00452             inline tType getStringType() const { return m_stringType; } 
00453             inline int getLen() const { return m_len; } 
00454             inline const char* getString(int idx = 0) const { return (idx >= m_len) ? NULL : m_val[idx]; } 
00455             bool addItem(const char *val) 
00456             {
00457                 if(m_val)
00458                 {
00459                     char **m_val_old = m_val;
00460                                         m_val = (char**)realloc(m_val, sizeof(char*) * (++m_len) ); //m_val can change its address. if NULL, reallocation failed and m_val_old still contains old values
00461                                         if (!m_val)
00462                                         {
00463                         m_val = m_val_old;
00464                                                 m_len--; //failed to add new value
00465                         return false;
00466                                         }
00467                 }
00468                 else
00469                 {
00470                     m_val = (char**) calloc(++m_len, sizeof(char*));
00471                 }
00472                 m_val[m_len-1] = _strdup(val);
00473                 return true;
00474             }
00475 
00476             StringMeta & operator += (const char *val)
00477             {
00478                 addItem(val);
00479                 return *this;
00480             }
00481 
00482         private:
00483             tType m_stringType;
00484             int m_len;
00485             char **m_val;
00486     };
00487 
00493     class ITOMCOMMON_EXPORT DObjMeta : public ParamMeta
00494     {
00495         public:
00496             explicit DObjMeta(uint32 allowedTypes = 0xFFFF, int minDim = 0, int maxDim = std::numeric_limits<int>::max()) : ParamMeta(ParamBase::DObjPtr), m_allowedTypes(allowedTypes), m_minDim(minDim), m_maxDim(maxDim) {}
00497             inline int getAllowedTypes() const { return m_allowedTypes; }
00498             inline int getMinDim() const { return m_minDim; } 
00499             inline int getMaxDim() const { return m_maxDim; } 
00500 
00501         private:
00502             uint32 m_allowedTypes;
00503             int m_minDim;
00504             int m_maxDim;
00505     };
00506 
00507 
00508 
00509     //----------------------------------------------------------------------------------------------------------------------------------
00516     class ITOMCOMMON_EXPORT Param : public ParamBase
00517     {
00518         private:
00519             ParamMeta *m_pMeta;
00520             ByteArray m_info;
00521 
00522         public:
00523 
00524             //--------------------------------------------------------------------------------------------
00525             //  CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
00526             //--------------------------------------------------------------------------------------------
00528             Param() : ParamBase(), m_pMeta(NULL), m_info(NULL) {}
00529             Param(const char *name) : ParamBase(name), m_pMeta(NULL), m_info(NULL) {}                         // type-less Param with name only
00530             Param(const char *name, const uint32 type) : ParamBase(name, type), m_pMeta(NULL), m_info(NULL) {}   // constructor with type and name
00531             Param(const char *name, const uint32 type, const char *val, const char *info);                        // constructor with name and type, char val and optional info
00532             Param(const char *name, const uint32 type, const double minVal, const double maxVal, const double val, const char *info); // constructor with name and type, double val, double minVal, double maxVal and optional info
00533             Param(const char *name, const uint32 type, const int minVal, const int maxVal, const int val, const char *info); // constructor with name and type, int val, int minVal, int maxVal and optional info
00534             Param(const char *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
00535             Param(const char *name, const uint32 type, const unsigned int size, const char *values, const char *info);  // array constructor with name and type, size and array
00536             Param(const char *name, const uint32 type, const unsigned int size, const int *values, const char *info);   // array constructor with name and type, size and array
00537             Param(const char *name, const uint32 type, const unsigned int size, const double *values, const char *info);// array constructor with name and type, size and array
00538             Param(const char *name, const uint32 type, const int val, ParamMeta *meta, const char *info);
00539             Param(const char *name, const uint32 type, const double val, ParamMeta *meta, const char *info);
00540             Param(const char *name, const uint32 type, const char val, ParamMeta *meta, const char *info);
00541             Param(const char *name, const uint32 type, const unsigned int size, const double *values, ParamMeta *meta, const char *info);
00542             Param(const char *name, const uint32 type, const unsigned int size, const int *values, ParamMeta *meta, const char *info);
00543             Param(const char *name, const uint32 type, const unsigned int size, const char *values, ParamMeta *meta, const char *info);
00544             ~Param();                        
00545             Param(const Param &copyConstr); 
00546 
00547             //--------------------------------------------------------------------------------------------
00548             //  ASSIGNMENT AND OPERATORS
00549             //--------------------------------------------------------------------------------------------
00550             const Param operator [] (const int num) const;    
00551             Param& operator = (const Param &rhs);             
00552             ito::RetVal copyValueFrom(const ParamBase *rhs);  
00553 
00554             //--------------------------------------------------------------------------------------------
00555             //  SET/GET FURTHER PROPERTIES
00556             //--------------------------------------------------------------------------------------------
00558             inline const char * getInfo(void) const { return m_info.data(); }
00559 
00561             inline void setInfo(const char *info)
00562             {
00563                 m_info = info;
00564             }
00565 
00566             inline const ParamMeta* getMeta(void) const { return m_pMeta; } 
00567             inline ParamMeta* getMeta(void) { return m_pMeta; }                
00568 
00570 
00575             bool setMeta(ParamMeta* meta, bool takeOwnership = false);
00576 
00577             bool copyMetaFrom(const ParamMeta *meta);
00578 
00579             double getMin() const;
00580             double getMax() const;
00581     };
00582 
00583     //---------------------------------------------------------------------------------------------------------------------
00584     template<typename _Tp>
00585     struct ItomParamHelper
00586     {
00587         static ito::RetVal setVal(uint32 type, char *&cVal, int &iVal, double &/*dVal*/, _Tp val, int len = 0)
00588         {
00589             switch (type & paramTypeMask)
00590             {
00591                 case (ito::ParamBase::HWRef & paramTypeMask):
00592                 case (ito::ParamBase::DObjPtr & paramTypeMask):
00593                 case ito::ParamBase::PointCloudPtr & paramTypeMask:
00594                 case ito::ParamBase::PointPtr & paramTypeMask:
00595                 case ito::ParamBase::PolygonMeshPtr & paramTypeMask:
00596 //                case ito::ParamBase::Pointer & paramTypeMask:
00597                     cVal = reinterpret_cast<char*>(val);
00598                     return ito::retOk;
00599 
00600                 case ito::ParamBase::String & paramTypeMask:
00601                     {
00602                         char *cVal_ = cVal;
00603                         if (val)
00604                         {
00605                             cVal = _strdup(const_cast<const char*>((char*)val));
00606                             iVal = static_cast<int>(strlen(cVal));
00607                         }
00608                         else
00609                         {
00610                             cVal = 0;
00611                             iVal = -1;
00612                         }
00613                         if (cVal_)
00614                         {
00615                             free(cVal_);
00616                         }
00617                     }
00618                     return ito::retOk;
00619 
00620                 case ito::ParamBase::CharArray & ito::paramTypeMask:
00621                     {
00622                         char *cVal_ = cVal;
00623                         if ((val) && (len > 0))
00624                         {
00625                             cVal = (char*)malloc(len * sizeof(char));
00626                             memcpy(cVal, val, len * sizeof(char));
00627                             iVal = len;
00628                         }
00629                         else
00630                         {
00631                             cVal = NULL;
00632                             iVal = -1;
00633                         }
00634                         if (cVal_)
00635                         {
00636                             free(cVal_);
00637                         }
00638                     }
00639                     return ito::retOk;
00640 
00641                 case ito::ParamBase::IntArray & ito::paramTypeMask:
00642                     {
00643                         char *cVal_ = cVal;
00644                         if ((val) && (len > 0))
00645                         {
00646                             cVal = (char*)malloc(len * sizeof(int));
00647                             memcpy(cVal, val, len * sizeof(int));
00648                             iVal = len;
00649                         }
00650                         else
00651                         {
00652                             cVal = NULL;
00653                             iVal = -1;
00654                         }
00655                         if (cVal_)
00656                         {
00657                             free(cVal_);
00658                         }
00659                     }
00660                     return ito::retOk;
00661 
00662                 case ito::ParamBase::DoubleArray & ito::paramTypeMask:
00663                     {
00664                         char *cVal_ = cVal;
00665                         if ((val) && (len > 0))
00666                         {
00667                             cVal = (char*)malloc(len * sizeof(double));
00668                             memcpy(cVal, val, len * sizeof(double));
00669                             iVal = len;
00670                         }
00671                         else
00672                         {
00673                             cVal = NULL;
00674                             iVal = -1;
00675                         }
00676                         if (cVal_)
00677                         {
00678                             free(cVal_);
00679                         }
00680                     }
00681                     return ito::retOk;
00682 
00683                 default:
00684                     return ito::retError;
00685             }
00686         }
00687 
00688         static _Tp getVal(const uint32 type, const char *cVal, const int &iVal, const double &/*dVal*/, int &len)
00689         {
00690             switch (type & paramTypeMask)
00691             {
00692                 case ito::ParamBase::String & paramTypeMask:
00693                     if (cVal)
00694                     {
00695                         len = static_cast<int>(strlen(cVal));
00696                         //return reinterpret_cast<_Tp>(_strdup(cVal));
00697                         return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
00698                     }
00699                     else
00700                     {
00701                         len = 0;
00702                         return 0;
00703                     }
00704 
00705                 case ito::ParamBase::CharArray & ito::paramTypeMask:
00706                 case ito::ParamBase::IntArray & ito::paramTypeMask:
00707                 case ito::ParamBase::DoubleArray & ito::paramTypeMask:
00708                     if (cVal)
00709                     {
00710                         len = iVal;
00711                         return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
00712                     }
00713                     else
00714                     {
00715                         len = 0;
00716                         return 0;
00717                     }
00718 
00719                 case (ito::ParamBase::HWRef & paramTypeMask):
00720                 case (ito::ParamBase::DObjPtr & paramTypeMask):
00721                 case ito::ParamBase::PointCloudPtr & paramTypeMask:
00722                 case ito::ParamBase::PointPtr & paramTypeMask:
00723                 case ito::ParamBase::PolygonMeshPtr & paramTypeMask:
00724                     return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
00725 
00726                 default:
00727                     throw std::logic_error("Param::getVal<_Tp>: Non-matching type!");
00728                     return (_Tp)0;
00729             }
00730         }
00731     };
00732 
00733     template<>
00734     struct ItomParamHelper<double>
00735     {
00736         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int &iVal, double &dVal, double val, int /*len = 0*/)
00737         {
00738             switch (type & paramTypeMask)
00739             {
00740                 case ito::ParamBase::Double & ito::paramTypeMask:
00741                     dVal = static_cast<double>(val);
00742                     return ito::retOk;
00743 
00744                 case ito::ParamBase::Int & ito::paramTypeMask:
00745                 case ito::ParamBase::Char & ito::paramTypeMask:
00746                     iVal = static_cast<int>(val);
00747                     return ito::retOk;
00748 
00749                 default:
00750                     return ito::retError;
00751             }
00752         }
00753 
00754         static double getVal(const uint32 type, const char * /*cVal*/, const int &iVal, const double &dVal, int & /*len*/)
00755         {
00756             switch (type & paramTypeMask)
00757             {
00758                 case ito::ParamBase::Int & ito::paramTypeMask:
00759                 case ito::ParamBase::Char & ito::paramTypeMask:
00760                     return static_cast<double>(iVal);
00761 
00762                 case ito::ParamBase::Double & ito::paramTypeMask:
00763                     return dVal;
00764 
00765                 default:
00766                     throw std::logic_error("Param::getVal<double>: Non-matching type!");
00767                     return 0;
00768             }
00769         }
00770     };
00771 
00772     template<>
00773     struct ItomParamHelper<int>
00774     {
00775         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int &iVal, double &dVal, int val, int /*len = 0*/)
00776         {
00777             switch (type & paramTypeMask)
00778             {
00779                 case ito::ParamBase::Double & ito::paramTypeMask:
00780                     dVal = static_cast<int>(val);
00781                     return ito::retOk;
00782 
00783                 case ito::ParamBase::Int & ito::paramTypeMask:
00784                 case ito::ParamBase::Char & ito::paramTypeMask:
00785                     iVal = val;
00786                     return ito::retOk;
00787 
00788                 default:
00789                     return ito::retError;
00790             }
00791         }
00792 
00793         static int getVal(const uint32 type, const char * /*cVal*/, const int &iVal, const double &dVal, int & /*len*/)
00794         {
00795             switch (type & paramTypeMask)
00796             {
00797                 case ito::ParamBase::Int & ito::paramTypeMask:
00798                 case ito::ParamBase::Char & ito::paramTypeMask:
00799                     return iVal;
00800 
00801                 case ito::ParamBase::Double & ito::paramTypeMask:
00802                     return static_cast<int>(dVal);
00803 
00804                 case 0:
00805                     throw std::invalid_argument("Param::getVal<int>: non existent parameter");
00806                     return 0;
00807 
00808                 default:
00809                     throw std::logic_error("Param::getVal<int>: Non-matching type!");
00810                     return 0;
00811             }
00812         }
00813     };
00814 
00815     template<>
00816     struct ItomParamHelper<char>
00817     {
00818         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int &iVal, double &dVal, char val, int /*len = 0*/)
00819         {
00820             switch (type & paramTypeMask)
00821             {
00822                 case ito::ParamBase::Double & ito::paramTypeMask:
00823                     dVal = static_cast<char>(val);
00824                     return ito::retOk;
00825 
00826                 case ito::ParamBase::Int & ito::paramTypeMask:
00827                 case ito::ParamBase::Char & ito::paramTypeMask:
00828                     iVal = static_cast<char>(val);
00829                     return ito::retOk;
00830 
00831                 default:
00832                     return ito::retError;
00833             }
00834         }
00835 
00836         static char getVal(const uint32 type, const char * /*cVal*/, const int &iVal, const double &dVal, int & /*len*/)
00837         {
00838             switch (type & paramTypeMask)
00839             {
00840                 case ito::ParamBase::Int & ito::paramTypeMask:
00841                 case ito::ParamBase::Char & ito::paramTypeMask:
00842                     return static_cast<char>(iVal);
00843 
00844                 case ito::ParamBase::Double & ito::paramTypeMask:
00845                     return static_cast<char>(dVal);
00846 
00847                 case 0:
00848                     throw std::invalid_argument("Param::getVal<char>: non existent parameter");
00849                     return 0;
00850 
00851                 default:
00852                     throw std::logic_error("Param::getVal<char>: Non-matching type!");
00853                     return 0;
00854             }
00855         }
00856     };
00857 
00858     template<>
00859     struct ItomParamHelper<unsigned char>
00860     {
00861         static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int &iVal, double &dVal, char val, int /*len = 0*/)
00862         {
00863             switch (type & paramTypeMask)
00864             {
00865                 case ito::ParamBase::Double & ito::paramTypeMask:
00866                     dVal = static_cast<unsigned char>(val);
00867                     return ito::retOk;
00868 
00869                 case ito::ParamBase::Int & ito::paramTypeMask:
00870                 case ito::ParamBase::Char & ito::paramTypeMask:
00871                     iVal = static_cast<unsigned char>(val);
00872                     return ito::retOk;
00873 
00874                 default:
00875                     return ito::retError;
00876             }
00877         }
00878 
00879         static char getVal(const uint32 type, const char * /*cVal*/, const int &iVal, const double &dVal, int & /*len*/)
00880         {
00881             switch (type & paramTypeMask)
00882             {
00883                 case ito::ParamBase::Int & ito::paramTypeMask:
00884                 case ito::ParamBase::Char & ito::paramTypeMask:
00885                     return static_cast<unsigned char>(iVal);
00886 
00887                 case ito::ParamBase::Double & ito::paramTypeMask:
00888                     return static_cast<unsigned char>(dVal);
00889 
00890                 case 0:
00891                     throw std::invalid_argument("Param::getVal<uchar>: non existent parameter");
00892                     return 0;
00893 
00894                 default:
00895                     throw std::logic_error("Param::getVal<uchar>: Non-matching type!");
00896                     return 0;
00897             }
00898         }
00899     };
00900 
00901 } //end namespace ito
00902 
00903 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends