libvisiontransfer  10.0.0
parametervalue.h
1 /*******************************************************************************
2  * Copyright (c) 2022 Nerian Vision 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 VT_EXPORT ParameterValue {
36 public:
37  enum ParameterType {
38  TYPE_INT,
39  TYPE_DOUBLE,
40  TYPE_BOOL,
41  TYPE_STRING,
42  TYPE_SAFESTRING,
43  TYPE_TENSOR,
44  TYPE_COMMAND,
45  TYPE_UNDEFINED
46  };
47 
49  ParameterValue& setType(ParameterType t);
50  ParameterValue& setTensorShape(const std::vector<unsigned int>& shape);
51  bool isDefined() const;
52  bool isUndefined() const;
53  bool isTensor() const;
54  bool isScalar() const;
55  bool isCommand() const;
56  unsigned int getTensorDimension() const;
57  std::vector<unsigned int> getTensorShape() const;
59  std::vector<double> getTensorData() const;
61  std::vector<double>& getTensorDataReference() { return tensorData; };
62  ParameterValue& setTensorData(const std::vector<double>& data);
63  unsigned int getTensorNumElements() const;
64  unsigned int getTensorCurrentDataSize() const;
65  ParameterType getType() const { return type; }
66  double& tensorElementAt(unsigned int x);
67  double& tensorElementAt(unsigned int y, unsigned int x);
68  double& tensorElementAt(unsigned int z, unsigned int y, unsigned int x);
69 
70  template<typename T> ParameterValue& setValue(T t);
71  template<typename T> T getValue() const;
72  template<typename T> T getWithDefault(const T& deflt) const { return (type==TYPE_UNDEFINED) ? deflt : getValue<T>(); }
73 
74 private:
75  double numVal;
76  std::string stringVal;
77  unsigned int tensorNumElements; // quick access to number of elements
78  std::vector<unsigned int> tensorShape;
79  std::vector<double> tensorData;
80 
81  ParameterType type;
82 
84  std::string sanitizeString(const std::string& s, unsigned int maxLength=4096);
85 };
86 
87 } // namespace param
88 } // namespace visiontransfer
89 
90 #endif
91 
92 
93 
94 
std::vector< double > & getTensorDataReference()
Return a reference to the internal tensor data (caution)
Nerian Vision Technologies