ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterSet.hpp
Go to the documentation of this file.
1 
5 #ifndef IWF_CTD_FILE_PARAMETER_SET_HPP_
6 #define IWF_CTD_FILE_PARAMETER_SET_HPP_
7 
8 #include "ctd/defines/defines.hpp"
9 #include "ctd/file/Parameter.hpp"
10 
12 
13 namespace ctd {
14 namespace file {
15 
17 class ParameterSet {
18 public:
19 
20  ParameterSet();
21 
24 
25  ~ParameterSet();
26 
28  static std::string Print(ctd::defines::List<ctd::file::Parameter>& par_list);
29 
31  virtual void Load(const std::string& filename,
32  const bool merge = false);
42  virtual void LoadUser(const std::string& filename,
43  const bool merge = false);
44 
46  void Store(const std::string& par_name,
47  const std::string& value,
48  const std::string& comment = "");
49 
51  std::string GetValueAsString(const std::string& par_name,
52  const bool exception = false) const;
53 
55  template <class TYPE> bool GetValue(const std::string& name,
56  TYPE& value,
57  const bool exception = false) const {
58  RAD_LOG_TRACE();
59 
60  ctd::file::Parameter tmpPar;
61  if (HasPar(name, tmpPar)) {
62  tmpPar.GetValue(value);
63  } else {
64  if (exception) {
65  throw rad::Exception("Undefined parameter name: %s", name.c_str());
66  } else {
67  return false;
68  }
69  }
70  return true;
71  }
72 
74  const ctd::file::Parameter& GetPar(const std::string& par_name) const;
75 
77  bool HasPar(const std::string& par_name) const;
78 
80  bool HasPar(const std::string& par_name,
81  ctd::file::Parameter& parameter) const;
82 
84  template <class TYPE> bool HasPar(const std::string& par_name,
85  TYPE& value) const {
86  RAD_LOG_TRACE();
87 
88  ctd::file::Parameter tmpPar;
89  if (HasPar(par_name, tmpPar)) {
90  tmpPar.GetValue(value);
91  } else {
92  return false;
93  }
94  return true;
95  }
96 
98  uint32_t Scan(const std::string& filter_reg_exp,
100 
102  std::string Print(const std::string& filter_reg_exp = "") const;
103 
106 
108  const std::map<std::string, ctd::file::Parameter>& GetParameterMap() const;
109 
111  const std::string& GetProcFile() const;
112 
115 
116 protected:
117  // Mapping keywords into the associated values.
118  std::map<std::string, ctd::file::Parameter> m_par_map;
119 
120  // File being processed.
121  std::string m_proc_file;
122 
123  // Currently loaded files.
125 
126  void _Copy(const ParameterSet& source);
127 
128 private:
129 
130 };
131 
132 } // namespace file
133 } // namespace ctd
134 
135 
136 #endif // !IWF_CTD_FILE_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:55
double value
Definition: easylogging++.h:814
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:135
std::string GetValueAsString(const std::string &par_name, const bool exception=false) const
Return value for the referenced parameter as a string.
Definition: ParameterSet.cpp:182
const std::string & GetProcFile() const
Return reference to file being processed (loaded).
Definition: ParameterSet.cpp:253
std::map< std::string, ctd::file::Parameter > m_par_map
Definition: ParameterSet.hpp:118
ctd::defines::List< std::string > m_loaded_files
Definition: ParameterSet.hpp:124
Class to handle information for one parameter.
Definition: Parameter.hpp:19
std::string m_proc_file
Definition: ParameterSet.hpp:121
const std::map< std::string, ctd::file::Parameter > & GetParameterMap() const
Return reference to the internal map with the names/parameter objects.
Definition: ParameterSet.cpp:260
bool HasPar(const std::string &par_name, TYPE &value) const
Return trie if parameter defined, sets the value as the native value.
Definition: ParameterSet.hpp:84
void _Copy(const ParameterSet &source)
Definition: ParameterSet.cpp:246
@ brief STL like list that can be indexed with []&#39;s.
Definition: defines.hpp:262
source
Definition: radgen_tool.py:35
uint32_t Scan(const std::string &filter_reg_exp, ctd::defines::List< ctd::file::Parameter > &matches) const
Scans through the parameter object namespace and creates list of matching parameters.
Definition: ParameterSet.cpp:196
bool HasPar(const std::string &par_name) const
Returns true if parameter is defined.
Definition: ParameterSet.cpp:147
ParameterSet()
Definition: ParameterSet.cpp:16
Definition: Exceptions.hpp:44
virtual void LoadUser(const std::string &filename, const bool merge=false)
Definition: ParameterSet.cpp:39
#define RAD_LOG_TRACE()
Definition: Logger.hpp:319
void GetValue(TYPE &value) const
Get parameter value as its native data type.
Definition: Parameter.hpp:55
const ctd::file::Parameter & GetPar(const std::string &par_name) const
Get reference to parameter object, referenced by its name.
Definition: ParameterSet.cpp:169
~ParameterSet()
Definition: ParameterSet.cpp:26
optional string name
Definition: topics.proto:50
Class to handle a set of parameters.
Definition: ParameterSet.hpp:17
ParameterSet & operator=(const ParameterSet &source)
Assignment operator.
Definition: ParameterSet.cpp:31
virtual void Load(const std::string &filename, const bool merge=false)
Load a file containing parameters.
Definition: ParameterSet.cpp:109
ctd::defines::List< std::string > ParNames() const
Returns list of parameter names.
Definition: ParameterSet.cpp:124
static std::string Print(ctd::defines::List< ctd::file::Parameter > &par_list)
Create an ASCII print out of the parameters in the list.
Definition: ParameterSet.cpp:210