ifw-core  5.0.0-pre2
parameterSet.hpp
Go to the documentation of this file.
1 
6 #ifndef IFW_CORE_UTILS_PARAMETER_SET_HPP_
7 #define IFW_CORE_UTILS_PARAMETER_SET_HPP_
8 
11 
13 
14 
15 namespace core::utils::param {
16 
18  class ParameterSet {
19  public:
20 
21  ParameterSet();
22 
24  ParameterSet(const ParameterSet& source);
25 
26  ~ParameterSet();
27 
29  static std::string ToString(std::vector<core::utils::param::Parameter>& par_list);
30 
33 
35  void Store(const std::string& par_name,
36  const std::string& value,
37  const std::string& comment = "");
38 
40  std::string GetValue(const std::string& par_name,
41  const bool exception = false) const;
42 
44  template <class TYPE>
45  bool GetValue(const std::string& name,
46  TYPE& value,
47  const bool exception = false) const {
48  LOG4CPLUS_TRACE_METHOD(core::utils::base::Logger(), __PRETTY_FUNCTION__);
49 
51  if (HasPar(name, tmpPar)) {
52  tmpPar.GetValue(value);
53  } else {
54  if (exception) {
55  throw std::runtime_error("Undefined parameter name: " + name);
56  } else {
57  return false;
58  }
59  }
60  return true;
61  }
62 
64  const core::utils::param::Parameter& GetPar(const std::string& par_name) const;
65 
67  bool HasPar(const std::string& par_name) const;
68 
70  bool HasPar(const std::string& par_name,
71  core::utils::param::Parameter& parameter) const;
72 
74  bool HasPar(const std::string& par_name,
75  std::string& value) const;
76 
78  template <class TYPE>
79  bool HasPar(const std::string& par_name,
80  TYPE& value) const {
81  LOG4CPLUS_TRACE_METHOD(core::utils::base::Logger(), __PRETTY_FUNCTION__);
82 
84  if (HasPar(par_name, tmpPar)) {
85  tmpPar.GetValue(value);
86  } else {
87  return false;
88  }
89  return true;
90  }
91 
93  uint32_t Scan(const std::string& filter_reg_exp,
94  std::vector<core::utils::param::Parameter>& matches) const;
95 
97  std::string ToString(const std::string& filter_reg_exp = "") const;
98 
100  std::vector<std::string> ParNames() const;
101 
103  const std::map<std::string, core::utils::param::Parameter>& GetParameterMap() const;
104 
106  void Merge(const ParameterSet& source_set);
107 
109  ParameterSet& operator = (const ParameterSet& source);
110 
111  protected:
112  // Mapping keywords into the associated values.
113  std::map<std::string, core::utils::param::Parameter> m_par_map;
114 
115  void _Copy(const ParameterSet& source);
116 
117  private:
118 
119  };
120 
121 }
122 
123 #endif // !IFW_CORE_UTILS_PARAMETER_SET_HPP_
Class to handle a set of parameters.
Definition: parameterSet.hpp:18
void Merge(const ParameterSet &source_set)
Merge the parameters of the source into this instance.
Definition: parameterSet.cpp:168
ParameterSet & Clear()
Clear the object.
Definition: parameterSet.cpp:43
ParameterSet & operator=(const ParameterSet &source)
Assignment operator.
Definition: parameterSet.cpp:28
std::map< std::string, core::utils::param::Parameter > m_par_map
Definition: parameterSet.hpp:113
uint32_t Scan(const std::string &filter_reg_exp, std::vector< core::utils::param::Parameter > &matches) const
Scans through the parameter object namespace and creates list of matching parameters.
Definition: parameterSet.cpp:113
std::vector< std::string > ParNames() const
Returns list of parameter names.
Definition: parameterSet.cpp:34
const core::utils::param::Parameter & GetPar(const std::string &par_name) const
Get reference to parameter object, referenced by its name.
Definition: parameterSet.cpp:92
static std::string ToString(std::vector< core::utils::param::Parameter > &par_list)
Create an ASCII print out of the parameters in the list.
void _Copy(const ParameterSet &source)
Definition: parameterSet.cpp:158
const std::map< std::string, core::utils::param::Parameter > & GetParameterMap() const
Return reference to the internal map with the names/parameter objects.
Definition: parameterSet.cpp:163
bool HasPar(const std::string &par_name) const
Returns true if parameter is defined.
Definition: parameterSet.cpp:61
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:79
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:49
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:45
ParameterSet()
Definition: parameterSet.cpp:14
~ParameterSet()
Definition: parameterSet.cpp:23
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:101
Class to handle information for one parameter.
Definition: parameter.hpp:22
const std::string & GetValue() const
Get parameter value as a string.
Definition: parameter.cpp:134
log4cplus::Logger & Logger()
Definition: tools.cpp:18
Definition: parameter.hpp:17