ifw-core  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterSet.hpp
Go to the documentation of this file.
1 
9 #ifndef IWF_CTD_PARAM_PARAMETER_SET_HPP_
10 #define IWF_CTD_PARAM_PARAMETER_SET_HPP_
11 
12 #include "ctd/defines/defines.hpp"
13 #include "ctd/param/Parameter.hpp"
14 
16 
17 namespace ctd {
18  namespace param {
19 
21  class ParameterSet {
22  public:
23 
24  ParameterSet();
25 
27  ParameterSet(const ParameterSet& source);
28 
29  ~ParameterSet();
30 
32  static std::string ToString(std::vector<ctd::param::Parameter>& par_list);
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  RAD_LOG_TRACE();
49 
50  ctd::param::Parameter tmpPar;
51  if (HasPar(name, tmpPar)) {
52  tmpPar.GetValue(value);
53  } else {
54  if (exception) {
55  throw rad::Exception("Undefined parameter name: %s", name.c_str());
56  } else {
57  return false;
58  }
59  }
60  return true;
61  }
62 
64  const ctd::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  ctd::param::Parameter& parameter) const;
72 
74  template <class TYPE>
75  bool HasPar(const std::string& par_name,
76  TYPE& value) const {
77  RAD_LOG_TRACE();
78 
79  ctd::param::Parameter tmpPar;
80  if (HasPar(par_name, tmpPar)) {
81  tmpPar.GetValue(value);
82  } else {
83  return false;
84  }
85  return true;
86  }
87 
89  uint32_t Scan(const std::string& filter_reg_exp,
90  std::vector<ctd::param::Parameter>& matches) const;
91 
93  std::string ToString(const std::string& filter_reg_exp = "") const;
94 
96  std::vector<std::string> ParNames() const;
97 
99  const std::map<std::string, ctd::param::Parameter>& GetParameterMap() const;
100 
102  ParameterSet& operator = (const ParameterSet& source);
103 
104  protected:
105  // Mapping keywords into the associated values.
106  std::map<std::string, ctd::param::Parameter> m_par_map;
107 
108  void _Copy(const ParameterSet& source);
109 
110  private:
111 
112  };
113 
114  }
115 }
116 
117 #endif // !IWF_CTD_PARAM_PARAMETER_SET_HPP_
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 & operator=(const ParameterSet &source)
Assignment operator.
Definition: ParameterSet.cpp:29
std::vector< std::string > ParNames() const
Returns list of parameter names.
Definition: ParameterSet.cpp:38
Class to handle a set of parameters.
Definition: ParameterSet.hpp:21
ParameterSet()
Definition: ParameterSet.cpp:11
Common definitions.
std::string GetValue() const
Get parameter value as a string.
Definition: Parameter.cpp:102
bool HasPar(const std::string &par_name) const
Returns true if parameter is defined.
Definition: ParameterSet.cpp:62
static std::string ToString(std::vector< ctd::param::Parameter > &par_list)
Create an ASCII print out of the parameters in the list.
Definition: ParameterSet.cpp:125
const ctd::param::Parameter & GetPar(const std::string &par_name) const
Get reference to parameter object, referenced by its name.
Definition: ParameterSet.cpp:85
std::map< std::string, ctd::param::Parameter > m_par_map
Definition: ParameterSet.hpp:106
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:96
void _Copy(const ParameterSet &source)
Definition: ParameterSet.cpp:161
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
const std::map< std::string, ctd::param::Parameter > & GetParameterMap() const
Return reference to the internal map with the names/parameter objects.
Definition: ParameterSet.cpp:168
~ParameterSet()
Definition: ParameterSet.cpp:23
Class to handle information for one parameter.
Definition: Parameter.hpp:24
Tools to handle parameter files.
uint32_t Scan(const std::string &filter_reg_exp, std::vector< ctd::param::Parameter > &matches) const
Scans through the parameter object namespace and creates list of matching parameters.
Definition: ParameterSet.cpp:111
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:75