libvisiontransfer  10.6.0
parameterset.cpp
1 /*******************************************************************************
2  * Copyright (c) 2023 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 #include <string>
16 #include <vector>
17 #include <cstring>
18 #include <sstream>
19 #include <set>
20 
21 #include <iostream>
22 
23 #include <visiontransfer/parameterset.h>
24 
25 namespace visiontransfer {
26 namespace param {
27 
28 
29 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, int value) {
30  auto it = find(uid);
31  if (it==end()) {
32  Parameter par(uid);
33  par.setType(ParameterValue::TYPE_INT).setCurrent(value);
34  operator[](uid) = par;
35  } else {
36  if (it->second.isTensor() || it->second.isCommand()) {
37  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
38  }
39  operator[](uid).setCurrent(value);
40  }
41  return operator[](uid);
42 }
43 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, bool value) {
44  auto it = find(uid);
45  if (it==end()) {
46  Parameter par(uid);
47  par.setType(ParameterValue::TYPE_BOOL).setCurrent(value);
48  operator[](uid) = par;
49  } else {
50  if (it->second.isTensor() || it->second.isCommand()) {
51  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
52  }
53  operator[](uid).setCurrent(value);
54  }
55  return operator[](uid);
56 }
57 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, double value) {
58  auto it = find(uid);
59  if (it==end()) {
60  Parameter par(uid);
61  par.setType(ParameterValue::TYPE_DOUBLE).setCurrent(value);
62  operator[](uid) = par;
63  } else {
64  if (it->second.isTensor() || it->second.isCommand()) {
65  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
66  }
67  operator[](uid).setCurrent(value);
68  }
69  return operator[](uid);
70 }
71 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, const std::string& value) {
72  auto it = find(uid);
73  if (it==end()) {
74  Parameter par(uid);
75  par.setType(ParameterValue::TYPE_STRING).setCurrent(value);
76  operator[](uid) = par;
77  } else {
78  if (it->second.isTensor() || it->second.isCommand()) {
79  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
80  }
81  operator[](uid).setCurrent(value);
82  }
83  return operator[](uid);
84 }
85 
86 } // namespace param
87 } // namespace visiontransfer
88 
Allied Vision