itom  4.1.0
param.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 *********************************************************************** */
27 
28 #ifndef PARAM_H
29 #define PARAM_H
30 
31 /* includes */
32 
33 #include "commonGlobal.h"
34 #include "typeDefs.h"
35 #include "byteArray.h"
36 #include "retVal.h"
37 #include "paramMeta.h"
38 
39 #include <string.h>
40 #include <stdlib.h>
41 #include <stdio.h>
42 #include <stdarg.h>
43 #include <limits>
44 #include <stdexcept>
45 
46 /* definition and macros */
47 /* global variables (avoid) */
48 /* content */
49 
50 namespace ito
51 {
52  class Param;
53  class ParamHelper;
54  template<typename _Tp> struct ItomParamHelper;
55 
56  const uint32 paramFlagMask = 0xFFFF0000;
57  const uint32 paramTypeMask = 0x0000FFFF;
58 
60  struct ITOMCOMMON_EXPORT complex128_
61  {
62  complex128_(float64 r, float64 i) : real(r), imag(i) {};
63  float64 real;
64  float64 imag;
65  };
66 
67  class ITOMCOMMON_EXPORT ParamBase
68  {
69  protected:
70  uint32 m_type;
72 
73  void inOutCheck();
74 
75  static inline uint32 typeFilter(uint32 type) { return type & paramTypeMask; }
76 
77  private:
79  ito::int32 m_iVal;
80  char *m_cVal;
81 
82  public:
83  enum Type {
85 
86  /* If this bit is set, this parameter should be automatically
87  stored if for instance a plugin is closed and if the plugin
88  with the same identifier is opened again, the parameter
89  value will be tried to be reconstructed from the stored value. */
90  NoAutosave = 0x010000,
91 
92  /* Flag to define this parameter to be readonly. It cannot for instance not be changed
93  from Python. Internally, the setVal method does not check for Readonly.
94  This has to be programmed manually. Plugins can also set or unset this flag
95  during the runtime. */
96  Readonly = 0x020000,
97 
98  /* Flag to mark this parameter as input value only.
99  If a plugin defines this flag without the Out-flag, it pretends
100  to only consume the given value, but the consumer will not change the value at any time.
101  If the Out-flag is set, too, the consumer (e.g. plugin) will read and write the
102  value, such that for instance a given dataObject will have another content after having
103  called a method of a plugin. Return parameters of a method must never have the In-flag set. */
104  In = 0x040000,
105 
106  /* Flag to mark this parameter, that the consumer will create or change
107  the value of this parameter.
108  This can be set together with In (or alone). All return parameters of an method in
109  an algorithm plugin, must have this flag set. For other mandatory or optional
110  input parameter, this flag can only be set together with In and means then,
111  that the content of the given parameter will be changed by the called method. */
112  Out = 0x080000,
113 
114  /* Flag to mark a parameter to be temporarily not available.
115  Plugins can also set or unset this flag
116  during the runtime. */
117  NotAvailable = 0x100000,
118 
120 
121  /* Helper-bit for all types that only contain a pointer to the real value and
122  not the value itself. For these types, the caller need to keep the pointed object
123  until both caller and called method do not use it any more! */
124  Pointer = 0x000001,
125  Char = 0x000002,
126  Int = 0x000004,
127  Double = 0x000008,
128  Complex = 0x000400,
129  DObjPtr = 0x000010 | Pointer | NoAutosave,
130  String = 0x000020 | Pointer,
131  HWRef = 0x000040 | Pointer | NoAutosave,
132  CharArray = Char | Pointer,
133  IntArray = Int | Pointer,
134  DoubleArray = Double | Pointer,
135  ComplexArray = Complex | Pointer,
136  PointCloudPtr = 0x000080 | Pointer | NoAutosave,
137  PointPtr = 0x000100 | Pointer | NoAutosave,
138  PolygonMeshPtr = 0x000200 | Pointer | NoAutosave
139  };
140 
141 
142  //--------------------------------------------------------------------------------------------
143  // CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
144  //--------------------------------------------------------------------------------------------
146  ParamBase() : m_type(0), m_name(NULL), m_dVal(0.0, 0.0), m_iVal(0), m_cVal(NULL) {}
147  ParamBase(const ByteArray &name); // type-less ParamBase with name only
148  ParamBase(const ByteArray &name, const uint32 type); // constructor with type and name
149  ParamBase(const ByteArray &name, const uint32 type, const char *val); // constructor with name and type and char val
150  ParamBase(const ByteArray &name, const uint32 type, const float64 val); // constructor with name and type and float64 val
151  ParamBase(const ByteArray &name, const uint32 type, const int32 val); // constructor with name and type and int32 val
152  ParamBase(const ByteArray &name, const uint32 type, const complex128 val); // constructor with name and type and complex128 val
153  ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const char *values); // array constructor with name and type, size and array
154  ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const int32 *values); // array constructor with name and type, size and array
155  ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const float64 *values); // array constructor with name and type, size and array
156  ParamBase(const ByteArray &name, const uint32 type, const uint32 size, const complex128 *values); // array constructor with name and type, size and array
157  virtual ~ParamBase(); //Destructor
158  ParamBase(const ParamBase &copyConstr); //Copy-Constructor
159 
160  //--------------------------------------------------------------------------------------------
161  // ASSIGNMENT AND OPERATORS
162  //--------------------------------------------------------------------------------------------
163  const ParamBase operator [] (const int num) const;
164  ParamBase& operator = (const ParamBase &rhs);
165  ito::RetVal copyValueFrom(const ito::ParamBase *rhs);
166 
167  //--------------------------------------------------------------------------------------------
168  // COMPARISON OPERATORS (two values are equal if both their type and the content is equal)
169  //--------------------------------------------------------------------------------------------
170  bool operator ==(const ParamBase &rhs) const;
171 
172  inline bool operator !=(const ParamBase &rhs) const
173  {
174  return !(*this == rhs);
175  }
176 
177  //--------------------------------------------------------------------------------------------
178  // SET/GET FURTHER PROPERTIES
179  //--------------------------------------------------------------------------------------------
180 
182  inline bool isNumeric(void) const
183  {
184  static int numericTypeMask = ito::ParamBase::Char | ParamBase::Int | ParamBase::Double | ParamBase::Complex;
185  return ((m_type & numericTypeMask) > 0) && !(m_type & ito::ParamBase::Pointer);
186  }
187 
189  inline bool isNumericArray(void) const
190  {
191  static int numericTypeMask = ito::ParamBase::Char | ParamBase::Int | ParamBase::Double | ParamBase::Complex;
192  return (m_type & (numericTypeMask | ito::ParamBase::Pointer)) > 0;
193  }
194 
196  inline bool isValid(void) const { return m_type != 0; }
197 
199  inline uint32 getType(bool filterFlags = true) const
200  {
201  if (filterFlags)
202  return m_type & paramTypeMask;
203  else
204  return m_type;
205  }
206 
208  inline uint32 getFlags(void) const { return m_type & paramFlagMask; }
209 
211  inline void setFlags(const uint32 flags) { m_type = getType() | (flags & paramFlagMask); }
212 
214  inline const char* getName(void) const { return m_name.data(); }
215 
218  inline bool getAutosave(void) const { return (m_type & NoAutosave) > 0; }
219 
222  inline void setAutosave(const bool autosave) { m_type = autosave ? (m_type | NoAutosave) : (m_type & ~NoAutosave); }
223 
225  int getLen(void) const;
226 
227 
234  template<typename _Tp> inline ito::RetVal setVal(_Tp val)
235  {
236  return ItomParamHelper<_Tp>::setVal(getType(), m_cVal, m_iVal, m_dVal, val, 0);
237  }
238 
246  template<typename _Tp> inline ito::RetVal setVal(_Tp val, int len)
247  {
248  return ItomParamHelper<_Tp>::setVal(getType(), m_cVal, m_iVal, m_dVal, val, len);
249  }
250 
257  template<typename _Tp> inline _Tp getVal(void) const
258  {
259  int len = 0;
260  return ItomParamHelper<_Tp>::getVal(getType(), m_cVal, m_iVal, m_dVal, len);
261  }
262 
269  template<typename _Tp> inline _Tp getVal(int &len) const
270  {
271  return ItomParamHelper<_Tp>::getVal(getType(), m_cVal, m_iVal, m_dVal, len);
272  }
273 
274  };
275 
276  //----------------------------------------------------------------------------------------------------------------------------------
283  class ITOMCOMMON_EXPORT Param : public ParamBase
284  {
285  private:
286  ParamMeta *m_pMeta;
287  ByteArray m_info;
288 
289  public:
290 
291  //--------------------------------------------------------------------------------------------
292  // CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
293  //--------------------------------------------------------------------------------------------
295  /*
296  This parameter has no documentation string and no meta information.
297  The type is 0 (invalid).
298  The name is empty.
299  */
300  Param() : ParamBase(), m_pMeta(NULL), m_info(NULL) {}
301 
303  /*
304  This parameter has no documentation string and no meta information.
305  The type is 0 (invalid).
306 
307  \param name is the name of the parameter
308  */
309  Param(const ByteArray &name) : ParamBase(name), m_pMeta(NULL), m_info(NULL) {}
310 
312  /*
313  This parameter has no documentation string and no meta information.
314 
315  \param name is the name of the parameter
316  \type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
317  e.g. ito::ParamBase::Char | ito::ParamBase::In for a read-only input parameter
318  */
319  Param(const ByteArray &name, const uint32 type) : ParamBase(name, type), m_pMeta(NULL), m_info(NULL) {}
320 
322  /*
323  This parameter has no meta information. They can be added using setMetaInfo.
324 
325  \param name is the name of the parameter
326  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
327  e.g. ito::ParamBase::String | ito::ParamBase::In for a read-only input parameter
328  \param val is the default string (const char*) of this parameter
329  \param info can be a documentation string for this parameter, an empty string or NULL
330  */
331  Param(const ByteArray &name, const uint32 type, const char *val, const char *info);
332 
334  /*
335  This parameter will automatically get meta information of type ito::CharMeta with a minimum and maximum value.
336 
337  \param name is the name of the parameter
338  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
339  e.g. ito::ParamBase::Char | ito::ParamBase::In for a read-only input parameter
340  \param minVal is the minimum allowed value (added to meta information)
341  \param maxVal is the maximum allowed value (added to meta information)
342  \param val is the default int8 value
343  \param info can be a documentation string for this parameter, an empty string or NULL
344  */
345  Param(const ByteArray &name, const uint32 type, const char minVal, const char maxVal, const char val, const char *info);
346 
348  /*
349  This parameter will automatically get meta information of type ito::IntMeta with a minimum and maximum value.
350 
351  \param name is the name of the parameter
352  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
353  e.g. ito::ParamBase::Int | ito::ParamBase::In for a read-only input parameter
354  \param minVal is the minimum allowed value (added to meta information)
355  \param maxVal is the maximum allowed value (added to meta information)
356  \param val is the default int32 value
357  \param info can be a documentation string for this parameter, an empty string or NULL
358  */
359  Param(const ByteArray &name, const uint32 type, const int32 minVal, const int32 maxVal, const int32 val, const char *info);
360 
362  /*
363  This parameter will automatically get meta information of type ito::DoubleMeta with a minimum and maximum value.
364 
365  \param name is the name of the parameter
366  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
367  e.g. ito::ParamBase::Double | ito::ParamBase::In for a read-only input parameter
368  \param minVal is the minimum allowed value (added to meta information)
369  \param maxVal is the maximum allowed value (added to meta information)
370  \param val is the default float64 value
371  \param info can be a documentation string for this parameter, an empty string or NULL
372  */
373  Param(const ByteArray &name, const uint32 type, const float64 minVal, const float64 maxVal, const float64 val, const char *info);
374 
376  /*
377  This parameter has no meta information. They can be added using setMetaInfo.
378 
379  \param name is the name of the parameter
380  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
381  e.g. ito::ParamBase::CharArray | ito::ParamBase::In for a read-only input parameter
382  \param size is the size of the given default values array
383  \param values is the default int8 array value
384  \param info can be a documentation string for this parameter, an empty string or NULL
385  */
386  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
387 
389  /*
390  This parameter has no meta information. They can be added using setMetaInfo.
391 
392  \param name is the name of the parameter
393  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
394  e.g. ito::ParamBase::IntArray | ito::ParamBase::In for a read-only input parameter
395  \param size is the size of the given default values array
396  \param values is the default int32 array value
397  \param info can be a documentation string for this parameter, an empty string or NULL
398  */
399  Param(const ByteArray &name, const uint32 type, const unsigned int size, const int32 *values, const char *info);
400 
402  /*
403  This parameter has no meta information. They can be added using setMetaInfo.
404 
405  \param name is the name of the parameter
406  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
407  e.g. ito::ParamBase::DoubleArray | ito::ParamBase::In for a read-only input parameter
408  \param size is the size of the given default values array
409  \param values is the default float64 array value
410  \param info can be a documentation string for this parameter, an empty string or NULL
411  */
412  Param(const ByteArray &name, const uint32 type, const unsigned int size, const float64 *values, const char *info);
413 
415  /*
416  This parameter has no meta information.
417 
418  \param name is the name of the parameter
419  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
420  e.g. ito::ParamBase::ComplexArray | ito::ParamBase::In for a read-only input parameter
421  \param size is the size of the given default values array
422  \param values is the default complex array value
423  \param info can be a documentation string for this parameter, an empty string or NULL
424  */
425  Param(const ByteArray &name, const uint32 type, const unsigned int size, const complex128 *values, const char *info);
426 
428  /*
429  \param name is the name of the parameter
430  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
431  e.g. ito::ParamBase::Char | ito::ParamBase::In for a read-only input parameter
432  \param val is the default value
433  \param meta might me NULL, if no meta information should be passed to this parameter.
434  If a pointer is given, it has to be an object of ito::CharMeta.
435  The ownership is taken by this parameter!
436  \param info can be a documentation string for this parameter, an empty string or NULL
437  */
438  Param(const ByteArray &name, const uint32 type, const char val, ParamMeta *meta, const char *info);
439 
441  /*
442  \param name is the name of the parameter
443  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
444  e.g. ito::ParamBase::Int | ito::ParamBase::In for a read-only input parameter
445  \param val is the default value
446  \param meta might me NULL, if no meta information should be passed to this parameter.
447  If a pointer is given, it has to be an object of ito::IntMeta.
448  The ownership is taken by this parameter!
449  \param info can be a documentation string for this parameter, an empty string or NULL
450  */
451  Param(const ByteArray &name, const uint32 type, const int32 val, ParamMeta *meta, const char *info);
452 
454  /*
455  \param name is the name of the parameter
456  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
457  e.g. ito::ParamBase::Double | ito::ParamBase::In for a read-only input parameter
458  \param val is the default value
459  \param meta might me NULL, if no meta information should be passed to this parameter.
460  If a pointer is given, it has to be an object of ito::DoubleMeta.
461  The ownership is taken by this parameter!
462  \param info can be a documentation string for this parameter, an empty string or NULL
463  */
464  Param(const ByteArray &name, const uint32 type, const float64 val, ParamMeta *meta, const char *info);
465 
467  /*
468  \param name is the name of the parameter
469  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
470  e.g. ito::ParamBase::Complex | ito::ParamBase::In for a read-only input parameter
471  \param val is the default value
472  \param meta might me NULL, if no meta information should be passed to this parameter.
473  Currently, there is no meta information class for complex value parameters!
474  \param info can be a documentation string for this parameter, an empty string or NULL
475  */
476  Param(const ByteArray &name, const uint32 type, const complex128 val, ParamMeta *meta, const char *info);
477 
479  /*
480  \param name is the name of the parameter
481  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
482  e.g. ito::ParamBase::CharArray | ito::ParamBase::In for a read-only input parameter
483  \param size is the length of the default array, passed to values
484  \param values is the pointer to the default array of values
485  \param meta might me NULL, if no meta information should be passed to this parameter.
486  If a pointer is given, it has to be an object of ito::CharArrayMeta.
487  The ownership is taken by this parameter!
488  \param info can be a documentation string for this parameter, an empty string or NULL
489  */
490  Param(const ByteArray &name, const uint32 type, const unsigned int size, const char *values, ParamMeta *meta, const char *info);
491 
493  /*
494  \param name is the name of the parameter
495  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
496  e.g. ito::ParamBase::IntArray | ito::ParamBase::In for a read-only input parameter
497  \param size is the length of the default array, passed to values
498  \param values is the pointer to the default array of values
499  \param meta might me NULL, if no meta information should be passed to this parameter.
500  If a pointer is given, it has to be an object of ito::IntArrayMeta, ito::IntervalMeta,
501  ito::RangeMeta or ito::RectMeta.
502  The ownership is taken by this parameter!
503  \param info can be a documentation string for this parameter, an empty string or NULL
504  */
505  Param(const ByteArray &name, const uint32 type, const unsigned int size, const int32 *values, ParamMeta *meta, const char *info);
506 
508  /*
509  \param name is the name of the parameter
510  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
511  e.g. ito::ParamBase::DoubleArray | ito::ParamBase::In for a read-only input parameter
512  \param size is the length of the default array, passed to values
513  \param values is the pointer to the default array of values
514  \param meta might me NULL, if no meta information should be passed to this parameter.
515  If a pointer is given, it has to be an object of ito::DoubleArrayMeta or ito::DoubleIntervalMeta.
516  The ownership is taken by this parameter!
517  \param info can be a documentation string for this parameter, an empty string or NULL
518  */
519  Param(const ByteArray &name, const uint32 type, const unsigned int size, const float64 *values, ParamMeta *meta, const char *info);
520 
522  /*
523  \param name is the name of the parameter
524  \param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
525  e.g. ito::ParamBase::ComplexArray | ito::ParamBase::In for a read-only input parameter
526  \param size is the length of the default array, passed to values
527  \param values is the pointer to the default array of values
528  \param meta might me NULL, if no meta information should be passed to this parameter.
529  If a pointer is given, the ownership is taken by this parameter!
530  Currently, there is no meta information class available for complex array parameters!
531  \param info can be a documentation string for this parameter, an empty string or NULL
532  */
533  Param(const ByteArray &name, const uint32 type, const unsigned int size, const complex128 *values, ParamMeta *meta, const char *info);
534 
536  ~Param();
537 
539  Param(const Param &copyConstr);
540 
541  //--------------------------------------------------------------------------------------------
542  // ASSIGNMENT AND OPERATORS
543  //--------------------------------------------------------------------------------------------
544  const Param operator [] (const int num) const;
545  Param& operator = (const Param &rhs);
546  ito::RetVal copyValueFrom(const ParamBase *rhs);
547 
548  //--------------------------------------------------------------------------------------------
549  // SET/GET FURTHER PROPERTIES
550  //--------------------------------------------------------------------------------------------
552  inline const char * getInfo(void) const { return m_info.data(); }
553 
555  inline void setInfo(const char *info)
556  {
557  m_info = info;
558  }
559 
560  inline void setInfo(const ByteArray &info)
561  {
562  m_info = info;
563  }
564 
565  inline const ParamMeta* getMeta(void) const { return m_pMeta; }
566  inline ParamMeta* getMeta(void) { return m_pMeta; }
567 
569  /*
570  Example: intParam.getMetaT<ito::IntMeta>();
571  */
572  template<typename _Tp> inline const _Tp* getMetaT(void) const
573  {
574  return static_cast<const _Tp*>(m_pMeta);
575  }
576 
578  /*
579  Example: intParam.getMetaT<ito::IntMeta>();
580  */
581  template<typename _Tp> inline _Tp* getMetaT(void)
582  {
583  return static_cast<_Tp*>(m_pMeta);
584  }
585 
587 
592  void setMeta(ParamMeta* meta, bool takeOwnership = false);
593 
594  float64 getMin() const;
595  float64 getMax() const;
596  };
597 
598  //---------------------------------------------------------------------------------------------------------------------
599  template<typename _Tp>
600  struct ItomParamHelper
601  {
602  static ito::RetVal setVal(uint32 type, char *&cVal, int32 &iVal, complex128_ &/*dVal*/, const _Tp val, int len = 0)
603  {
604  switch (type & paramTypeMask)
605  {
606  case (ito::ParamBase::HWRef & paramTypeMask):
607  case (ito::ParamBase::DObjPtr & paramTypeMask):
608  case ito::ParamBase::PointCloudPtr & paramTypeMask:
609  case ito::ParamBase::PointPtr & paramTypeMask:
610  case ito::ParamBase::PolygonMeshPtr & paramTypeMask:
611 // case ito::ParamBase::Pointer & paramTypeMask:
612  cVal = (char*)(reinterpret_cast<const char*>(val));
613  return ito::retOk;
614 
615  case ito::ParamBase::String & paramTypeMask:
616  {
617  char *cVal_ = cVal;
618  if (val)
619  {
620  cVal = _strdup((const char*)val);
621  iVal = static_cast<int>(strlen(cVal));
622  }
623  else
624  {
625  cVal = 0;
626  iVal = -1;
627  }
628  if (cVal_)
629  {
630  free(cVal_);
631  }
632  }
633  return ito::retOk;
634 
636  {
637  char *cVal_ = cVal;
638  if ((val) && (len > 0))
639  {
640  cVal = (char*)malloc(len * sizeof(char));
641  memcpy(cVal, val, len * sizeof(char));
642  iVal = len;
643  }
644  else
645  {
646  cVal = NULL;
647  iVal = -1;
648  }
649  if (cVal_)
650  {
651  free(cVal_);
652  }
653  }
654  return ito::retOk;
655 
657  {
658  char *cVal_ = cVal;
659  if ((val) && (len > 0))
660  {
661  cVal = (char*)malloc(len * sizeof(ito::int32));
662  memcpy(cVal, val, len * sizeof(ito::int32));
663  iVal = len;
664  }
665  else
666  {
667  cVal = NULL;
668  iVal = -1;
669  }
670  if (cVal_)
671  {
672  free(cVal_);
673  }
674  }
675  return ito::retOk;
676 
678  {
679  char *cVal_ = cVal;
680  if ((val) && (len > 0))
681  {
682  cVal = (char*)malloc(len * sizeof(ito::float64));
683  memcpy(cVal, val, len * sizeof(ito::float64));
684  iVal = len;
685  }
686  else
687  {
688  cVal = NULL;
689  iVal = -1;
690  }
691  if (cVal_)
692  {
693  free(cVal_);
694  }
695  }
696  return ito::retOk;
697 
699  {
700  char *cVal_ = cVal;
701  if ((val) && (len > 0))
702  {
703  cVal = (char*)malloc(len * sizeof(ito::complex128));
704  memcpy(cVal, val, len * sizeof(ito::complex128));
705  iVal = len;
706  }
707  else
708  {
709  cVal = NULL;
710  iVal = -1;
711  }
712  if (cVal_)
713  {
714  free(cVal_);
715  }
716  }
717  return ito::retOk;
718 
719  default:
720  return ito::RetVal(ito::retError, 0, "_Tp parameter of setVal<_Tp> does not match the type of the parameter");
721  }
722  }
723 
724  static _Tp getVal(const uint32 type, const char *cVal, const int32 &iVal, const complex128_ &/*dVal*/, int &len)
725  {
726  switch (type & paramTypeMask)
727  {
728  case ito::ParamBase::String & paramTypeMask:
729  if (cVal)
730  {
731  len = static_cast<int>(strlen(cVal));
732  return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
733  }
734  else
735  {
736  len = 0;
737  return 0;
738  }
739 
744  if (cVal)
745  {
746  len = iVal;
747  return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
748  }
749  else
750  {
751  len = 0;
752  return 0;
753  }
754 
755  case (ito::ParamBase::HWRef & paramTypeMask):
756  case (ito::ParamBase::DObjPtr & paramTypeMask):
757  case ito::ParamBase::PointCloudPtr & paramTypeMask:
758  case ito::ParamBase::PointPtr & paramTypeMask:
759  case ito::ParamBase::PolygonMeshPtr & paramTypeMask:
760  return reinterpret_cast<_Tp>(const_cast<char*>(cVal));
761 
762  default:
763  throw std::logic_error("Param::getVal<_Tp>: Non-matching type!");
764  }
765  }
766  };
767 
768  template<>
769  struct ItomParamHelper<float64>
770  {
771  static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, float64 val, int /*len = 0*/)
772  {
773  switch (type & paramTypeMask)
774  {
777  dVal.real = static_cast<float64>(val);
778  dVal.imag = 0.0;
779  return ito::retOk;
780 
783  iVal = static_cast<int32>(val);
784  return ito::retOk;
785 
786  default:
787  return ito::RetVal(ito::retError, 0, "float64 value passed to setVal<float64> does not match the type of the parameter");
788  }
789  }
790 
791  static float64 getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
792  {
793  switch (type & paramTypeMask)
794  {
797  return static_cast<float64>(iVal);
798 
801  return dVal.real;
802 
803  default:
804  throw std::logic_error("Param::getVal<float64>: Non-matching type!");
805  }
806  }
807  };
808 
809  template<>
810  struct ItomParamHelper<int32>
811  {
812  static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, int32 val, int /*len = 0*/)
813  {
814  switch (type & paramTypeMask)
815  {
818  dVal.real = static_cast<float64>(val);
819  dVal.imag = 0.0;
820  return ito::retOk;
821 
824  iVal = val;
825  return ito::retOk;
826 
827  default:
828  return ito::RetVal(ito::retError, 0, "int32 value passed to setVal<int32> does not match the type of the parameter");
829  }
830  }
831 
832  static int32 getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
833  {
834  switch (type & paramTypeMask)
835  {
838  return iVal;
839 
842  return static_cast<int32>(dVal.real);
843 
844  case 0:
845  throw std::invalid_argument("Param::getVal<int32>: non existent parameter");
846 
847  default:
848  throw std::logic_error("Param::getVal<int32>: Non-matching type!");
849  }
850  }
851  };
852 
853  template<>
854  struct ItomParamHelper<char>
855  {
856  static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, char val, int /*len = 0*/)
857  {
858  switch (type & paramTypeMask)
859  {
862  dVal.real = static_cast<float64>(val);
863  dVal.imag = 0.0;
864  return ito::retOk;
865 
868  iVal = static_cast<char>(val);
869  return ito::retOk;
870 
871  default:
872  return ito::RetVal(ito::retError, 0, "char value passed to setVal<char> does not match the type of the parameter");
873  }
874  }
875 
876  static char getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
877  {
878  switch (type & paramTypeMask)
879  {
882  return static_cast<char>(iVal);
883 
886  return static_cast<char>(dVal.real);
887 
888  case 0:
889  throw std::invalid_argument("Param::getVal<char>: non existent parameter");
890 
891  default:
892  throw std::logic_error("Param::getVal<char>: Non-matching type!");
893  }
894  }
895  };
896 
897  template<>
898  struct ItomParamHelper<unsigned char>
899  {
900  static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, char val, int /*len = 0*/)
901  {
902  switch (type & paramTypeMask)
903  {
906  dVal.real = static_cast<float64>(val);
907  dVal.imag = 0.0;
908  return ito::retOk;
909 
912  iVal = static_cast<unsigned char>(val);
913  return ito::retOk;
914 
915  default:
916  return ito::RetVal(ito::retError, 0, "unsigned char value passed to setVal<unsigned char> does not match the type of the parameter");
917  }
918  }
919 
920  static char getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
921  {
922  switch (type & paramTypeMask)
923  {
926  return static_cast<unsigned char>(iVal);
927 
930  return static_cast<unsigned char>(dVal.real);
931 
932  case 0:
933  throw std::invalid_argument("Param::getVal<uchar>: non existent parameter");
934 
935  default:
936  throw std::logic_error("Param::getVal<uchar>: Non-matching type!");
937  }
938  }
939  };
940 
941  template<>
942  struct ItomParamHelper<complex128>
943  {
944  static ito::RetVal setVal(uint32 type, char *&/*cVal*/, int32 &iVal, complex128_ &dVal, complex128 val, int /*len = 0*/)
945  {
946  switch (type & paramTypeMask)
947  {
949  dVal.real = val.real();
950  dVal.imag = val.imag();
951  return ito::retOk;
952 
953  default:
954  return ito::RetVal(ito::retError, 0, "complex128 value passed to setVal<complex128> does not match the type of the parameter");
955  }
956  }
957 
958  static complex128 getVal(const uint32 type, const char * /*cVal*/, const int32 &iVal, const complex128_ &dVal, int & /*len*/)
959  {
960  switch (type & paramTypeMask)
961  {
964  return complex128(iVal, 0.0);
965 
967  return complex128(dVal.real, dVal.imag);
968 
970  return dVal.real;
971 
972  default:
973  throw std::logic_error("Param::getVal<complex128>: Non-matching type!");
974  }
975  }
976  };
977 
978 } //end namespace ito
979 
980 #endif
array of complex numbers
Definition: param.h:135
bool isNumericArray(void) const
returns true if Param is of type char array, int array, double array or complex array ...
Definition: param.h:189
complex128_ m_dVal
internal value for float64 and complex128 typed values
Definition: param.h:78
Param(const ByteArray &name)
type-less Param with name and type
Definition: param.h:309
void setFlags(const uint32 flags)
sets parameter flagsfor possible flags see tParamType
Definition: param.h:211
complex (complex128) parameter
Definition: param.h:128
bool isNumeric(void) const
returns true if Param is of type char, int, double or complex
Definition: param.h:182
ito::RetVal setVal(_Tp val, int len)
Definition: param.h:246
Definition: typeDefs.h:60
ito::int32 m_iVal
internal value for integer typed values
Definition: param.h:79
Class for managing status values (like errors or warning)
Definition: retVal.h:54
class for parameter handling e.g. to pass paramters to plugins
Definition: param.h:283
bool getAutosave(void) const
Definition: param.h:218
const char * getInfo(void) const
< returns content of info string (string is not copied)
Definition: param.h:552
Definition: param.h:54
array of doubles
Definition: param.h:134
array of integers
Definition: param.h:133
ParamMeta * getMeta(void)
returns pointer to meta-information instance or NULL if not available. Cast this pointer to the right...
Definition: param.h:566
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition: byteArray.h:64
Param()
default constructor, creates "empty" Param
Definition: param.h:300
Definition: typeDefs.h:58
ito::RetVal setVal(_Tp val)
Definition: param.h:234
DataObject imag(const DataObject &dObj)
high-level value which calculates the imaginary value of each element of the input source data object...
Definition: dataobj.cpp:10622
polygon mesh parameter (pointer, no auto-safe possible)
Definition: param.h:138
Definition: apiFunctionsGraph.cpp:39
const ParamMeta * getMeta(void) const
returns const-pointer to meta-information instance or NULL if not available. Cast this pointer to the...
Definition: param.h:565
point parameter (pointer, no auto-safe possible)
Definition: param.h:137
bool isValid(void) const
returns whether Param contains a valid type (true) or is an empty parameter (false, type == 0). The default tParam-constructor is always an invalid tParam.
Definition: param.h:196
array of characters
Definition: param.h:132
ParamBase()
default constructor, creates "empty" ParamBase
Definition: param.h:146
uint32 getType(bool filterFlags=true) const
returns parameter type (autosave flag and other flags (like in, out or readonly) are only included if...
Definition: param.h:199
bool operator==(const ByteArray &a1, const char *a2)
comparison operator that returns true if the content of a1 is equal to the given zero-terminated stri...
Definition: byteArray.h:185
point cloud parameter (pointer, no auto-safe possible)
Definition: param.h:136
reference to another plugin instance (pointer, no auto-save possible)
Definition: param.h:131
void setAutosave(const bool autosave)
Definition: param.h:222
Param(const ByteArray &name, const uint32 type)
Constructor for a string value (const char*)
Definition: param.h:319
uint32 getFlags(void) const
returns parameter flags
Definition: param.h:208
const char * getName(void) const
returns parameter name (returned string is no copy, do not delete it)
Definition: param.h:214
const uint32 paramTypeMask
bits of param type lying withing this mask describe the type (typeNoAutosave must be included there) ...
Definition: param.h:57
_Tp getVal(void) const
Definition: param.h:257
DataObject real(const DataObject &dObj)
high-level value which calculates the real value of each element of the input source data object and ...
Definition: dataobj.cpp:10215
wrapper class for a complex128 value. This class is used, since the std::complex stl class is not exp...
Definition: param.h:60
const uint32 paramFlagMask
bits of type lying within this mask are flags (e.g. typeNoAutosave, typeReadonly...)
Definition: param.h:56
Base class for all meta-information classes.
Definition: paramMeta.h:59
bool operator!=(const ByteArray &a1, const char *a2)
comparison operator that returns true if the content of a1 is not equal to the given zero-terminated ...
Definition: byteArray.h:197
ByteArray m_name
parameter name
Definition: param.h:71
char * m_cVal
internal pointer for pointer type values (also strings)
Definition: param.h:80
string parameter
Definition: param.h:130
Definition: param.h:67
Type
Definition: param.h:83
dataObject parameter (pointer, no auto-save possible)
Definition: param.h:129
const char * data() const
return the pointer to the internal character array. If it is empty, the returned pointer still points...
Definition: byteArray.h:131
integer (int32) parameter
Definition: param.h:126
_Tp getVal(int &len) const
Definition: param.h:269
double (float64) parameter
Definition: param.h:127
character (int8) parameter
Definition: param.h:125