libvisiontransfer  10.6.0
parameterset.h
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 #ifndef VISIONTRANSFER_PARAMETERSET_H
16 #define VISIONTRANSFER_PARAMETERSET_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 #include <visiontransfer/parameter.h>
30 
31 namespace visiontransfer {
32 namespace param {
33 
35 class VT_EXPORT ParameterSet: public std::map<std::string, Parameter> {
36  public:
37  typedef std::shared_ptr<ParameterSet> ptr;
39  inline Parameter& get(const std::string& uid) {
40  auto it = find(uid);
41  if (it==end()) throw std::runtime_error(std::string("Attempted to get nonexistent parameter ") + uid);
42  return it->second;
43  }
44  inline bool add(const Parameter& param) { operator[](param.getUid()) = param; return true; }
46  template<typename T> T getCurrentOrFallback(const std::string& key, T&& fallback) {
47  auto it = find(key);
48  if (it!=end()) return it->second.getCurrent<T>();
49  else return (T) fallback;
50  }
52  template<typename T> T getCurrent(const std::string& key) {
53  auto it = find(key);
54  if (it!=end()) return it->second.getCurrent<T>();
55  else throw std::runtime_error(std::string("Parameter not found in the parameter set: ") + key);
56  }
57  // Convenience functions for quickly adding (internal) parameter values; scalars with no initial metadata
58  Parameter& setOrCreateSimpleScalar(const std::string& uid, int value);
59  Parameter& setOrCreateSimpleScalar(const std::string& uid, bool value);
60  Parameter& setOrCreateSimpleScalar(const std::string& uid, double value);
61  Parameter& setOrCreateSimpleScalar(const std::string& uid, const std::string& value);
62 };
63 
64 } // namespace param
65 } // namespace visiontransfer
66 
67 #endif
68 
visiontransfer::param::Parameter
Definition: parameter.h:71
Allied Vision