ifw-core 7.0.0
 
Loading...
Searching...
No Matches
parameterSet.hpp
Go to the documentation of this file.
1
6
7#ifndef IFW_CORE_UTILS_PARAMETER_SET_HPP_
8#define IFW_CORE_UTILS_PARAMETER_SET_HPP_
9
12
14
15
17
20 public:
21
23
25 ParameterSet(const ParameterSet& source);
26
28
30 static std::string ToString(std::vector<ifw::core::utils::param::Parameter>& par_list);
31
34
36 void Store(const std::string& par_name,
37 const std::string& value,
38 const std::string& comment = "");
39
41 std::string GetValue(const std::string& par_name,
42 const bool exception = false) const;
43
45 template <class TYPE>
46 bool GetValue(const std::string& name,
47 TYPE& value,
48 const bool exception = false) const {
49 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
50
52 if (HasPar(name, tmpPar)) {
53 tmpPar.GetValue(value);
54 } else {
55 if (exception) {
56 throw std::runtime_error("Undefined parameter name: " + name);
57 } else {
58 return false;
59 }
60 }
61 return true;
62 }
63
65 const ifw::core::utils::param::Parameter& GetPar(const std::string& par_name) const;
66
68 bool HasPar(const std::string& par_name) const;
69
71 bool HasPar(const std::string& par_name,
72 ifw::core::utils::param::Parameter& parameter) const;
73
75 bool HasPar(const std::string& par_name,
76 std::string& value) const;
77
79 template <class TYPE>
80 bool HasPar(const std::string& par_name,
81 TYPE& value) const {
82 LOG4CPLUS_TRACE_METHOD(ifw::core::utils::base::Logger(), __PRETTY_FUNCTION__);
83
85 if (HasPar(par_name, tmpPar)) {
86 tmpPar.GetValue(value);
87 } else {
88 return false;
89 }
90 return true;
91 }
92
94 uint32_t Scan(const std::string& filter_reg_exp,
95 std::vector<ifw::core::utils::param::Parameter>& matches) const;
96
98 std::string ToString(const std::string& filter_reg_exp = "") const;
99
101 std::vector<std::string> ParNames() const;
102
104 const std::map<std::string, ifw::core::utils::param::Parameter>& GetParameterMap() const;
105
107 void Merge(const ParameterSet& source_set);
108
110 ParameterSet& operator = (const ParameterSet& source);
111
112 protected:
113 // Mapping keywords into the associated values.
114 std::map<std::string, ifw::core::utils::param::Parameter> m_par_map;
115
116 void _Copy(const ParameterSet& source);
117
118 private:
119
120 };
121
122}
123
124#endif // !IFW_CORE_UTILS_PARAMETER_SET_HPP_
Class to handle a set of parameters.
Definition parameterSet.hpp:19
bool HasPar(const std::string &par_name) const
Returns true if parameter is defined.
Definition parameterSet.cpp:63
ParameterSet()
Definition parameterSet.cpp:16
void _Copy(const ParameterSet &source)
Definition parameterSet.cpp:160
void Merge(const ParameterSet &source_set)
Merge the parameters of the source into this instance.
Definition parameterSet.cpp:170
ParameterSet & operator=(const ParameterSet &source)
Assignment operator.
Definition parameterSet.cpp:30
bool GetValue(const std::string &name, TYPE &value, const bool exception=false) const
Return value for the referenced parameter as its native data type.
Definition parameterSet.hpp:46
void Store(const std::string &par_name, const std::string &value, const std::string &comment="")
Store a parameter name, value and possibly comment in the object.
Definition parameterSet.cpp:51
std::string GetValue(const std::string &par_name, const bool exception=false) const
Return value for the referenced parameter as a string.
Definition parameterSet.cpp:103
const ifw::core::utils::param::Parameter & GetPar(const std::string &par_name) const
Get reference to parameter object, referenced by its name.
Definition parameterSet.cpp:94
uint32_t Scan(const std::string &filter_reg_exp, std::vector< ifw::core::utils::param::Parameter > &matches) const
Scans through the parameter object namespace and creates list of matching parameters.
Definition parameterSet.cpp:115
~ParameterSet()
Definition parameterSet.cpp:25
bool HasPar(const std::string &par_name, TYPE &value) const
Return true if parameter defined, sets the value as the native value.
Definition parameterSet.hpp:80
ParameterSet & Clear()
Clear the object.
Definition parameterSet.cpp:45
const std::map< std::string, ifw::core::utils::param::Parameter > & GetParameterMap() const
Return reference to the internal map with the names/parameter objects.
Definition parameterSet.cpp:165
std::vector< std::string > ParNames() const
Returns list of parameter names.
Definition parameterSet.cpp:36
std::map< std::string, ifw::core::utils::param::Parameter > m_par_map
Definition parameterSet.hpp:114
static std::string ToString(std::vector< ifw::core::utils::param::Parameter > &par_list)
Create an ASCII print out of the parameters in the list.
Class to handle information for one parameter.
Definition parameter.hpp:25
const std::string & GetValue() const
Get parameter value as a string.
Definition parameter.cpp:140
log4cplus::Logger & Logger()
Definition tools.cpp:20
Definition parameter.hpp:20