-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparam.h
1554 lines (1340 loc) · 54.3 KB
/
param.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ********************************************************************
itom software
URL: http://www.uni-stuttgart.de/ito
Copyright (C) 2020, Institut für Technische Optik (ITO),
Universität Stuttgart, Germany
This file is part of itom and its software development toolkit (SDK).
itom is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public Licence as published by
the Free Software Foundation; either version 2 of the Licence, or (at
your option) any later version.
In addition, as a special exception, the Institut für Technische
Optik (ITO) gives you certain additional rights.
These rights are described in the ITO LGPL Exception version 1.0,
which can be found in the file LGPL_EXCEPTION.txt in this package.
itom is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
General Public Licence for more details.
You should have received a copy of the GNU Library General Public License
along with itom. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************** */
#pragma once
/* includes */
#include "byteArray.h"
#include "commonGlobal.h"
#include "paramMeta.h"
#include "retVal.h"
#include "typeDefs.h"
#include <algorithm>
#include <atomic>
#include <limits>
#include <stdarg.h>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* definition and macros */
/* global variables (avoid) */
/* content */
namespace ito {
class Param;
template <typename _Tp> struct ItomParamHelper;
const uint32 paramFlagMask = 0xFFFF0000; //!< bits of type lying within this mask are flags (e.g.
//!< typeNoAutosave, typeReadonly...)
const uint32 paramTypeMask = 0x0000FFFF; //!< bits of param type lying within this mask describe
//!< the type (typeNoAutosave must be included there)
//! wrapper class for a complex128 value. This class is used, since the std::complex stl class is
//! not exported over DLLs
struct complex128_
{
float64 real;
float64 imag;
};
//!< Union for the internal parameter value of class ParamBase.
union ParamBaseData {
//!< 1 byte
int8 i8Val;
//!< 4 bytes
int32 i32Val;
//!< 8 bytes
float64 f64Val;
//!< 16 bytes
complex128_ c128Val;
//!< 8 bytes
void* ptrVal;
};
//-------------------------------------------------------------------------------------
//!< \class ParamBase
/* \brief Base class for parameter container.
This base class only holds the name of the parameter, the type of the internal value,
the value itself and
some optional flags.
*/
class ITOMCOMMON_EXPORT ParamBase
{
public:
//!< Flag section, new for itom > 4.1. Before it was part of the Type enumeration.
/* For compatibility reasons with older versions of itom, values in this enumeration
must only set bits in the range 17-32 of an uint32 value, since they can be
used together with values of the Type enum below, using bits 1-16.
Internally, the flags are stored as uint16 object, where these enumeration
values are shifted by 16bits.
*/
enum Flag
{
/* If this bit is set, this parameter should be automatically
stored if for instance a plugin is closed and if the plugin
with the same identifier is opened again, the parameter
value will be tried to be reconstructed from the stored value. */
NoAutosave = 0x010000,
/* Flag to define this parameter to be readonly. It cannot for instance not be changed
from Python. Internally, the setVal method does not check for Readonly.
This has to be programmed manually. Plugins can also set or unset this flag
during the runtime. */
Readonly = 0x020000,
/* Flag to mark this parameter as input value only.
If a plugin defines this flag without the Out-flag, it pretends
to only consume the given value, but the consumer will not change the value at any time.
If the Out-flag is set, too, the consumer (e.g. plugin) will read and write the
value, such that for instance a given dataObject will have another content after having
called a method of a plugin. Return parameters of a method must never have the In-flag set.
*/
In = 0x040000,
/* Flag to mark this parameter, that the consumer will create or change
the value of this parameter.
This can be set together with In (or alone). All return parameters of an method in
an algorithm plugin, must have this flag set. For other mandatory or optional
input parameter, this flag can only be set together with In and means then,
that the content of the given parameter will be changed by the called method. */
Out = 0x080000,
/* Flag to mark a parameter to be temporarily not available.
Plugins can also set or unset this flag
during the runtime. */
NotAvailable = 0x100000,
};
enum Type
{
/* Helper-bit for all types that only contain a pointer to the real value and
not the value itself. For these types, the caller need to keep the pointed object
until both caller and called method do not use it any more! */
Pointer = 0x0001,
//!< character (int8) parameter
Char = 0x0002,
//!< integer (int32) parameter
Int = 0x0004,
//!< double (float64) parameter
Double = 0x0008,
//!< complex (complex128) parameter
Complex = 0x0400,
//!< dataObject parameter (pointer, no auto-save possible)
DObjPtr = 0x0010 | Pointer,
//!< string parameter
String = 0x0020 | Pointer,
//!< reference to another plugin instance (pointer, no auto-save possible)
HWRef = 0x0040 | Pointer,
//!< array of characters
CharArray = Char | Pointer,
//!< array of integers
IntArray = Int | Pointer,
//!< array of doubles
DoubleArray = Double | Pointer,
//!< array of complex numbers
ComplexArray = Complex | Pointer,
//!< point cloud parameter (pointer, no auto-safe possible)
PointCloudPtr = 0x0080 | Pointer,
//!< point parameter (pointer, no auto-safe possible)
PointPtr = 0x0100 | Pointer,
//!< polygon mesh parameter (pointer, no auto-safe possible)
PolygonMeshPtr = 0x0200 | Pointer,
//!< list of strings, given as ito::ByteArray
StringList = 0x0800 | Pointer
};
//--------------------------------------------------------------------------------------------
// CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
//--------------------------------------------------------------------------------------------
//! default constructor, creates "empty" ParamBase
ParamBase();
// type-less ParamBase with name only
ParamBase(const ByteArray& name);
// constructor with type and name
ParamBase(const ByteArray& name, const uint32 typeAndFlags);
// constructor with name and type and char val
ParamBase(const ByteArray& name, const uint32 typeAndFlags, const char* val);
// constructor with name and type and float64 val
ParamBase(const ByteArray& name, const uint32 typeAndFlags, const float64 val);
// constructor with name and type and int32 val
ParamBase(const ByteArray& name, const uint32 typeAndFlags, const int32 val);
// constructor with name and type and complex128 val
ParamBase(const ByteArray& name, const uint32 typeAndFlags, const complex128 val);
// array constructor with name and type, size and array
ParamBase(
const ByteArray& name, const uint32 typeAndFlags, const uint32 size, const char* values);
// array constructor with name and type, size and array
ParamBase(
const ByteArray& name, const uint32 typeAndFlags, const uint32 size, const int32* values);
// array constructor with name and type, size and array
ParamBase(
const ByteArray& name, const uint32 typeAndFlags, const uint32 size, const float64* values);
// array constructor with name and type, size and array
ParamBase(
const ByteArray& name,
const uint32 typeAndFlags,
const uint32 size,
const complex128* values);
// array constructor with name and type, size and string list
ParamBase(
const ByteArray& name,
const uint32 typeAndFlags,
const uint32 size,
const ByteArray* values);
//!< Destructor
virtual ~ParamBase();
//!< copy constructor
ParamBase(const ParamBase& other);
//!< copy constructor for rvalues
ParamBase(ParamBase&& other) noexcept;
//--------------------------------------------------------------------------------------------
// ASSIGNMENT AND OPERATORS
//--------------------------------------------------------------------------------------------
//!< braces operator for element-wise access in arrays
const ParamBase operator[](const int index) const;
//!< assignment operator (sets values of lhs to
//!< values of rhs Param, strings are copied)
ParamBase& operator=(const ParamBase& rhs);
//!< rvalue assignment operator
inline ParamBase& operator=(ParamBase&& other) noexcept
{
if (this != &other)
{
std::swap(d, other.d);
}
return *this;
}
//!< just copies the value from the right-hand-side tParam (rhs) to this tParam.
ito::RetVal copyValueFrom(const ito::ParamBase* rhs);
//--------------------------------------------------------------------------------------------
// COMPARISON OPERATORS (two values are equal if both their type and the content is equal)
//--------------------------------------------------------------------------------------------
bool operator==(const ParamBase& rhs) const;
inline bool operator!=(const ParamBase& rhs) const
{
return !(*this == rhs);
}
//--------------------------------------------------------------------------------------------
// SET/GET FURTHER PROPERTIES
//--------------------------------------------------------------------------------------------
//! returns true if Param is of type char, int, double or complex
bool isNumeric(void) const;
//! returns true if Param is of type char array, int array, double array or complex array
bool isNumericArray(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.
bool isValid(void) const;
//! returns parameter type
uint16 getType() const;
//! returns parameter flags
uint32 getFlags() const;
//! sets parameter flags for possible flags see \ref tParamType
void setFlags(const uint32 flags);
//! returns parameter name (returned string is no copy, do not delete it)
const char* getName(void) const;
//! return the name, where an integer index is appended with bracket squares, e.g. myArray
//! becomes myArray[2].
ito::ByteArray getNameWithIndexSuffix(int index) const;
//! returns content of autosave flag - this flag determines whether the parameter value gets
//! automagically saved to xml file when an instance of a plugin class is deleted (closed)
bool getAutosave() const;
//! sets content of autosave flag - this flag determines whether the parameter value gets
//! automagically saved to xml file when an instance of a plugin class is deleted (closed)
void setAutosave(const bool autosave);
//! returns length of array parameters.
/* The return value of this method depends on the type of parameter:
For scalar parameters, like Char, Int, Double, Complex, 1 is always returned.
For number array parameters (CharArray, IntArray, DoubleArray, ComplexArray, the
number of values in the array is returned. Even if the array is a nullptr,
0 is returned. This changed from itom 5.0 on. Before -1 was returned
if the array is a nullptr (which is equal to a length of 0).
StringList parameter behave like the other scalar parameters.
For String parameters, the length of the string is returned, but
-1 is returned if the internal string is nullptr.
An invalid parameter will also return -1 always.
*/
int getLen() const;
/** setVal set parameter value - templated version
* @param [in] val value to set to
* @return RetVal with operation status
* sets the parameter value to the passed value, if the parameter type is inadequate it is set
* to the maximum value of template type
*/
template <typename _Tp> inline ito::RetVal setVal(_Tp val)
{
return ItomParamHelper<_Tp>::setVal(this, val, 0);
}
/** setVal set parameter value - templated version for arrays
* @param [in] val value to set to
* @param [in] len length of array
* @return RetVal with operation status
* sets the parameter value to the passed value, if the length is below 1 or a Null pointer is
* passed an error is returned
*/
template <typename _Tp> inline ito::RetVal setVal(_Tp val, int len)
{
return ItomParamHelper<_Tp>::setVal(this, val, len);
}
/** getVal read parameter value - templated version
* @return parameter value (numeric, casted)
*
* returns the actual parameter value casted to the template parameter type. If the tParam has
* a non numeric type the largest value for the template type is passed.
*/
template <typename _Tp> inline _Tp getVal() const
{
int len = 0;
return ItomParamHelper<_Tp>::getVal(this, len);
}
/** getVal read parameter value - templated version for arrays
* @param [out] len length of array
*
* returns the actual parameter value casted to the template parameter type. In 'len' is
* returned what is supposed to be the length of the array. As only array references are used
* within tParam the actual size may differ.
*/
template <typename _Tp> inline _Tp getVal(int& len) const
{
return ItomParamHelper<_Tp>::getVal(this, len);
}
private:
//!< struct used as shared memory of ParamBase
struct Data
{
Data(const ByteArray& name_ = "") : ref(0), flags(0), type(0), len(0), name(name_)
{
memset(&data, 0, sizeof(ParamBaseData));
}
/*!< reference counter for implicit sharing (0: means one reference, ...) */
std::atomic_int ref;
//!< value as union
ParamBaseData data;
//!< length of array if the type is an array type (including string or string list)
uint32 len;
//!< flags, bitmask of the higher level values in ParamBase::Flag
uint16 flags;
//!< type, correspond to ParamBase::Type
uint16 type;
//!< name of this parameter
ByteArray name;
};
//!< shared data container
mutable Data* d;
//!< clears and frees memory that has been allocated by data. Does not delete
//!< data itself. Usually this method is internally called by decRefAndFree.
void clearData(Data* data);
//!< if data is currently shared with another object, detach this
//!< data d from the shared ones by making a copy. If this data is not
//!< shared, this method is a noop.
/*
\param allocNewArray if false, now new arrays, strings or string list
memory is allocated and the len is set to 0. This should only be
set to false, if it is assured that the memory is allocated by
another part of the code.
*/
void detach(bool allocNewArray = true);
//!< decrements the reference counter of data. If it drops below zero
//!< the allocated memory is cleared.
inline void decRefAndFree(Data* x)
{
if (x && (!(x->ref--)))
{
clearData(x);
delete (x);
x = nullptr;
}
}
//!< increments the reference counter of data
inline void incRef(Data* x)
{
if (x)
{
(x->ref)++;
}
}
//!< depending on the type, set the default value for the autosave flag.
void setDefaultAutosaveFlag();
void checkAndCorrectInOutFlag();
template <typename _Tp> friend struct ItomParamHelper;
};
//----------------------------------------------------------------------------------------------------------------------------------
/** @class Param
* @brief class for parameter handling e.g. to pass parameters to plugins
*
* The plugins use this class to organize their parameters (internally) and for the paramList
* which is used for type checking whilst parsing parameters passed from python to c.
*/
class ITOMCOMMON_EXPORT Param : public ParamBase
{
public:
//--------------------------------------------------------------------------------------------
// CONSTRUCTORS, COPY-CONSTRUCTOR, DESTRUCTOR
//--------------------------------------------------------------------------------------------
//! default constructor, creates "empty" Param
/*
This parameter has no documentation string and no meta information.
The type is 0 (invalid).
The name is empty.
*/
Param();
//!< type-less Param with name only
/*
This parameter has no documentation string and no meta information.
The type is 0 (invalid).
\param name is the name of the parameter
*/
Param(const ByteArray& name);
//!< type-less Param with name and type
/*
This parameter has no documentation string and no meta information.
\param name is the name of the parameter
\type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Char | ito::ParamBase::In for a read-only input parameter
*/
Param(const ByteArray& name, const uint32 typeAndFlags);
//!< Constructor for a string value (const char*)
/*
This parameter has no meta information. They can be added using setMetaInfo.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::String | ito::ParamBase::In for a read-only input parameter
\param val is the default string (const char*) of this parameter
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(const ByteArray& name, const uint32 typeAndFlags, const char* val, const char* info);
//!< Constructor for a char value parameter (int8)
/*
This parameter will automatically get meta information of type ito::CharMeta with a minimum and
maximum value.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Char | ito::ParamBase::In for a read-only input parameter
\param minVal is the minimum allowed value (added to meta information)
\param maxVal is the maximum allowed value (added to meta information)
\param val is the default int8 value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const char minVal,
const char maxVal,
const char val,
const char* info);
//!< Constructor for an integer value parameter (int32)
/*
This parameter will automatically get meta information of type ito::IntMeta with a minimum and
maximum value.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Int | ito::ParamBase::In for a read-only input parameter
\param minVal is the minimum allowed value (added to meta information)
\param maxVal is the maximum allowed value (added to meta information)
\param val is the default int32 value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const int32 minVal,
const int32 maxVal,
const int32 val,
const char* info);
//!< Constructor for an double value parameter (float64)
/*
This parameter will automatically get meta information of type ito::DoubleMeta with a minimum
and maximum value.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Double | ito::ParamBase::In for a read-only input parameter
\param minVal is the minimum allowed value (added to meta information)
\param maxVal is the maximum allowed value (added to meta information)
\param val is the default float64 value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const float64 minVal,
const float64 maxVal,
const float64 val,
const char* info);
//!< Constructor for a character array parameter (int8)
/*
This parameter has no meta information. They can be added using setMetaInfo.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::CharArray | ito::ParamBase::In for a read-only input parameter
\param size is the size of the given default values array
\param values is the default int8 array value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const char* values,
const char* info); // array constructor with name and type, size and array
//!< Constructor for an integer array parameter (int32)
/*
This parameter has no meta information. They can be added using setMetaInfo.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::IntArray | ito::ParamBase::In for a read-only input parameter
\param size is the size of the given default values array
\param values is the default int32 array value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const int32* values,
const char* info);
//!< Constructor for a double array parameter (float64)
/*
This parameter has no meta information. They can be added using setMetaInfo.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::DoubleArray | ito::ParamBase::In for a read-only input parameter
\param size is the size of the given default values array
\param values is the default float64 array value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const float64* values,
const char* info);
//!< Constructor for a complex128 array parameter
/*
This parameter has no meta information.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::ComplexArray | ito::ParamBase::In for a read-only input parameter
\param size is the size of the given default values array
\param values is the default complex array value
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const complex128* values,
const char* info);
//!< Constructor for a string list parameter
/*
This parameter has no meta information.
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::ComplexArray | ito::ParamBase::In for a read-only input parameter
\param size is the size of the given default values array
\param values is the default ByteArray list
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const ByteArray* values,
const char* info);
//!< constructor for a character value (int8)
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Char | ito::ParamBase::In for a read-only input parameter
\param val is the default value
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, it has to be an object of ito::CharMeta.
The ownership is taken by this parameter!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const char val,
ParamMeta* meta,
const char* info);
//!< constructor for an integer value (int32)
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Int | ito::ParamBase::In for a read-only input parameter
\param val is the default value
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, it has to be an object of ito::IntMeta.
The ownership is taken by this parameter!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const int32 val,
ParamMeta* meta,
const char* info);
//!< constructor for a double value (float64)
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Double | ito::ParamBase::In for a read-only input parameter
\param val is the default value
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, it has to be an object of ito::DoubleMeta.
The ownership is taken by this parameter!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const float64 val,
ParamMeta* meta,
const char* info);
//!< constructor for a complex value (complex128)
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::Complex | ito::ParamBase::In for a read-only input parameter
\param val is the default value
\param meta might be nullptr, if no meta information should be passed to this parameter.
Currently, there is no meta information class for complex value parameters!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const complex128 val,
ParamMeta* meta,
const char* info);
//!< constructor for int32 arrays.
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::CharArray | ito::ParamBase::In for a read-only input parameter
\param size is the length of the default array, passed to values
\param values is the pointer to the default array of values
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, it has to be an object of ito::CharArrayMeta.
The ownership is taken by this parameter!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const char* values,
ParamMeta* meta,
const char* info);
//!< constructor for int32 arrays.
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::IntArray | ito::ParamBase::In for a read-only input parameter
\param size is the length of the default array, passed to values
\param values is the pointer to the default array of values
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, it has to be an object of ito::IntArrayMeta, ito::IntervalMeta,
ito::RangeMeta or ito::RectMeta.
The ownership is taken by this parameter!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const int32* values,
ParamMeta* meta,
const char* info);
//!< constructor for float64 arrays.
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::DoubleArray | ito::ParamBase::In for a read-only input parameter
\param size is the length of the default array, passed to values
\param values is the pointer to the default array of values
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, it has to be an object of ito::DoubleArrayMeta or
ito::DoubleIntervalMeta. The ownership is taken by this parameter! \param info can be a
documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const float64* values,
ParamMeta* meta,
const char* info);
//!< constructor for complex128 arrays.
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::ComplexArray | ito::ParamBase::In for a read-only input parameter
\param size is the length of the default array, passed to values
\param values is the pointer to the default array of values
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, the ownership is taken by this parameter!
Currently, there is no meta information class available for complex array parameters!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const complex128* values,
ParamMeta* meta,
const char* info);
//!< constructor for a string list.
/*
\param name is the name of the parameter
\param type is a flag mask, that might consists of combinations of ito::ParamBase::Type,
e.g. ito::ParamBase::ComplexArray | ito::ParamBase::In for a read-only input parameter
\param size is the length of the default array, passed to values
\param values is the pointer to the default string list values
\param meta might be nullptr, if no meta information should be passed to this parameter.
If a pointer is given, the ownership is taken by this parameter!
Currently, there is no meta information class available for complex array parameters!
\param info can be a documentation string for this parameter, an empty string or nullptr
*/
Param(
const ByteArray& name,
const uint32 typeAndFlags,
const unsigned int size,
const ByteArray* values,
ParamMeta* meta,
const char* info);
//!< Destructor
~Param();
//!< Copy-Constructor
Param(const Param& copyConstr);
//!< rvalue copy constructor
Param(Param&& rvalue);
//--------------------------------------------------------------------------------------------
// ASSIGNMENT AND OPERATORS
//--------------------------------------------------------------------------------------------
//!< braces operator for element-wise access in arrays
const Param operator[](const int index) const;
//!< assignment operator (sets values of lhs to values of
//!< rhs Param, strings are copied)
Param& operator=(const Param& rhs);
//!< rvalue assignment operator
Param& operator=(Param&& rvalue) noexcept;
//!< just copies the value from the right-hand-side ParamBase (rhs)
//!< to this tParam.
ito::RetVal copyValueFrom(const ParamBase* rhs);
private:
//!< struct for the shared container for meta information
struct MetaShared
{
MetaShared(ParamMeta* m) : meta(m), ref(0)
{
}
ParamMeta* meta;
std::atomic_int ref;
};
//!< shared meta information object
MetaShared* m_pMetaShared;
//!< description of this parameter
ByteArray m_info;
/* call this method, if the internal meta object
is likely to be changed. If so, a deep copy of the
internal meta object will be done (if it is currently shared),
such that other Param objects are not affected by the possible meta
change. */
void detachMeta();
inline void incRefMeta(MetaShared* ms) const
{
if (ms)
{
ms->ref++;
}
}
inline void decRefMeta(MetaShared* ms) const
{
if (ms && !(ms->ref--))
{
delete ms->meta;
delete ms;
ms = nullptr;
}
}
public:
//--------------------------------------------------------------------------------------------
// SET/GET FURTHER PROPERTIES
//--------------------------------------------------------------------------------------------
//!< returns content of info string (string is not copied)
inline const char* getInfo() const
{
return m_info.data();
}
//!< sets content of info string, if necessary the info buffer is freed first, passed string is
//!< copied
inline void setInfo(const char* info)
{
m_info = info;
}
//!< set the info string (description) to info.
inline void setInfo(const ByteArray& info)
{
m_info = info;
}
//!< returns const-pointer to meta-information instance or nullptr if not available. Cast this
//!< pointer to the right class of the parameter.
inline const ParamMeta* getMeta() const
{
return m_pMetaShared ? m_pMetaShared->meta : nullptr;
}
//!< returns const-pointer to meta-information instance or nullptr if not available. Cast this
//!< pointer to the right class of the parameter.
inline const ParamMeta* getConstMeta() const
{
return m_pMetaShared ? m_pMetaShared->meta : nullptr;
}
//!< returns pointer to meta-information instance or nullptr if not available. Cast this pointer
//!< to the right class of the parameter.
inline ParamMeta* getMeta(void)
{
if (m_pMetaShared && m_pMetaShared->ref > 0)
{
// decouple the internal meta object, since it
// could be changed by the caller of this method.
detachMeta();
}
return m_pMetaShared ? m_pMetaShared->meta : nullptr;
}
//!< returns const-pointer to meta-information instance casted to 'const _Tp*' or nullptr if not
//!< available or cast failed.
/*
Example: intParam.getMetaT<ito::IntMeta>();
Usually, it is more explicit to call getConstMetaT instead of this method.
*/
template <typename _Tp> inline const _Tp* getMetaT(void) const
{
if (m_pMetaShared)
{
return static_cast<const _Tp*>(m_pMetaShared->meta);
}
return nullptr;
}
//!< returns const-pointer to meta-information instance casted to 'const _Tp*' or nullptr if not
//!< available or cast failed.
/*
Example: intParam.getMetaT<ito::IntMeta>();
*/
template <typename _Tp> inline const _Tp* getConstMetaT(void) const
{
if (m_pMetaShared)
{
return static_cast<const _Tp*>(m_pMetaShared->meta);
}
return nullptr;
}
//!< returns pointer to meta-information instance casted to '_Tp*' or nullptr if not available
//!< or cast failed.