libvisiontransfer  10.8.0
parametervalue.h
1 /*******************************************************************************
2  * Copyright (c) 2024 Allied Vision Technologies GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef VISIONTRANSFER_PARAMETERVALUE_H
16 #define VISIONTRANSFER_PARAMETERVALUE_H
17 
18 #include <string>
19 #include <vector>
20 #include <map>
21 
22 #include <cstring>
23 #include <sstream>
24 #include <iomanip>
25 #include <limits>
26 #include <memory>
27 
28 #include <visiontransfer/common.h>
29 
30 namespace visiontransfer {
31 namespace param {
32 
33 
35 class ParameterValue {
36 
37 private:
38  // We follow the pimpl idiom
39  class Pimpl;
40  Pimpl* pimpl;
41 
42 public:
43  enum ParameterType {
44  TYPE_INT,
45  TYPE_DOUBLE,
46  TYPE_BOOL,
47  TYPE_STRING,
48  TYPE_SAFESTRING,
49  TYPE_TENSOR,
50  TYPE_COMMAND,
51  TYPE_UNDEFINED
52  };
53 
54  VT_EXPORT ParameterValue();
55  VT_EXPORT ParameterValue(const ParameterValue& other);
56  VT_EXPORT ~ParameterValue();
57  VT_EXPORT ParameterValue& operator= (const ParameterValue& other);
58  VT_EXPORT ParameterValue& setType(ParameterType t);
59  VT_EXPORT ParameterValue& setTensorShape(const std::vector<unsigned int>& shape);
60  VT_EXPORT bool isDefined() const;
61  VT_EXPORT bool isUndefined() const;
62  VT_EXPORT bool isTensor() const;
63  VT_EXPORT bool isScalar() const;
64  VT_EXPORT bool isCommand() const;
65  VT_EXPORT unsigned int getTensorDimension() const;
66  VT_EXPORT std::vector<unsigned int> getTensorShape() const;
68  VT_EXPORT std::vector<double> getTensorData() const;
70  VT_EXPORT std::vector<double>& getTensorDataReference();
71  VT_EXPORT ParameterValue& setTensorData(const std::vector<double>& data);
72  VT_EXPORT unsigned int getTensorNumElements() const;
73  VT_EXPORT unsigned int getTensorCurrentDataSize() const;
74  VT_EXPORT ParameterType getType() const;
75  VT_EXPORT double& tensorElementAt(unsigned int x);
76  VT_EXPORT double& tensorElementAt(unsigned int y, unsigned int x);
77  VT_EXPORT double& tensorElementAt(unsigned int z, unsigned int y, unsigned int x);
78 
79  template<typename T> VT_EXPORT ParameterValue& setValue(T t);
80  template<typename T> VT_EXPORT T getValue() const;
81  template<typename T> VT_EXPORT T getWithDefault(const T& deflt) const;
82 
83 };
84 
85 } // namespace param
86 } // namespace visiontransfer
87 
88 #endif
89 
90 
91 
92 
visiontransfer::param::ParameterValue::getTensorDataReference
VT_EXPORT std::vector< double > & getTensorDataReference()
Return a reference to the internal tensor data (caution)
Definition: parametervalue.cpp:512
visiontransfer::param::ParameterValue
Definition: parametervalue.h:59
visiontransfer::param::ParameterValue::getTensorData
VT_EXPORT std::vector< double > getTensorData() const
Return a copy of the internal tensor data.
Definition: parametervalue.cpp:508
Allied Vision