libvisiontransfer  10.8.0
parameterset.cpp
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 #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 class ParameterSet::Pimpl {
29  // Empty for now, reserved for extensibility of ParameterSet
30 };
31 
32 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, int value) {
33  auto it = find(uid);
34  if (it==end()) {
35  Parameter par(uid);
36  par.setType(ParameterValue::TYPE_INT).setCurrent(value);
37  operator[](uid) = par;
38  } else {
39  if (it->second.isTensor() || it->second.isCommand()) {
40  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
41  }
42  operator[](uid).setCurrent(value);
43  }
44  return operator[](uid);
45 }
46 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, bool value) {
47  auto it = find(uid);
48  if (it==end()) {
49  Parameter par(uid);
50  par.setType(ParameterValue::TYPE_BOOL).setCurrent(value);
51  operator[](uid) = par;
52  } else {
53  if (it->second.isTensor() || it->second.isCommand()) {
54  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
55  }
56  operator[](uid).setCurrent(value);
57  }
58  return operator[](uid);
59 }
60 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, double value) {
61  auto it = find(uid);
62  if (it==end()) {
63  Parameter par(uid);
64  par.setType(ParameterValue::TYPE_DOUBLE).setCurrent(value);
65  operator[](uid) = par;
66  } else {
67  if (it->second.isTensor() || it->second.isCommand()) {
68  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
69  }
70  operator[](uid).setCurrent(value);
71  }
72  return operator[](uid);
73 }
74 Parameter& ParameterSet::setOrCreateSimpleScalar(const std::string& uid, const std::string& value) {
75  auto it = find(uid);
76  if (it==end()) {
77  Parameter par(uid);
78  par.setType(ParameterValue::TYPE_STRING).setCurrent(value);
79  operator[](uid) = par;
80  } else {
81  if (it->second.isTensor() || it->second.isCommand()) {
82  throw std::runtime_error("setOrCreateSimpleScalar(): refusing to overwrite a Tensor or Command parameter");
83  }
84  operator[](uid).setCurrent(value);
85  }
86  return operator[](uid);
87 }
88 
89 } // namespace param
90 } // namespace visiontransfer
91 
Allied Vision